Example #1
0
        private bool SetsEqual(IComparisonContext context, object[] set1, object[] set2)
        {
            var expected = set2.ToList();
            var extra = new List<object>();

            for (int i = 0; i < set1.Length; i++)
            {
                var obj = set1[i];
                var innerContext = new ComparisonContext();
                var found = expected.FirstOrDefault(e => Inner.Compare(innerContext, obj, e) == ComparisonResult.Pass);

                if (found != null)
                    expected.RemoveAll(x => x.Equals(found));
                else
                    extra.Add(obj);
            }

            var equal = expected.Count == 0 && extra.Count == 0;

            if (!equal)
            {
                context.AddDifference(new SetDifference(context.Breadcrumb, expected, extra));
            }

            return equal;
        }
Example #2
0
        private (ComparisonResult result, IComparisonContext context) SetsEqual(IComparisonContext context, object[] set1, object[] set2)
        {
            var expected = set2.ToList();
            var extra    = new List <object>();

            foreach (var obj in set1)
            {
                var innerContext = new ComparisonContext();
                var found        = expected.FirstOrDefault(e => Inner.Compare(innerContext, obj, e).result == ComparisonResult.Pass);

                if (found != null)
                {
                    expected.RemoveAll(x => ReferenceEquals(x, found));
                }
                else
                {
                    extra.Add(obj);
                }
            }

            var equal = expected.Count == 0 && extra.Count == 0;

            if (!equal)
            {
                return(
                    ComparisonResult.Fail,
                    context.AddDifference(
                        new SetDifference(
                            context.Breadcrumb,
                            expected,
                            extra
                            )
                        )
                    );
            }

            return(ComparisonResult.Pass, context);
        }
Example #3
0
        private object FindKey(IDictionary<object, object> dictionary, object key)
        {
            var tempContext = new ComparisonContext();

            foreach (var key2 in dictionary.Keys)
            {
                if (KeyComparer.Compare(tempContext, key, key2) == ComparisonResult.Pass)
                    return key2;
            }

            return null;
        }
Example #4
0
        public void Comparing_values(object value1, object value2, ComparisonResult expected)
        {
            "Given a Fixture"
                .Given(() => Fixture = new Fixture());

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

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

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

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

            if (expected == ComparisonResult.Pass)
            {
                "And it should not add any differences"
                    .And(() => Context.Differences.Count.ShouldBe(0));
            }
            else
            {
                var expectedDifference = new Difference
                    {
                        Breadcrumb = "Property",
                        Value1 = value1,
                        Value2 = value2
                    };

                "And it should add a differences"
                    .And(() => Context.Differences[0].ShouldBe(expectedDifference));
            }
        }