예제 #1
0
        public void TestSimpleObject()
        {
            var serializer = new BinarySerializer();
            var obj        = Create();

            serializer.PrepareObjectGraph(obj);
            var result = serializer.SerializeObjectGraph();

            var deserializer = new BinaryDeserializer();
            var deserObj     = (BasicObject)deserializer.DeserializeObjectGraph(result);

            Assert.Equal(obj.TestIntZero, deserObj.TestIntZero);
            Assert.Equal(obj.TestStringContent, deserObj.TestStringContent);
            Assert.Equal(obj.TestStringNull, deserObj.TestStringNull);
            Assert.Equal(obj.TestIntMax, deserObj.TestIntMax);
            Assert.Equal(obj.TestIntMin, deserObj.TestIntMin);
            Assert.Equal(obj.TestDoubleMax, deserObj.TestDoubleMax);
            Assert.Equal(obj.TestDoubleMin, deserObj.TestDoubleMin);
            Assert.Equal(obj.TestDoubleNan, deserObj.TestDoubleNan);
            Assert.Equal(obj.TestDoubleZero, deserObj.TestDoubleZero);
            Assert.Equal(obj.TestBoolFalse, deserObj.TestBoolFalse);
            Assert.Equal(obj.TestBoolTrue, deserObj.TestBoolTrue);
            Assert.Equal(obj.TestLongMin, deserObj.TestLongMin);
            Assert.Equal(obj.TestLongMax, deserObj.TestLongMax);
            Assert.Equal(obj.TestULongMax, deserObj.TestULongMax);
            Assert.Equal(obj.TestUShortMin, deserObj.TestUShortMin);
            Assert.Equal(obj.TestShortMin, deserObj.TestShortMin);
            Assert.Equal(obj.TestFloatMax, deserObj.TestFloatMax);
            Assert.Equal(obj.TestDateTime, deserObj.TestDateTime);
            Assert.Equal(0, deserObj.TestSkipInt);
        }
예제 #2
0
        public void RiskyFlySerialization()
        {
            var origin     = new DateTime(2017, 02, 07);
            var atms       = new double[] { 0.3, 0.32, 0.34 };
            var fwds       = new double[] { 100, 102, 110 };
            var maturities = new DateTime[] { new DateTime(2017, 04, 06), new DateTime(2017, 06, 07), new DateTime(2017, 08, 07) };
            var wingDeltas = new[] { 0.1, 0.25 };
            var riskies    = new[] { new[] { 0.025, 0.015 }, new[] { 0.025, 0.015 }, new[] { 0.025, 0.015 } };
            var flies      = new[] { new[] { 0.0025, 0.0015 }, new[] { 0.0025, 0.0015 }, new[] { 0.0025, 0.0015 } };
            var surface    = new RiskyFlySurface(
                origin, atms, maturities, wingDeltas, riskies, flies, fwds, WingQuoteType.Simple,
                AtmVolType.ZeroDeltaStraddle, Interpolator1DType.Linear,
                Interpolator1DType.LinearInVariance);

            Assert.Equal(atms[1], surface.GetVolForDeltaStrike(0.5, maturities[1], fwds[1]));

            var binSer = new BinarySerializer();

            binSer.PrepareObjectGraph(surface);
            var span = binSer.SerializeObjectGraph();

            var binDeser = new BinaryDeserializer();
            var surface2 = (ObjectWithLists)binDeser.DeserializeObjectGraph(span);

            Assert.Equal(atms[1], surface.GetVolForDeltaStrike(0.5, maturities[1], fwds[1]));
        }
예제 #3
0
        public void CanSerializeFullHashSet()
        {
            var obj    = CreateFull();
            var binSer = new BinarySerializer();

            binSer.PrepareObjectGraph(obj);
            var span = binSer.SerializeObjectGraph();

            var binDeser = new BinaryDeserializer();
            var newObj   = (ObjectWithFullHashSets)binDeser.DeserializeObjectGraph(span);

            Assert.Equal(3, newObj.NestedHashSet.Count);
        }
예제 #4
0
        public void CanSerializeSimpleArrays()
        {
            var serializer = new BinarySerializer();
            var obj        = Create();

            serializer.PrepareObjectGraph(obj);
            var result = serializer.SerializeObjectGraph();

            var deserializer = new BinaryDeserializer();
            var deser        = (BasicArraysObject)deserializer.DeserializeObjectGraph(result);

            Comparer(obj, deser);
        }
예제 #5
0
        public void OneLayerNestedObject()
        {
            var serializer = new BinarySerializer();
            var obj        = Create();

            serializer.PrepareObjectGraph(obj);
            var result = serializer.SerializeObjectGraph();

            var deserializer = new BinaryDeserializer();
            var deser        = (LinearObject)deserializer.DeserializeObjectGraph(result);

            Assert.Null(deser.BasicArraysNull);
            ArraySerializationFacts.Comparer(obj.BasicArrays, deser.BasicArrays);
        }
예제 #6
0
        public void SimpleNestedStructsWork()
        {
            var bin = new BinarySerializer();
            var obj = Create();

            bin.PrepareObjectGraph(obj);
            var data = bin.SerializeObjectGraph();

            var deBin  = new BinaryDeserializer();
            var newObj = (ClassWithStruct)deBin.DeserializeObjectGraph(data);

            Assert.Equal(obj.Struct.TestInt, newObj.Struct.TestInt);
            Assert.Equal(obj.Struct.TestDouble, newObj.Struct.TestDouble);
        }
예제 #7
0
        public void CanSerializeSimpleHashset()
        {
            var obj    = Create();
            var binSer = new BinarySerializer();

            binSer.PrepareObjectGraph(obj);
            var span = binSer.SerializeObjectGraph();

            var binDeser = new BinaryDeserializer();
            var newObj   = (ObjectWithHashsets)binDeser.DeserializeObjectGraph(span);

            Assert.Equal(obj.StringHashset, newObj.StringHashset);
            Assert.Equal(obj.IntHashset, newObj.IntHashset);
            Assert.Null(newObj.NullHashset);
        }
예제 #8
0
        public void CanSerializeSimpleDictionary()
        {
            var obj    = Create();
            var t      = obj.IntDictionary.GetType();
            var i      = t.GetInterfaces();
            var binSer = new BinarySerializer();

            binSer.PrepareObjectGraph(obj);
            var span = binSer.SerializeObjectGraph();

            var binDeser = new BinaryDeserializer();
            var newObj   = (ObjectWithDictionaries)binDeser.DeserializeObjectGraph(span);

            Assert.Equal(obj.StringDictionary, newObj.StringDictionary);
            Assert.Equal(obj.IntDictionary, newObj.IntDictionary);
            Assert.Null(newObj.NullDictionary);
        }
예제 #9
0
        public static object QUtils_DeSerializeObject(
            [ExcelArgument(Description = "Output object name")] string ObjectName,
            [ExcelArgument(Description = "Object type, e.g. Qwack.Core.Models.IAssetFxModel, Qwack.Core")] string ObjectType,
            [ExcelArgument(Description = "Filename")] string FileName)
        {
            return(ExcelHelper.Execute(_logger, () =>
            {
                var t = Type.GetType(ObjectType);
                var s = new BinaryDeserializer();
                var bytes = System.IO.File.ReadAllBytes(FileName);
                var obj = s.DeserializeObjectGraph(bytes);

                var method = typeof(ContainerStores).GetMethod("PutObjectToCache");
                var generic = method.MakeGenericMethod(t);
                generic.Invoke(null, new object[] { ObjectName, obj });

                return $"{ObjectName}¬1";
            }));
        }
예제 #10
0
        public void CanSerializeEnums()
        {
            var ser   = new BinarySerializer();
            var deser = new BinaryDeserializer();

            var obj = Create();

            ser.PrepareObjectGraph(obj);
            var span = ser.SerializeObjectGraph();

            var newObj = (EnumObject)deser.DeserializeObjectGraph(span);

            Assert.Equal(obj.IntEnum1, newObj.IntEnum1);
            Assert.Equal(obj.IntEnum2, newObj.IntEnum2);
            Assert.Equal(obj.ShortEnum1, newObj.ShortEnum1);
            Assert.Equal(obj.ShortEnum2, newObj.ShortEnum2);
            Assert.Equal(obj.LongEnum1, newObj.LongEnum1);
            Assert.Equal(obj.LongEnum2, newObj.LongEnum2);
        }