public void Can_compare_types(Type type1, Type type2, Type elementType1, Type elementType2, bool expected)
        {
            "Given a fixture".x(() =>
            {
                Fixture = new Fixture();
            });

            "And an inner comparison".x(() =>
            {
                Inner = new MockComparison();
                Fixture.Inject <IComparison>(Inner);
            });

            "And an ListComparison".x(() =>
                                      SUT = Fixture.Create <SetComparison>()
                                      );

            "When calling CanCompare({0}, {1})".x(() =>
                                                  CanCompareResult = SUT.CanCompare(type1, type2)
                                                  );

            "It should return {2}".x(() =>
                                     CanCompareResult.ShouldBe(expected)
                                     );

            if (expected)
            {
                "and it should call CanCompare on the inner comparer".x(() =>
                                                                        Inner.CanCompareCalls.ShouldContain((elementType1, elementType2))
                                                                        );
            }
        }
예제 #2
0
        private void SetUp()
        {
            "Given a fixture".x(() =>
            {
                Fixture = new Fixture();
                Fixture.Customize(new AutoMoqCustomization());
            });

            "And an inner comparison".x(() =>
            {
                Inner = new MockComparison();
                Fixture.Inject <IComparison>(Inner);
            });

            "And a ComplexObjectComparison".x(() =>
                                              SUT = Fixture.Build <ComplexObjectComparison>()
                                                    .OmitAutoProperties()
                                                    .Create()
                                              );

            "And a Comparison context object".x(() =>
                                                Context = new ComparisonContext("Property")
                                                );
        }
        public void When_comparing_sets(IEnumerable value1, IEnumerable value2, ComparisonResult expected)
        {
            var list1 = value1.Cast <object>().ToArray();
            var list2 = value2.Cast <object>().ToArray();

            "Given a fixture".x(() =>
            {
                Fixture = new Fixture();
            });

            "And an inner comparison".x(() =>
            {
                Inner = new MockComparison();
                Fixture.Inject <IComparison>(Inner);
            });

            "And a SetComparison".x(() =>
                                    SUT = Fixture.Create <SetComparison>()
                                    );

            "And a Comparison context object".x(() =>
                                                Context = new ComparisonContext("Set")
                                                );

            "When comparing enumerables".x(() =>
            {
                var(result, context) = SUT.Compare(Context, value1, value2);
                Result  = result;
                Context = context;
            });

            "Then it should return {2}".x(() =>
                                          Result.ShouldBe(expected)
                                          );

            if (list1.Length == list2.Length)
            {
                "And it should call the inner comparison Compare for each element in the set".x(() =>
                {
                    for (var i = 0; i < list1.Length; i++)
                    {
                        var local = i;

                        Inner.CompareCalls.ShouldContain(call => call.value1.Equals(list1[local]));
                    }
                });

                if (expected == ComparisonResult.Fail)
                {
                    "And it should add a SetDifference".x(() =>
                                                          Context.Differences[0].ShouldBeAssignableTo <SetDifference>()
                                                          );
                }
            }
            else
            {
                var expectedDifference = new BasicDifference(
                    breadcrumb: "Set",
                    value1: list1.Length,
                    value2: list2.Length,
                    childProperty: "Count"
                    );

                "And it should add a Difference".x(() =>
                                                   Context.Differences[0].ShouldDeepEqual(expectedDifference)
                                                   );
            }
        }
        public void When_comparing_enumerables(IEnumerable value1, IEnumerable value2, ComparisonResult expected)
        {
            var list1 = value1.Cast <object>().ToArray();
            var list2 = value2.Cast <object>().ToArray();

            "Given a fixture".x(() =>
                                Fixture = new Fixture()
                                );

            "And an inner comparison".x(() =>
            {
                Inner = new MockComparison();
                Fixture.Inject <IComparison>(Inner);
            });

            "And a ListComparison".x(() =>
                                     SUT = Fixture.Create <ListComparison>()
                                     );

            "And a Comparison context object".x(() =>
                                                Context = new ComparisonContext("List")
                                                );

            "When comparing enumerables".x(() =>
            {
                (var result, var context) = SUT.Compare(Context, value1, value2);
                Result  = result;
                Context = context;
            });

            "Then it should return {2}".x(() =>
                                          Result.ShouldBe(expected)
                                          );

            if (list1.Length == list2.Length)
            {
                "And it should call the inner comparison Compare for each element in the list".x(() =>
                {
                    var pairs = list1.Zip(list2, Tuple.Create).ToList();
                    for (var i = 0; i < pairs.Count; i++)
                    {
                        var p     = pairs[i];
                        var index = i;

                        Inner.CompareCalls.ShouldContain(call =>
                                                         call.context.Breadcrumb == $"List[{index}]" &&
                                                         call.value1.Equals(p.Item1) &&
                                                         call.value2.Equals(p.Item2)
                                                         );
                    }
                });
            }
            else
            {
                var expectedDifference = new
                {
                    Breadcrumb    = "List",
                    ChildProperty = "Count",
                    Value1        = list1.Length,
                    Value2        = list2.Length
                };

                "And it should add a Difference".x(() =>
                                                   Context.Differences[0].ShouldDeepEqual(expectedDifference)
                                                   );
            }
        }