Beispiel #1
0
        public void TwoListsHaveDifferentOrder()
        {
            var a = new List<int> { 1, 2, 3 };
            var b = new List<int> { 2, 3, 1 };
            var c = new List<int> { 1, 3, 2 };

            var calculator = new NetDiff.DiffCalculator();
            var result = calculator.DiffList(
                baseObj:    a.Cast<object>(),
                antagonist: b.Cast<object>());

            var secondResult = calculator.DiffList(
                baseObj:    a.Cast<object>(),
                antagonist: c.Cast<object>());

            Assert.Equal(
                expected: 3,
                actual: result.Count(n => n.Message.Equals(DiffMessage.DiffersInOrder)));

            Assert.Equal(
                expected: 2,
                actual: secondResult.Count(n => n.Message.Equals(DiffMessage.DiffersInOrder)));

            Assert.Equal(
                expected: 1,
                actual: secondResult.Count(n => n.Message.Equals(DiffMessage.NotApplicable)));
        }
Beispiel #2
0
        public void TwoListsDemonstrateThatContentDiffers()
        {
            var a = new List <int> {
                1, 2, 3
            };
            var b = new List <int> {
                2, 3, 1
            };
            var c = new List <int> {
                3, 3, 2
            };

            var calculator = new NetDiff.DiffCalculator();
            var result     = calculator.DiffList(
                baseObj: a.Cast <object>(),
                antagonist: b.Cast <object>());

            var secondResult = calculator.DiffList(
                baseObj: a.Cast <object>(),
                antagonist: c.Cast <object>());

            Assert.Equal(
                expected: 3,
                actual: result.Count(n => n.Message.Equals(DiffMessage.DiffersInOrder)));

            Assert.Equal(
                expected: 3,
                actual: secondResult.Count(n => n.Message.Equals(DiffMessage.DiffersInContent)));
        }
Beispiel #3
0
        public void TwoListsHaveDifferentOrder()
        {
            var a = new List <int> {
                1, 2, 3
            };
            var b = new List <int> {
                2, 3, 1
            };
            var c = new List <int> {
                1, 3, 2
            };

            var calculator = new NetDiff.DiffCalculator();
            var result     = calculator.DiffList(
                baseObj:    a.Cast <object>(),
                antagonist: b.Cast <object>());

            var secondResult = calculator.DiffList(
                baseObj:    a.Cast <object>(),
                antagonist: c.Cast <object>());

            Assert.Equal(
                expected: 3,
                actual: result.Count(n => n.Message.Equals(DiffMessage.DiffersInOrder)));

            Assert.Equal(
                expected: 2,
                actual: secondResult.Count(n => n.Message.Equals(DiffMessage.DiffersInOrder)));

            Assert.Equal(
                expected: 1,
                actual: secondResult.Count(n => n.Message.Equals(DiffMessage.NotApplicable)));
        }
Beispiel #4
0
        public void TwoListsAreEqual()
        {
            var a = new List<int> {1, 2, 3};
            var b = new List<int> {1, 2, 3};

            var calculator = new NetDiff.DiffCalculator();
            var result = calculator.DiffList(a.Cast<object>(), b.Cast<object>());

            Assert.Equal(3, result.Count());

            foreach (var item in result)
            {
                Assert.True(item.ValuesMatch);
            }

        }
Beispiel #5
0
        public void TwoListsAreEqual()
        {
            var a = new List <int> {
                1, 2, 3
            };
            var b = new List <int> {
                1, 2, 3
            };

            var calculator = new NetDiff.DiffCalculator();
            var result     = calculator.DiffList(a.Cast <object>(), b.Cast <object>());

            Assert.Equal(3, result.Count());

            foreach (var item in result)
            {
                Assert.True(item.ValuesMatch);
            }
        }
Beispiel #6
0
        public void TwoListsDemonstrateThatContentDiffers()
        {
            var a = new List<int> { 1, 2, 3 };
            var b = new List<int> { 2, 3, 1 };
            var c = new List<int> { 3, 3, 2 };

            var calculator = new NetDiff.DiffCalculator();
            var result = calculator.DiffList(
                baseObj: a.Cast<object>(),
                antagonist: b.Cast<object>());

            var secondResult = calculator.DiffList(
                baseObj: a.Cast<object>(),
                antagonist: c.Cast<object>());

            Assert.Equal(
                expected: 3,
                actual: result.Count(n => n.Message.Equals(DiffMessage.DiffersInOrder)));

            Assert.Equal(
                expected: 3,
                actual: secondResult.Count(n => n.Message.Equals(DiffMessage.DiffersInContent)));
        }
Beispiel #7
0
        public void DiffListCannotSortListsOfObjects()
        {
            var a = new List <SubObject>
            {
                new SubObject("a"),
                new SubObject("b"),
                new SubObject("c")
            };
            var b = new List <SubObject>
            {
                new SubObject("c"),
                new SubObject("b"),
                new SubObject("a")
            };

            var calculator = new NetDiff.DiffCalculator();
            var result     = calculator.DiffList(
                baseObj: a,
                antagonist: b);

            Assert.Equal(
                expected: 2,
                actual: result.Count(n => n.Message.Equals(DiffMessage.DiffersInContent)));
        }
Beispiel #8
0
        public void PrivateFieldsShouldNotBeComparedWithReadOnlyCollections()
        {
            //ReadOnlyCollections will throw exceptions on accessing _syncRoot
            var baseCollection = new List<ObjectWithPrivateMembers>()
            {
                new ObjectWithPrivateMembers(
                    someIntField: 1,
                    somePrivateIntField: 2,
                    somePrivateIntProperty: 2),
                new ObjectWithPrivateMembers(
                    someIntField: 1,
                    somePrivateIntField: 3,
                    somePrivateIntProperty: 3)
            };

            var antagonistCollection = new List<ObjectWithPrivateMembers>()
            {
                new ObjectWithPrivateMembers(
                    someIntField:1,
                    somePrivateIntField:2,
                    somePrivateIntProperty:4),
                new ObjectWithPrivateMembers(
                    someIntField:1,
                    somePrivateIntField:3,
                    somePrivateIntProperty:5)
            };

            var baseObject = new ObjectWithReadOnlyCollectionField() {Collection = baseCollection.AsReadOnly()};
            var antagonist = new ObjectWithReadOnlyCollectionField() {Collection = antagonistCollection.AsReadOnly()};

            var calc = new NetDiff.DiffCalculator();

            var result = calc.Diff(baseObject, antagonist);

            Assert.Equal(true, result.ValuesMatch);
        }
Beispiel #9
0
        public void DiffListCannotSortListsOfObjects()
        {
            var a = new List<SubObject>
            {
                new SubObject("a"),
                new SubObject("b"),
                new SubObject("c")
            };
            var b = new List<SubObject>
            {
                new SubObject("c"),
                new SubObject("b"),
                new SubObject("a")
            };

            var calculator = new NetDiff.DiffCalculator();
            var result = calculator.DiffList(
                baseObj: a,
                antagonist: b);

            Assert.Equal(
                expected: 2,
                actual: result.Count(n => n.Message.Equals(DiffMessage.DiffersInContent)));
        }