コード例 #1
0
        public void Should_Return_Not_Equal_When_Source_Inner_Collection_Is_Not_Null_And_Destination_Inner_Collection_Is_Null()
        {
            // fixture setup
            var value = new AnotherTypeWithAnotherInnerCollectionBuilder()
                        .WithInnerCollectionItemsCount(2)
                        .Build()
            ;

            var other = new TypeWithInnerCollectionBuilder()
                        .WithNullInnerCollection()
                        .Build()
            ;

            // exercise
            var result = value.AsSource().OfLikeness <TypeWithInnerCollection>()
                         .WithCollectionInnerLikeness(t => t.Collection, s => s.OtherCollection)
                         .Equals(other);

            // verify
            Assert.That(result, Is.False);
        }
コード例 #2
0
        public void Should_Return_Not_Equal_When_Inner_Collections_Counts_Are_Different(int valueCollectionCount,
                                                                                        int otherCollectionCount)
        {
            // fixture setup
            var value = new AnotherTypeWithAnotherInnerCollectionBuilder()
                        .WithInnerCollectionItemsCount(valueCollectionCount)
                        .Build()
            ;

            var other = new TypeWithInnerCollectionBuilder()
                        .WithInnerCollectionItemsCount(otherCollectionCount)
                        .Build()
            ;

            // exercise
            var result = value.AsSource().OfLikeness <TypeWithInnerCollection>()
                         .WithCollectionInnerLikeness(t => t.Collection, s => s.OtherCollection)
                         .Equals(other);

            // verify
            Assert.That(result, Is.False);
        }
コード例 #3
0
        public void Should_Return_Not_Equal_When_Source_Collection_Inner_Collection_Contains_Item_That_Cannot_Be_Cast_To_Likeness_Property_Type()
        {
            // fixture setup
            var value = new AnotherTypeWithAnotherInnerCollectionBuilder()
                        .WithInnerCollectionItemTypeOfObjectWithInt("item1", 1)
                        .Build()
            ;

            var other = new TypeWithInnerCollectionBuilder()
                        .WithInnerCollectionItemTypeOfObjectWithInt("item1", 1)
                        .Build()
            ;

            // exercise
            var action = new TestDelegate(() => value.AsSource().OfLikeness <TypeWithInnerCollection>()
                                          .WithCollectionInnerSpecificLikeness(t => t.Collection, d => d.OtherCollection,
                                                                               (Likeness <AnotherObjectWithAnotherStringPropertiesDerived, ObjectWithAnotherIntPropertyDerived> likeness) => likeness)
                                          .Equals(other));

            // verify
            Assert.That(action, Throws.ArgumentException.And.Message.Contains("Source value is type of 'Jmansar.SemanticComparisonExtensions.Test.TestData.AnotherObjectWithAnotherIntPropertyDerived', cannot cast to 'Jmansar.SemanticComparisonExtensions.Test.TestData.AnotherObjectWithAnotherStringPropertiesDerived"));
        }
コード例 #4
0
        public void Should_Return_Not_Equal_When_Destination_Collection_Inner_Collection_Contains_Item_That_Cannot_Be_Cast_To_Likeness_Property_Type()
        {
            // fixture setup
            var value = new AnotherTypeWithAnotherInnerCollectionBuilder()
                        .WithInnerCollectionItemTypeOfObjectWithInt("item1", 1)
                        .Build()
            ;

            var other = new TypeWithInnerCollectionBuilder()
                        .WithInnerCollectionItemTypeOfObjectWithInt("item1", 1)
                        .Build()
            ;

            // exercise
            var result = value.AsSource().OfLikeness <TypeWithInnerCollection>()
                         .WithCollectionInnerSpecificLikeness(t => t.Collection, d => d.OtherCollection,
                                                              (Likeness <AnotherObjectWithAnotherIntPropertyDerived, ObjectWithAnotherStringPropertiesDerived> likeness) => likeness)
                         .Equals(other);

            // verify
            Assert.That(result, Is.False);
        }
コード例 #5
0
        public void Should_Return_Not_Equal_When_Corresponding_Inner_Collections_Items_Are_Not_Equal_Using_Default_Likeness()
        {
            // fixture setup
            var value = new AnotherTypeWithAnotherInnerCollectionBuilder()
                        .WithInnerCollectionItemValue("item1")
                        .WithInnerCollectionItemValue("item2")
                        .Build()
            ;

            var other = new TypeWithInnerCollectionBuilder()
                        .WithInnerCollectionItemValue("item1")
                        .WithInnerCollectionItemValue("QWERTY")
                        .Build()
            ;

            // exercise
            var result = value.AsSource().OfLikeness <TypeWithInnerCollection>()
                         .WithCollectionInnerLikeness(t => t.Collection, d => d.OtherCollection)
                         .Equals(other);

            // verify
            Assert.That(result, Is.False);
        }
コード例 #6
0
        public void Should_Return_Equal_When_Corresponding_Inner_Collections_Items_Are_Equal_Using_Likeness_For_Overriden_Types()
        {
            // fixture setup
            var value = new AnotherTypeWithAnotherInnerCollectionBuilder()
                        .WithInnerCollectionItemTypeOfObjectWithInt("item1", 1)
                        .WithInnerCollectionItemTypeOfObjectWithInt("item2", 2)
                        .Build()
            ;

            var other = new TypeWithInnerCollectionBuilder()
                        .WithInnerCollectionItemTypeOfObjectWithInt("item1", 1)
                        .WithInnerCollectionItemTypeOfObjectWithInt("item2", 2)
                        .Build()
            ;

            // exercise
            var result = value.AsSource().OfLikeness <TypeWithInnerCollection>()
                         .WithCollectionInnerSpecificLikeness(t => t.Collection, d => d.OtherCollection,
                                                              (Likeness <AnotherObjectWithAnotherIntPropertyDerived, ObjectWithAnotherIntPropertyDerived> likeness) => likeness)
                         .Equals(other);

            // verify
            Assert.That(result, Is.True);
        }
コード例 #7
0
        public void Should_Use_Inner_Comparison_Overrides_To_Force_Equal()
        {
            // fixture setup
            var value = new AnotherTypeWithAnotherInnerCollectionBuilder()
                        .WithInnerCollectionItemValue("item1")
                        .WithInnerCollectionItemValue("item2")
                        .Build()
            ;

            var other = new TypeWithInnerCollectionBuilder()
                        .WithInnerCollectionItemValue("item1")
                        .WithInnerCollectionItemValue("QWERTY")
                        .Build()
            ;

            // exercise
            var result = value.AsSource().OfLikeness <TypeWithInnerCollection>()
                         .WithCollectionInnerLikeness(t => t.Collection, d => d.OtherCollection,
                                                      likeness => likeness.With(x => x.StringTypeProperty).EqualsWhen((s, d) => true))
                         .Equals(other);

            // verify
            Assert.That(result, Is.True);
        }