public void Expect_the_Via_headers_to_be_equal() { var c = ObjectComparer.Create(); c.Compare(_response.Vias, Request.Vias); c.Differences.Should().BeEmpty(); }
public void Expect_the_RouteSet_to_be_RecordRoutes_of_the_response_in_reverse_order() { var oc = ObjectComparer.Create(); oc.Compare(ClientDialog.RouteSet, ReceivedResponse.RecordRoutes.ToList()); oc.Differences.Should().BeEmpty(); }
public static ISynchronizer GetSynchronizer() { var connectionString = "mongodb://localhost:27017"; var collection = "Users"; var source = "Symmetry-Source"; var destination = "Symmetry-Destination"; var dataSource = MongoDbDataSource <User> .Create(connectionString, source) .WithQuery(q => q.Where(x => x.Name != string.Empty)) .WithCollection(collection) .Build(); var dataDestination = MongoDbDataSource <User> .Create(connectionString, destination) .WithCollection(collection) .Build(); var dataStore = MongoDbDataStore <User> .Create(connectionString, destination) .WithCollection(collection) .Build(); var synchronizerConfiguration = SynchronizerConfiguration <User> .Create() .WithDataSource(() => dataSource) .WithDataDestination(() => dataDestination) .WithDataStore(() => dataStore) .WithComparer(() => ObjectComparer <User> .Create((a, b) => a.Name == b.Name)) .Build(); return(Synchronizer <User> .Create(synchronizerConfiguration) .Build()); }
public void CompareWithCustomComparer() { //Arrange. Mock <IComparer> customComparer = new Mock <IComparer>(); customComparer.Setup(m => m.Compare(It.IsAny <Genders>(), It.IsAny <Genders>())) .Returns(0) .Callback <Genders, Genders>((d1, d2) => { if (d1.GetType() != typeof(Genders) || d2.GetType() != typeof(Genders)) { throw new AssertionException("The arguments of the custom comparer are not of the expected type."); } }) .Verifiable("Custom comparer was not invoked."); Person p1 = ModelsHelper.CreatePerson(); Person p2 = ModelsHelper.CreatePerson(); ObjectComparer comparer = ObjectComparer.Create <Person>(); comparer.Comparers.Add(typeof(Genders), customComparer.Object); //Act. var result = comparer.Compare(p1, p2, out bool isDifferent); //Assert. customComparer.VerifyAll(); isDifferent.Should().BeFalse(); }
public void CompareTypeMismatch(object o1, object o2) { //Arrange. ObjectComparer comparer = ObjectComparer.Create <Person, PersonByRefUdt>(); //Act. Action act = () => comparer.Compare(o1, o2); //Assert. act.Should().Throw <ArgumentException>(); }
public void CompareSameObject() { //Arrange. Person p1 = ModelsHelper.CreatePerson(); Person p2 = p1; ObjectComparer comparer = ObjectComparer.Create <Person>(); //Act. Action act = () => comparer.Compare(p1, p2); //Assert. act.Should().Throw <InvalidOperationException>(); }
public void PropertyNotFound() { //Arrange. PersonEx p1 = ModelsHelper.CreatePersonEx(); Person p2 = ModelsHelper.CreatePerson(); ObjectComparer comparer = ObjectComparer.Create <PersonEx, Person>(); //Act. var result = comparer.Compare(p1, p2, out bool isDifferent); //Assert. isDifferent.Should().BeFalse(); result[nameof(PersonEx.NickName)].Result.Should().Be(ComparisonResult.PropertyNotFound); }
public void Parse_WithWildCard_ExpectTheParsedToBeEqualToTheOriginal() { var original = new SipContactHeaderBuilder() .WithIsWildCard(true).Build(); var bodyString = original.FormatBodyToString(); var parsed = new SipContactHeaderParser().Parse(bodyString); var c = ObjectComparer.Create(); c.Compare(original, parsed); c.Differences.Should().BeEmpty(); }
public void Parse_WithLooseRouting_ExpectTheParsedToBeEqualToTheOriginal() { var original = new SipRecordRouteHeader(); original.SipUri = new SipUriBuilder().WithLoooseRouting(true).Build(); var bodyString = original.FormatBodyToString(); var parsed = new SipRecordRouteHeaderParser().Parse(bodyString); var c = ObjectComparer.Create(); c.Compare(original, parsed); c.Differences.Should().BeEmpty(); }
private static IEnumerable ObjectComparerForUnregisteredTypeTestData() { string rootName = nameof(ObjectComparerForUnregisteredType); Action a = () => ObjectComparer.Create <DateTime>(); yield return(new TestCaseData(a) .SetName($"{rootName} Single Type")); a = () => ObjectComparer.Create <DateTime, Person>(); yield return(new TestCaseData(a) .SetName($"{rootName} Two Types First Type")); a = () => ObjectComparer.Create <Person, DateTime>(); yield return(new TestCaseData(a) .SetName($"{rootName} Two Types Second Type")); }
public void CompareNullablePropertiesSameType(bool date1Null, bool date2Null) { //Arrange. PersonEx2WithPropertyMap p1 = ModelsHelper.CreatePersonEx2WithPropertyMap(date1Null); PersonEx2 p2 = ModelsHelper.CreatePersonEx2(date2Null); ObjectComparer comparer = ObjectComparer.Create <PersonEx2WithPropertyMap, PersonEx2>(); //Act. var result = comparer.Compare(p1, p2, out bool _); //Assert. result.Should().NotBeNull(); PropertyComparisonResult propResult = result[nameof(PersonEx2WithPropertyMap.DateOfBirth)]; propResult.Should().NotBeNull(); }
public void CompareNonNullableToNullableSameBaseType(bool nullDate) { //Arrange. PersonEx2NonNullable p1 = ModelsHelper.CreatePersonEx2NonNullable(); PersonEx2 p2 = ModelsHelper.CreatePersonEx2(nullDate); ObjectComparer comparer = ObjectComparer.Create <PersonEx2NonNullable, PersonEx2>(); //Act. var result = comparer.Compare(p1, p2, out bool _); //Assert. result.Should().NotBeNull(); PropertyComparisonResult propResult = result[nameof(PersonEx2.BirthDate)]; propResult.Should().NotBeNull(); (propResult.Result & ComparisonResult.StringCoercion).Should().Be(ComparisonResult.Undefined, "Comparison without coercion is possible."); }
public void CompareCoercesToStringOnPropertyTypeMismatch() { //Arrange. PersonEx2 p1 = ModelsHelper.CreatePersonEx2(); PersonEx2StringDate p2 = ModelsHelper.CreatePersonEx2StringDate(); ObjectComparer comparer = ObjectComparer.Create <PersonEx2, PersonEx2StringDate>(); //Act. var result = comparer.Compare(p1, p2, out bool _); //Assert. result.Should().NotBeNull(); PropertyComparisonResult propResult = result[nameof(PersonEx2.BirthDate)]; propResult.Should().NotBeNull(); (propResult.Result & ComparisonResult.StringCoercion).Should().Be(ComparisonResult.StringCoercion); }
public void IgnoreForComparisonAttributeIgnoreForSelf() { //Arrange. PersonExWithIgnoreForSelf p1 = ModelsHelper.CreatePersonExWithIgnoreForSelf(); PersonExWithIgnoreForSelf p2 = ModelsHelper.CreatePersonExWithIgnoreForSelf(); ObjectComparer comparer = ObjectComparer.Create <PersonExWithIgnoreForSelf>(); //Act. var result = comparer.Compare(p1, p2, out bool _); //Assert. result.Should().NotBeNull(); PropertyComparisonResult propertyResult = result[nameof(PersonExWithIgnoreForSelf.NickName)]; propertyResult.Should().NotBeNull(); propertyResult.Result.Should().Be(ComparisonResult.PropertyIgnored); }
public void CompareCoercesToStringOnAttributedDemand(bool date1Null, bool date2Null) { //Arrange. PersonExWithStringCoerce p1 = ModelsHelper.CreatePersonExWithStringCoerce(date1Null); PersonEx2 p2 = ModelsHelper.CreatePersonEx2(date2Null); ObjectComparer comparer = ObjectComparer.Create <PersonExWithStringCoerce, PersonEx2>(); //Act. var result = comparer.Compare(p1, p2, out bool _); //Assert. result.Should().NotBeNull(); PropertyComparisonResult propResult = result[nameof(PersonExWithStringCoerce.DateOfBirth)]; propResult.Should().NotBeNull(); (propResult.Result & ComparisonResult.StringCoercion).Should().Be(ComparisonResult.StringCoercion); }
public void ByValUserDefinedType(UdtStruct value1, UdtStruct value2, ComparisonResult expectedResult) { //Arrange. PersonByValUdt p1 = ModelsHelper.CreatePersonByValUdt(); p1.ByValProperty = value1; PersonByValUdt p2 = ModelsHelper.CreatePersonByValUdt(); p2.ByValProperty = value2; ObjectComparer comparer = ObjectComparer.Create <PersonByValUdt>(); //Act. var result = comparer.Compare(p1, p2, out bool isDifferent); //Assert. isDifferent.Should().Be((expectedResult & ComparisonResult.NotEqual) == ComparisonResult.NotEqual); result[nameof(PersonByValUdt.ByValProperty)].Result.Should().Be(expectedResult); }
public void CompareEqualObjects() { //Arrange. Person p1 = ModelsHelper.CreatePerson(); Person p2 = ModelsHelper.CreatePerson(); ObjectComparer comparer = ObjectComparer.Create <Person>(); //Act. var result = comparer.Compare(p1, p2, out bool isDifferent); //Assert. isDifferent.Should().BeFalse(); result.Should().NotBeNull(); result.Count.Should().Be(5); foreach (PropertyComparisonResult pcr in result) { pcr.Result.Should().Be(ComparisonResult.Equal); } }
public void IComparerResult(int comparerReturnValue, ComparisonResult expectedResult) { //Arrange. Mock <IComparer> customComparer = new Mock <IComparer>(); customComparer.Setup(m => m.Compare(It.IsAny <Genders>(), It.IsAny <Genders>())) .Returns(comparerReturnValue) .Verifiable("Custom comparer was not invoked."); Person p1 = ModelsHelper.CreatePerson(); Person p2 = ModelsHelper.CreatePerson(); ObjectComparer comparer = ObjectComparer.Create <Person>(); comparer.Comparers.Add(typeof(Genders), customComparer.Object); //Act. var result = comparer.Compare(p1, p2, out bool isDifferent); //Assert. customComparer.VerifyAll(); isDifferent.Should().Be(expectedResult != ComparisonResult.Equal); result[nameof(Person.Gender)].Result.Should().Be(expectedResult); }
public static ISynchronizer GetSynchronizer() { var sourceUsers = new List <User> { new User("user1"), new User("user2"), new User("user3"), }; var destinationUsers = new List <User> { new User("user1"), new User("user5") }; var dataSource = MemoryDataSource <User> .Create(sourceUsers) .Build(); var dataDestination = MemoryDataSource <User> .Create(destinationUsers) .Build(); var dataStore = MemoryDataStore <User> .Create() .Build(); var synchronizerConfiguration = SynchronizerConfiguration <User> .Create() .WithDataSource(() => dataSource) .WithDataDestination(() => dataDestination) .WithDataStore(() => dataStore) .WithComparer(() => ObjectComparer <User> .Create((a, b) => a.Name == b.Name)) .Build(); return(Synchronizer <User> .Create(synchronizerConfiguration) .Build()); }
public void CompareWithNull(object o1, object o2, string paramName) { //Arrange. ObjectComparer comparer = ObjectComparer.Create <Person>(); //Act. Action act = () => comparer.Compare(o1, o2); ArgumentNullException ex = null; try { act(); } catch (ArgumentNullException aex) { ex = aex; } //Assert. act.Should().Throw <ArgumentNullException>(); ex.Should().NotBeNull(); ex.ParamName.Should().Be(paramName); }
public void IComparerThrows() { //Arrange. Person p1 = ModelsHelper.CreatePerson(); Person p2 = ModelsHelper.CreatePerson(); Mock <IComparer> throwingComparer = new Mock <IComparer>(); throwingComparer.Setup(m => m.Compare(It.IsAny <object>(), It.IsAny <object>())) .Throws(new InvalidOperationException("Compare throws.")) .Verifiable($"{nameof(IComparer.Compare)}() method not invoked."); ObjectComparer comparer = ObjectComparer.Create <Person>(); comparer.Comparers.Add(typeof(Genders), throwingComparer.Object); //Act. var result = comparer.Compare(p1, p2, out bool isDifferent); //Assert. throwingComparer.VerifyAll(); PropertyComparisonResult r = result[nameof(Person.Gender)]; r.Result.Should().Be(ComparisonResult.ComparisonException); r.Exception.Should().NotBeNull(); }
public void Test() { _requestReceived = new ManualResetEvent(false); /*setup + start listening*/ var stub = new SipReceivedMessageProcessorStub(OnRequestReceived, (s, e) => { }); var listeningPoint = new IPEndPoint(TestConstants.MyIpAddress, 33333); var f = new SipFactory(); var stp = new SmartThreadPool(); stp.Start(); var provider = new SipContextSource(listeningPoint, stp); provider.AddListener(null); provider.Start(); /*send a message to the listener*/ var send = new SipRequestBuilder().Build(); var requestBytes = SipFormatter.FormatMessage(send); var udpClient = new UdpClient(); udpClient.Send(requestBytes, requestBytes.Length, listeningPoint); _requestReceived.WaitOne(); var oc = ObjectComparer.Create(); var received = stub.Requests.First(); oc.Compare(received, send); Assert.True(oc.Differences.Count == 0, oc.DifferencesString); }
private void DemoLocalConfiguration() { var comparer = ObjectComparer.Create(useGlobal: true, c => c .IncludeCollections() .IncludeNotPublicFields() .IncludePublicFields() .Ignore <ClassE>(x => x.N1) ); var objB = new ClassB() { Source = new BaseClassA() }; var objC = new ClassC() { Source = new BaseClassA() }; var result = comparer.Compare(objB, objC); Console.WriteLine($"Result:{result.AreEqual}"); Console.WriteLine(result.AggregateAllMessages()); Console.WriteLine(); }
public void Expect_the_MaxForwards_headers_to_be_equal() { ObjectComparer.Create().Compare(_response.MaxForwards, Request.MaxForwards).Should().BeTrue(); }
public void Expect_the_Cseq_headers_to_be_equal() { ObjectComparer.Create().Compare(_response.CSeq, Request.CSeq).Should().BeTrue(); }
public void Expect_the_callId_headers_to_be_equal() { ObjectComparer.Create().Compare(_response.CallId, Request.CallId).Should().BeTrue(); }
public void Expect_the_to_headers_to_be_equal() { var c = ObjectComparer.Create(); c.Compare(_response.To, Request.To).Should().BeTrue(); }
public void Expect_the_from_headers_to_be_equal() { ObjectComparer.Create().Compare(_response.From, Request.From).Should().BeTrue(); }
public void Expect_the_result_to_be_equal_to_the_original() { var c = ObjectComparer.Create(); c.Compare(_fromHeader, _fromHeaderParsed).Should().BeTrue(); }
public void Expect_the_reconstructed_to_to_be_equal_to_the_original() { var c = ObjectComparer.Create(); c.Compare(_originalResponse.To, _sipResponse.To).Should().BeTrue(); }