Esempio n. 1
0
        public void CombineNullClass(bool prevExist, bool nextExist, bool resultExist)
        {
            var prev = new TestClass()
            {
                PString = "prev"
            };
            if (!prevExist)
                prev = null;

            var next = new TestClass()
            {
                PString = "next"
            };
            if (!nextExist)
                next = null;

            var result = DefaultCombiner.Instance.Combine(prev, next);

            if(resultExist)
            {
                if(prevExist)
                    Assert.That(result.PString, Is.EqualTo("prev"));
                if(nextExist)
                    Assert.That(result.PString, Is.EqualTo("next"));
            }
            else
                Assert.That(result, Is.Null);
        }
Esempio n. 2
0
        public void ModifyCombined()
        {
            var x = new TestClass()
            {
                F1 = "xF1",
                Inner = new TestClass()
                {
                    F1 = "xiF1"
                }
            };

            var y = new TestClass()
            {
                F1 = "yF1",
                Inner = new TestClass()
                {
                    F1 = "yiF1"
                }
            };

            var childCombiner = new ChildCombiner(DefaultCombiner.Instance);
            childCombiner.SetCombiner<TestClass>((ctx, prev, next) => prev == null ? next : next == null ? prev : new TestClass()
            {
                F1 = prev.F1 + "," + next.F1,
                Inner = ctx.CurrentCombine(prev.Inner, next.Inner)
            });

            var childCombiner2 = new ChildCombiner(childCombiner)
                .Modify<TestClass>(_ => _.F1 += " combined");

            var combined = childCombiner2.Combine(x, y);

            Assert.That(combined.F1, Is.EqualTo("xF1,yF1 combined"));
            Assert.That(combined.Inner.F1, Is.EqualTo("xiF1,yiF1 combined"));
        }
Esempio n. 3
0
        public void CombineClass()
        {
            var prev = new TestClass()
            {
                PString = "prev",
                FString1 = "prev",
                FString2 = "prev",
                FInt = 1,
                NInt = 0,
                Array1 = new int[]{1, 2, 3},
                Array2 = new int[]{1, 2, 3}
            };

            var next = new TestClass()
            {
                PString = "next",
                FString1 = "next",
                FString2 = null,
                FInt = 0,
                NInt = null,
                Array1 = null,
                Array2 = new int[]{3, 3, 3}
            };

            var result = DefaultCombiner.Instance.Combine(prev, next);

            Assert.That(result.PString, Is.EqualTo("next"));
            Assert.That(result.FString1, Is.EqualTo("next"));
            Assert.That(result.FString2, Is.EqualTo("prev"));
            Assert.That(result.FInt, Is.EqualTo(1));
            Assert.That(result.NInt, Is.EqualTo(0));
            Assert.That(result.Array1, Is.EquivalentTo(new int[] { 1, 2, 3 }));
            Assert.That(result.Array2, Is.EquivalentTo(new int[] { 3, 3, 3 }));
        }