void TestCloning <T>()
        {
            var source = Random.Init <T>();
            var target = Clone <T> .From(source);

            Assert.IsTrue(Comparer.Equal(source, target));
        }
Exemplo n.º 2
0
        static void TestTypeAliases <T, U>(T from) where T : class
        {
            Util.AllSerializeDeserialize <T, T>(from);

            var to = Clone <T> .From(Clone <U> .From(from));

            Assert.IsTrue(from.IsEqual <T>(to));
        }
Exemplo n.º 3
0
        public void TestCloning <T, U>()
            where T : class
            where U : class
        {
            var source = Random.Init <T>();
            var target = Clone <U> .From(source);

            Assert.IsTrue(source.IsEqual(target));
        }
Exemplo n.º 4
0
        public void CloningBonded()
        {
            var source = new StructWithBonded();

            var field = Random.Init <Derived>();

            source.field = Util.MakeBondedCB(field);

            var poly0 = Random.Init <EmptyBase>();
            var poly1 = Random.Init <Nested>();
            var poly2 = Random.Init <Derived>();

            source.poly.Add(Util.MakeBondedCB(poly0));
            source.poly.Add(Util.MakeBondedCB(poly1));
            source.poly.Add(new Bonded <Derived>(poly2));

            var target = Clone <StructWithBonded> .From(source);

            Assert.IsTrue(Comparer.Equal(field, target.field.Deserialize <Derived>()));
            Assert.IsTrue(Comparer.Equal(poly0, target.poly[0].Deserialize <EmptyBase>()));
            Assert.IsTrue(Comparer.Equal(poly1, target.poly[1].Deserialize()));
            Assert.IsTrue(Comparer.Equal(poly2, target.poly[2].Deserialize <Derived>()));
        }
Exemplo n.º 5
0
        public void GenericHelpers()
        {
            GenericHelperScalar <bool>();
            GenericHelperScalar <sbyte>();
            GenericHelperScalar <short>();
            GenericHelperScalar <int>();
            GenericHelperScalar <long>();
            GenericHelperScalar <byte>();
            GenericHelperScalar <ushort>();
            GenericHelperScalar <uint>();
            GenericHelperScalar <ulong>();
            GenericHelperScalar <float>();
            GenericHelperScalar <double>();
            GenericHelperArraySegment();

            GenericHelperClass <BasicTypes>();
            GenericHelperClass <List <BasicTypes> >();
            GenericHelperClass <List <string> >();

            GenericCompareFalse(true, false);
            GenericCompareFalse(false, true);
            GenericCompareFalse(1, 2);
            GenericCompareFalse <short>(1, 2);
            GenericCompareFalse <float>(1, 2);
            GenericCompareFalse <float?>(1, 2);
            GenericCompareFalse("abc", "abcd");
            GenericCompareFalse("abc", null);
            GenericCompareFalse(new BasicTypes(), null);
            GenericCompareFalse <double?>(10, null);

            GenericCompareTrue("abc", "abc");
            GenericCompareTrue <string>(null, null);
            GenericCompareTrue <int?>(null, null);
            GenericCompareTrue <int?>(10, 10);
            GenericCompareTrue <BasicTypes>(null, null);

            var blob1 = new ArraySegment <byte>(new byte[2]);
            var blob2 = new ArraySegment <byte>(blob1.Array, 1, blob1.Count - 1);

            GenericCompareFalse(blob1, blob2);
            GenericCompareFalse(blob2, blob1);

            var vectors1 = Random.Init <Vectors>();
            var vectors2 = Clone <Vectors> .From(vectors1);

            GenericCompareTrue(vectors1, vectors2);
            GenericCompareTrue(vectors1._bool, vectors2._bool);

            vectors1._bool.Add(false);
            GenericCompareFalse(vectors1, vectors2);
            GenericCompareFalse(vectors1._bool, null);
            GenericCompareFalse(vectors1._bool, vectors2._bool);

            vectors1._bool.Add(true);
            GenericCompareFalse(vectors1, vectors2);
            GenericCompareFalse(vectors1._bool, vectors2._bool);

            var nested1 = Random.Init <NestedContainers>();
            var nested2 = Clone <NestedContainers> .From(nested1);

            GenericCompareTrue(nested1, nested2);
            GenericCompareTrue(nested1.vvbt, nested2.vvbt);

            if (nested1.vvbt.Count != 0)
            {
                nested1.vvbt[0].Add(new BasicTypes());
                GenericCompareFalse(nested1, nested2);
                GenericCompareFalse(nested1.vvbt, nested2.vvbt);

                nested2.vvbt[0].Add(new BasicTypes());
                GenericCompareTrue(nested1, nested2);
                GenericCompareTrue(nested1.vvbt, nested2.vvbt);

                nested1.vvbt[0][0]._bool = !nested2.vvbt[0][0]._bool;
                GenericCompareFalse(nested1, nested2);
                GenericCompareFalse(nested1.vvbt, nested2.vvbt);

                nested1.vvbt[0].Add(null);
                nested2.vvbt[0].Add(new BasicTypes());
                GenericCompareFalse(nested1, nested2);
                GenericCompareFalse(nested1.vvbt, nested2.vvbt);
            }

            var derived1 = Random.Init <Derived>();
            var derived2 = Clone <Derived> .From(derived1);

            GenericCompareTrue(derived1, derived2);

            derived1.basic._bool = !derived2.basic._bool;
            GenericCompareFalse(derived1, derived2);

            derived1.basic._bool = derived2.basic._bool;
            GenericCompareTrue(derived1, derived2);
            derived1.basic._enum1 = EnumType1.EnumValue1;
            derived2.basic._enum1 = EnumType1.EnumValue2;
            GenericCompareFalse(derived1, derived2);
        }
 /// <summary>
 /// Clones the current instance.
 /// </summary>
 /// <returns>New MetricCheck instance containing the same data as the current instance.</returns>
 public MetricCheck Clone()
 {
     return(Clone <MetricCheck> .From(this));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Clones the current instance.
 /// </summary>
 /// <returns>New HealthCheck instance containing the same data as the current instance.</returns>
 public HealthCheck Clone()
 {
     return(Clone <HealthCheck> .From(this));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Clones the current instance.
 /// </summary>
 /// <returns>New HealthCheck instance containing the same data as the current instance.</returns>
 public WatchdogScheduledItem Clone()
 {
     return(Clone <WatchdogScheduledItem> .From(this));
 }