Ejemplo n.º 1
0
        public void Comparing_value_types_returns_Pass_or_Fail(object value1, object value2, ComparisonResult expectedResult)
        {
            var newContext = default(IComparisonContext);

            "Given a DefaultComparison".x(() =>
                                          SUT = new DefaultComparison()
                                          );

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

            "When calling Compare".x(() =>
                                     (Result, newContext) = SUT.Compare(Context, value1, value2)
                                     );

            "The result should be Pass or Fail".x(() =>
                                                  Result.ShouldBe(expectedResult)
                                                  );

            if (expectedResult == ComparisonResult.Fail)
            {
                var expectedDifference = new BasicDifference(
                    breadcrumb: "Root",
                    value1: value1,
                    value2: value2,
                    childProperty: null
                    );

                "And it should add a difference".x(() =>
                                                   newContext.Differences[0].ShouldDeepEqual(expectedDifference)
                                                   );
            }
        }
Ejemplo n.º 2
0
        public void Comparing_values(object value1, object value2, ComparisonResult expected)
        {
            "Given a Fixture".x(() =>
                                Fixture = new Fixture()
                                );

            "And an EnumComparer".x(() =>
                                    SUT = Fixture.Create <EnumComparison>()
                                    );

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

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

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

            if (expected == ComparisonResult.Pass)
            {
                "And it should not add any differences".x(() =>
                                                          Context.Differences.Count.ShouldBe(0)
                                                          );
            }
            else
            {
                var expectedDifference = new BasicDifference(
                    breadcrumb: "Property",
                    value1: value1,
                    value2: value2,
                    childProperty: null
                    );

                "And it should add a differences".x(() =>
                                                    Context.Differences[0].ShouldDeepEqual(expectedDifference)
                                                    );
            }
        }
        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)
                                                   );
            }
        }