本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.Intersect方法的典型用法代码示例。如果您正苦于以下问题:C# List.Intersect方法的具体用法?C# List.Intersect怎么用?C# List.Intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.Intersect方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanBeUsedByLinqSetOperatorsSuchAsIntersect
public void CanBeUsedByLinqSetOperatorsSuchAsIntersect()
{
IList<ConcreteEntityWithDomainSignatureProperties> objects1 =
new List<ConcreteEntityWithDomainSignatureProperties>();
var object1 = new ConcreteEntityWithDomainSignatureProperties
{
Name = "Billy McCafferty",
};
EntityIdSetter.SetIdOf(object1, 2);
objects1.Add(object1);
IList<ConcreteEntityWithDomainSignatureProperties> objects2 =
new List<ConcreteEntityWithDomainSignatureProperties>();
var object2 = new ConcreteEntityWithDomainSignatureProperties
{
Name = "Jimi Hendrix",
};
EntityIdSetter.SetIdOf(object2, 1);
objects2.Add(object2);
var object3 = new ConcreteEntityWithDomainSignatureProperties
{
Name =
"Doesn't Matter since the Id will match and the presedence of the domain signature will go overridden",
};
EntityIdSetter.SetIdOf(object3, 2);
objects2.Add(object3);
Assert.AreEqual(1, objects1.Intersect(objects2,
new BaseObjectEqualityComparer
<ConcreteEntityWithDomainSignatureProperties>()).Count());
Assert.AreEqual(objects1.Intersect(objects2,
new BaseObjectEqualityComparer
<ConcreteEntityWithDomainSignatureProperties>()).First(), object1);
Assert.AreEqual(objects1.Intersect(objects2,
new BaseObjectEqualityComparer
<ConcreteEntityWithDomainSignatureProperties>()).First(), object3);
}
示例2: MakeAssertions
private void MakeAssertions(ICollection<string> searchResults, List<int> expectedSearchResultIndexValues, int expectedCount)
{
Assert.IsNotNull(searchResults);
Assert.IsTrue(searchResults.Count == expectedCount);
ICollection<int> actualSearchResultIndexValues =
searchResults.Select(searchResult => _fileData.IndexOf(searchResult)).ToList();
Assert.IsTrue(expectedSearchResultIndexValues.Intersect(actualSearchResultIndexValues).Count() ==
expectedSearchResultIndexValues.Count);
}
示例3: TestIntersectAdd_WithComparer_NullDestination_Throws
public void TestIntersectAdd_WithComparer_NullDestination_Throws()
{
IReadOnlySublist<List<int>, int> list1 = new List<int>().ToSublist();
IExpandableSublist<List<int>, int> list2 = new List<int>().ToSublist();
IExpandableSublist<List<int>, int> destination = null;
IComparer<int> comparer = Comparer<int>.Default;
list1.Intersect(list2, comparer).AddTo(destination);
}
示例4: TestIntersectAdd_WithComparison_NullList2_Throws
public void TestIntersectAdd_WithComparison_NullList2_Throws()
{
IReadOnlySublist<List<int>, int> list1 = new List<int>().ToSublist();
IExpandableSublist<List<int>, int> list2 = null;
Func<int, int, int> comparison = Comparer<int>.Default.Compare;
list1.Intersect(list2, comparison);
}
示例5: TestIntersectAdd_NullDestination_Throws
public void TestIntersectAdd_NullDestination_Throws()
{
IReadOnlySublist<List<int>, int> list1 = new List<int>().ToSublist();
IExpandableSublist<List<int>, int> list2 = new List<int>().ToSublist();
IExpandableSublist<List<int>, int> destination = null;
list1.Intersect(list2).AddTo(destination);
}
示例6: TestIntersectAdd_NullList2_Throws
public void TestIntersectAdd_NullList2_Throws()
{
IReadOnlySublist<List<int>, int> list1 = new List<int>().ToSublist();
IExpandableSublist<List<int>, int> list2 = null;
list1.Intersect(list2);
}
示例7: TestIntersectAdd_NullComparison_Throws
public void TestIntersectAdd_NullComparison_Throws()
{
IReadOnlySublist<List<int>, int> list1 = new List<int>().ToSublist();
IExpandableSublist<List<int>, int> list2 = new List<int>().ToSublist();
Func<int, int, int> comparison = null;
list1.Intersect(list2, comparison);
}
示例8: TestIntersectCopy_WithComparer_NullList2_Throws
public void TestIntersectCopy_WithComparer_NullList2_Throws()
{
IReadOnlySublist<List<int>, int> list1 = new List<int>().ToSublist();
IExpandableSublist<List<int>, int> list2 = null;
IComparer<int> comparer = Comparer<int>.Default;
list1.Intersect(list2, comparer);
}
示例9: Intersect_abnormal
public void Intersect_abnormal()
{
// arrange
List<int> first = new List<int>() { 1, 2, 3 };
// act and assert
try
{
first.Intersect(null);
Assert.Fail();
}
catch (Exception e)
{
Assert.IsTrue(e is ArgumentNullException);
}
}
示例10: Intersect
public void Intersect()
{
// arrange
List<int> first = new List<int>() { 1, 2, 3 };
List<int> second = new List<int>() { 1, 3 };
// act
List<int> actual = first.Intersect(second).ToList();
// assert
Assert.AreEqual(2, actual.Count());
Assert.AreEqual(1, actual[0]);
Assert.AreEqual(3, actual[1]);
}
示例11: Serialization
[Ignore()] // This test seems totally broken
public void Serialization()
{
Assembly twitterizerAssembly = Assembly.GetAssembly(typeof(TwitterUser));
var objectTypesToCheck = from t in twitterizerAssembly.GetExportedTypes()
where !t.IsAbstract &&
!t.IsInterface &&
(
t.GetInterfaces().Contains(twitterizerAssembly.GetType("Twitterizer.Core.ITwitterObject")) ||
t.IsSubclassOf(twitterizerAssembly.GetType("Twitterizer.Entities.TwitterEntity"))
)
select t;
var interfacesToImplement = new List<Type>();
interfacesToImplement.Add(twitterizerAssembly.GetType("Twitterizer.Core.ICommand`1"));
//interfacesToImplement.Add(twitterizerAssembly.GetType("Twitterizer.Core.ITwitterCommand`1"));
Assert.AreEqual(0, interfacesToImplement.Where(x => x == null).Count(), "interfacesToImplement contains null values");
var baseClassesToInherit = new List<Type>();
baseClassesToInherit.Add(twitterizerAssembly.GetType("Twitterizer.Commands.PagedTimelineCommand`1"));
Assert.AreEqual(0, baseClassesToInherit.Where(x => x == null).Count(), "baseClassesToInherit contains null values");
var commandTypesToCheck =
(from t in twitterizerAssembly.GetTypes()
where
(
interfacesToImplement.Intersect(t.GetInterfaces()).Count() > 0 ||
baseClassesToInherit.Any(t.IsSubclassOf)
)
select t)
.ToList();
Assert.AreEqual(0, commandTypesToCheck.Where(x => x == null).Count(), "commandTypesToCheck contains null values");
var objects = objectTypesToCheck.Union(commandTypesToCheck).ToList();
Assert.AreEqual(0, objects.Where(x => x == null).Count(), "objects contains null values");
foreach (Type type in objects)
{
Console.WriteLine(string.Format("Inspecting: {0}", type.FullName));
// Check that the object itself is marked as serializable
Assert.IsTrue(type.IsSerializable, string.Format("{0} is not marked as Serializable", type.Name));
// Get the parameter-less constructor, if there is one
ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
if (constructor == null)
Assert.Fail(string.Format("{0} does not have a public ctor", type.FullName));
// Instantiate the type by invoking the constructor
object objectToSerialize = constructor.Invoke(null);
try
{
using (MemoryStream ms = new MemoryStream())
{
// Serialize the object
new BinaryFormatter().Serialize(ms, objectToSerialize);
}
}
catch (Exception) // Catch any exceptions and assert a failure
{
Assert.Fail(string.Format("{0} could not be serialized", type.FullName));
}
}
}