本文整理汇总了C#中NUnit.Framework.List.OfType方法的典型用法代码示例。如果您正苦于以下问题:C# List.OfType方法的具体用法?C# List.OfType怎么用?C# List.OfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NUnit.Framework.List
的用法示例。
在下文中一共展示了List.OfType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IntervalTimePerTimeValuesAttribute
static IntervalTimePerTimeValuesAttribute()
{
var values = new List<IQuantity>();
var times = new[]
{
//TODO: ... however, us, ms, s, min, hr, are not unreasonable to expect ...
T.Microsecond,
T.Millisecond,
T.Second,
T.Minute,
T.Hour,
////TODO: we do not care about Days or Weeks for purposes of these tests...
//T.Day,
//T.Week,
};
// TODO: TBD: Avoid scaling too absurdly: may want to be more selective than this...
var length = times.Length - 2;
// TODO: TBD: Could also vary the value itself, but this will do for starters...
const double value = 1e2;
var first = times.Take(length).ToArray();
var second = times.Reverse().Take(length).ToArray();
values.AddRange(from x in first from y in second select new Quantity(value, x, y.Invert()));
values.AddRange(from y in first from x in second select new Quantity(value, x, y.Invert()));
Values = values.OfType<object>().ToArray();
}
示例2: ShouldBehavior
public void ShouldBehavior()
{
var items = new List<object>();
items.Add("Hello");
items.Add(5);
string item = items.OfType<string>().First();
Assert.That(item, Is.EqualTo("Hello"));
}
示例3: OfType_LinqExt
public void OfType_LinqExt ()
{
// Filter out those which are note od typw double
var sampleIntNumbers = new List<object> (){ 1,2,3,4,5,6m,7,8m,9,10};
var sampleDecimalNumbers = sampleIntNumbers.OfType<decimal> ().ToList ();
Assert.AreEqual (2, sampleDecimalNumbers.Count ());
Assert.IsInstanceOfType (typeof(List<decimal>), sampleDecimalNumbers);
Assert.IsInstanceOfType (typeof(decimal), sampleDecimalNumbers.First ());
}
示例4: SetUp
public void SetUp()
{
var configurationSettings = new List<IConfigurationSetting>();
ConfigurationConfigurator.RegisterConfigurationSettings()
.FromAssemblies(Assembly.GetExecutingAssembly())
.RegisterWithContainer(configurationSettings.Add)
.AllowConfigurationEntriesThatDoNotHaveSettingsClasses(false)
.WithCustomValueParsers(new PersonNameValueParser())
.ExcludeSettingKeys("IgnoredSetting")
.DoYourThing();
_somePersonSetting = configurationSettings.OfType<SomePersonSetting>().Single();
}
示例5: IndexShouldRenderViewIndex
public void IndexShouldRenderViewIndex()
{
var contents = new List<Content>
{
new TextContent { UrlName = HomeController.Shopfront }
}.AsQueryable();
contentRepository.Expect(cr => cr.GetAll()).Return(contents);
homeController.Index()
.ReturnsViewResult()
.ForView("Index")
.WithModel<CmsViewData>()
.AssertAreSame(
contents.OfType<ITextContent>().First(),
vd => vd.TextContent);
}
示例6: Index_ShouldRenderTopContentWithTopPageView
public void Index_ShouldRenderTopContentWithTopPageView()
{
const string urlName = "home_page";
var contents = new List<Content>
{
new TopContent { UrlName = "home_page" }
}.AsQueryable();
contentRepository.Expect(cr => cr.GetAll()).Return(contents);
cmsController.Index(urlName)
.ReturnsViewResult()
.ForView("TopPage")
.WithModel<CmsViewData>()
.AssertAreSame(
contents.OfType<ITextContent>().First(), vd => vd.TextContent);
}
示例7: TimePerStepValuesAttribute
static TimePerStepValuesAttribute()
{
var values = new List<IQuantity>();
var times = new[]
{
T.Microsecond,
T.Millisecond,
T.Second,
T.Minute,
T.Hour,
//// Day and week are way too extreme for purposes of these tests.
//T.Day,
//T.Week,
};
const double value = 1e1;
values.AddRange(from t in times select new Quantity(value, t));
Values = values.OfType<object>().ToArray();
}
示例8: OfTypeQueryReuse
public void OfTypeQueryReuse()
{
List<int> data = new List<int> { 1, 2 };
IEnumerable<object> enumerable = data.OfType<object>();
enumerable.AssertEqual(1, 2);
data.Add(3);
enumerable.AssertEqual(1, 2, 3);
}
示例9: GetTimeDependentFeatureCoverage
private static FeatureCoverage GetTimeDependentFeatureCoverage()
{
IList<SimpleFeature> features = new List<SimpleFeature>
{
new SimpleFeature(0, new Point(0, 0)),
new SimpleFeature(1, new Point(1, 1)),
new SimpleFeature(2, new Point(2, 2))
};
var coverage = FeatureCoverage.GetTimeDependentFeatureCoverage<SimpleFeature>();
// set values of feature a variable
coverage.Features.AddRange(features.OfType<IFeature>());
coverage.FeatureVariable.SetValues(features);
return coverage;
}
示例10: UnityCanResolveEnumerableOfTypesRegisteredInUnityTest
public void UnityCanResolveEnumerableOfTypesRegisteredInUnityTest()
{
// Setup
var unityContainer = new UnityContainer();
// Add composition support for unity
unityContainer.AddNewExtension<LazySupportExtension>();
Component1.InstanceCount = 0;
Component2.InstanceCount = 0;
unityContainer.RegisterType<IComponent, Component1>("component1");
unityContainer.RegisterType<IComponent, Component2>("component2");
unityContainer.RegisterType<IComponent, Component3>();
var collectionOfLazyUnityComponents = unityContainer.Resolve<IEnumerable<IComponent>>();
Assert.That(collectionOfLazyUnityComponents, Is.Not.Null);
Assert.That(Component1.InstanceCount, Is.EqualTo(1));
Assert.That(Component2.InstanceCount, Is.EqualTo(1));
var list = new List<IComponent>(collectionOfLazyUnityComponents);
Assert.That(list.Count, Is.EqualTo(3));
Assert.That(list.OfType<Component1>().Count(), Is.EqualTo(1));
Assert.That(list.OfType<Component2>().Count(), Is.EqualTo(1));
Assert.That(list.OfType<Component3>().Count(), Is.EqualTo(1));
}
示例11: ContainersAreNestedAndSorted
public void ContainersAreNestedAndSorted()
{
Type itemType = typeof(Definitions.ItemWithNestedContainers);
IList<IEditable> editables = new List<IEditable>();
IList<IEditableContainer> containers = explorer.Find<IEditableContainer>(itemType);
HierarchyNode<IContainable> rootContainer = hierarchyBuilder.Build(containers.OfType<IContainable>(), editables.OfType<IContainable>());
var first = rootContainer.Children[0];//.GetContained(null)[0] as IEditableContainer;
Assert.IsNotNull(first.Current);
Assert.AreSame(first.Current, containers[1]);
Assert.AreEqual(3, first.Children.Count);//.GetContained(null).Count);
var inside3 = first.Children[0];//.GetContained(null)[0] as IEditableContainer;
Assert.IsNotNull(inside3.Current);
Assert.AreSame(inside3.Current, containers[0]);
Assert.AreEqual(0, inside3.Children.Count);//.GetContained(null).Count);
var inside1 = first.Children[1];//.GetContained(null)[1] as IEditableContainer;
Assert.IsNotNull(inside1.Current);
Assert.AreSame(inside1.Current, containers[2]);
Assert.AreEqual(1, inside1.Children.Count);//.GetContained(null).Count);
var inside2 = first.Children[2];//.GetContained(null)[2] as IEditableContainer;
Assert.IsNotNull(inside2.Current);
Assert.AreSame(inside2.Current, containers[3]);
Assert.AreEqual(0, inside2.Children.Count);//.GetContained(null).Count);
}
示例12: UnityCanResolveEnumerableOfTypesRegisteredInUnityAndMefTest
public void UnityCanResolveEnumerableOfTypesRegisteredInUnityAndMefTest()
{
// Setup
var unityContainer = new UnityContainer();
var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
MixedComponent1.InstanceCount = 0;
MixedComponent2.InstanceCount = 0;
MixedComponent5.InstanceCount = 0;
// Add composition support for unity
unityContainer.AddExtension(new CompositionIntegration(true));
unityContainer.Configure<CompositionIntegration>().Catalogs.Add(assemblyCatalog);
unityContainer.RegisterType<IMixedComponent, MixedComponent1>("component1");
unityContainer.RegisterType<IMixedComponent, MixedComponent2>("component2");
unityContainer.RegisterType<IMixedComponent, MixedComponent3>();
var collectionOfLazyUnityComponents = unityContainer.Resolve<IEnumerable<IMixedComponent>>();
Assert.That(collectionOfLazyUnityComponents, Is.Not.Null);
Assert.That(MixedComponent1.InstanceCount, Is.EqualTo(1));
Assert.That(MixedComponent2.InstanceCount, Is.EqualTo(1));
Assert.That(MixedComponent5.InstanceCount, Is.EqualTo(1));
var list = new List<IMixedComponent>(collectionOfLazyUnityComponents);
Assert.That(list.Count, Is.EqualTo(5));
Assert.That(list.OfType<MixedComponent1>().Count(), Is.EqualTo(1));
Assert.That(list.OfType<MixedComponent2>().Count(), Is.EqualTo(1));
Assert.That(list.OfType<MixedComponent3>().Count(), Is.EqualTo(1));
Assert.That(list.OfType<MixedComponent4>().Count(), Is.EqualTo(1));
Assert.That(list.OfType<MixedComponent5>().Count(), Is.EqualTo(1));
}
示例13: OriginalSourceReturnedForSequenceOfCorrectNonNullableValueType
public void OriginalSourceReturnedForSequenceOfCorrectNonNullableValueType()
{
IEnumerable ints = new List<int>();
Assert.AreSame(ints, ints.OfType<int>());
}
示例14: InvalidContainerReference_IsIgnored
public void InvalidContainerReference_IsIgnored()
{
Type itemType = typeof(N2.Tests.Definitions.Definitions.ItemWithNestedContainers);
IList<IEditable> editables = new List<IEditable>();
IList<IEditableContainer> containers = explorer.Find<IEditableContainer>(itemType);
containers.RemoveAt(2); // inside1
Assert.DoesNotThrow(() => hierarchyBuilder.Build(containers.OfType<IContainable>(), editables.OfType<IContainable>()));
}
示例15: OriginalSourceNotReturnedForNullableValueTypes
public void OriginalSourceNotReturnedForNullableValueTypes()
{
IEnumerable nullableInts = new List<int?>();
Assert.AreNotSame(nullableInts, nullableInts.OfType<int?>());
}