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); }
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); }
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); }
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); }
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); }
public void TestIntersectAdd_NullList2_Throws() { IReadOnlySublist<List<int>, int> list1 = new List<int>().ToSublist(); IExpandableSublist<List<int>, int> list2 = null; list1.Intersect(list2); }
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); }
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); }
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); } }
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]); }
[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)); } } }