public void HashSetsSame() { HashSetWrapper hashSet1 = new HashSetWrapper { StatusId = 1, Name = "Paul" }; HashSetWrapper hashSet2 = new HashSetWrapper { StatusId = 1, Name = "Paul" }; HashSetClass secondClassObject1 = new HashSetClass { Id = 1 }; HashSetClass secondClassObject2 = new HashSetClass { Id = 1 }; hashSet1.HashSetCollection.Add(secondClassObject1); hashSet2.HashSetCollection.Add(secondClassObject2); ComparisonResult result = _compare.Compare(hashSet1, hashSet2); if (!result.AreEqual) { throw new Exception(result.DifferencesString); } }
public void HashSetsDifferent() { HashSetWrapper hashSet1 = new HashSetWrapper { StatusId = 1, Name = "Paul" }; HashSetWrapper hashSet2 = new HashSetWrapper { StatusId = 1, Name = "Paul" }; HashSetClass secondClassObject1 = new HashSetClass { Id = 1 }; HashSetClass secondClassObject2 = new HashSetClass { Id = 2 }; hashSet1.HashSetCollection.Add(secondClassObject1); hashSet2.HashSetCollection.Add(secondClassObject2); Assert.IsFalse(_compare.Compare(hashSet1, hashSet2).AreEqual); }
public void HashSetsMultipleItemsWithIgnoreCollectionOrderTest() { HashSetWrapper hashSet1 = new HashSetWrapper { StatusId = 1, Name = "Paul" }; HashSetWrapper hashSet2 = new HashSetWrapper { StatusId = 1, Name = "Paul" }; HashSetClass secondClassObject1 = new HashSetClass { Id = 1 }; HashSetClass secondClassObject2 = new HashSetClass { Id = 2 }; HashSetClass secondClassObject3 = new HashSetClass { Id = 3 }; HashSetClass secondClassObject4 = new HashSetClass { Id = 4 }; hashSet1.HashSetCollection.Add(secondClassObject3); hashSet1.HashSetCollection.Add(secondClassObject1); hashSet1.HashSetCollection.Add(secondClassObject2); hashSet1.HashSetCollection.Add(secondClassObject4); hashSet2.HashSetCollection.Add(secondClassObject2); hashSet2.HashSetCollection.Add(secondClassObject4); hashSet2.HashSetCollection.Add(secondClassObject3); hashSet2.HashSetCollection.Add(secondClassObject1); _compare.Config.IgnoreCollectionOrder = true; ComparisonResult result = _compare.Compare(hashSet1, hashSet2); if (!result.AreEqual) { throw new Exception(result.DifferencesString); } }
public void HashSetsMultipleItemsWithIgnoreCollectionOrderNegativeTest() { HashSetWrapper hashSet1 = new HashSetWrapper { StatusId = 1, Name = "Paul" }; HashSetWrapper hashSet2 = new HashSetWrapper { StatusId = 1, Name = "Paul" }; HashSetClass secondClassObject1 = new HashSetClass { Id = 1 }; HashSetClass secondClassObject2 = new HashSetClass { Id = 2 }; HashSetClass secondClassObject3 = new HashSetClass { Id = 3 }; HashSetClass secondClassObject4 = new HashSetClass { Id = 4 }; hashSet1.HashSetCollection.Add(secondClassObject3); hashSet1.HashSetCollection.Add(secondClassObject1); hashSet1.HashSetCollection.Add(secondClassObject2); hashSet1.HashSetCollection.Add(secondClassObject4); hashSet2.HashSetCollection.Add(secondClassObject2); hashSet2.HashSetCollection.Add(secondClassObject4); hashSet2.HashSetCollection.Add(secondClassObject3); hashSet2.HashSetCollection.Add(secondClassObject1); _compare.Config.IgnoreCollectionOrder = false; Assert.IsFalse(_compare.Compare(hashSet1, hashSet2).AreEqual); }
public void HashSetTest() { var d = new HashSetClass() { Strings = { "a", "b", "c" }, Classes = new HashSet <baseclass> () { new baseclass() { Name = "a" }, new class1() { Name = "b", guid = Guid.NewGuid() } } }; var s = JSON.ToJSON(d, new JSONParameters() { ShowReadOnlyProperties = true }); Console.WriteLine(s); var o = JSON.ToObject <HashSetClass> (s); CollectionAssert.AreEqual(new List <string> (d.Strings), new List <string>(o.Strings)); bool a = false, b = false; foreach (var item in o.Classes) { if (item.Name == "a") { a = true; } if (item.Name == "b" && item is class1) { b = true; } } Assert.IsTrue(a); Assert.IsTrue(b); }