Example #1
0
 public static String GetInputTemplate()
 {
     STR_OORInput input = new STR_OORInput();
     Serializer serializer = new Serializer(typeof(STR_OORInput));
     String jsonText = serializer.Serialize(input);
     return jsonText;
 }
 public void SerializeShortTest(short expected)
 {
     Serializer s = new Serializer(typeof(short));
     s.Config.SetJsonStrictOptions();
     string result = s.Serialize(expected);
     Assert.AreEqual(expected.ToString(CultureInfo.InvariantCulture), result.Trim(), "Short did not serialize correctly");
 }
Example #3
0
 public String GetInputTemplate()
 {
     EDoorInput input = new EDoorInput();
     Serializer serializer = new Serializer(typeof(EDoorInput));
     String jsonText = serializer.Serialize(input);
     return jsonText;
 }
 public void DeepCircularReferenceError()
 {
     Serializer s = new Serializer(typeof(MockReferenceObject));
     s.Config.ReferenceWritingType = SerializationContext.ReferenceOption.ErrorCircularReferences;
     string result = s.Serialize(deep);
     MockReferenceObject actual = (MockReferenceObject)s.Deserialize(result);
 }
 public void SerializeBoolTest(bool Value, string Expected)
 {
     Serializer s = new Serializer(typeof(bool));
     s.Config.SetJsonStrictOptions();
     string result = s.Serialize(Value);
     Assert.AreEqual(Expected, result.Trim(), "Bool did not serialize correctly");
 }
 public void ConvertGuidTest()
 {
     Serializer s = new Serializer(typeof(Guid));
     Guid g = Guid.NewGuid();
     string result = s.Serialize(g);
     Guid actual = (Guid)s.Deserialize(result);
     Assert.AreEqual(g, actual, "Guid test failed");
 }
 public void CircularReferenceIgnore()
 {
     Serializer s = new Serializer(typeof(MockReferenceObject));
     s.Config.ReferenceWritingType = SerializationContext.ReferenceOption.IgnoreCircularReferences;
     string result = s.Serialize(simple);
     MockReferenceObject actual = (MockReferenceObject)s.Deserialize(result);
     Assert.IsNull(actual.Reference.Reference);
 }
 public void TestCollectionHandler()
 {
     Serializer s = new Serializer(typeof(MockCollection), "TestCollectionHandlers");
     MockCollection coll = new MockCollection("test");
     string result = s.Serialize(coll);
     MockCollection actual = (MockCollection) s.Deserialize(result);
     Assert.AreEqual(coll.Value(), actual.Value(), "MockCollectionHandler not configured correctly");
 }
 public void SimpleConstructorNoInitTest()
 {
     MyPointConstructor pt = new MyPointConstructor(3, 9);
     Serializer s = new Serializer(pt.GetType());
     string result = s.Serialize(pt);
     MyPointConstructor actual = (MyPointConstructor)s.Deserialize(result);
     Assert.AreEqual(pt, actual, "Simple Constructor with no initializer failed");
 }
 public void ClassAttributeTest()
 {
     Serializer serializer = new Serializer(typeof(MyImmutablePoint));
     MyImmutablePoint expectedPt = new MyImmutablePoint(12, -10);
     string result = serializer.Serialize(expectedPt);
     MyImmutablePoint actualPt = (MyImmutablePoint) serializer.Deserialize(result);
     Assert.AreEqual(expectedPt, actualPt, "MyImmutablePoint class not serialized correctly");
 }
 public void WhenHasProtectedField_ItsNotSerialized()
 {
     MockFields src = new MockFields();
     src.SetProtected(true);
     Serializer s = new Serializer(typeof(MockFields));
     string result = s.Serialize(src);
     MockFields dest = (MockFields)s.Deserialize(result);
     Assert.IsFalse(dest.GetProtected());            
 }
 public void TestIntField()
 {
     MockFields src = new MockFields();
     src.IntValue = 23;
     Serializer s = new Serializer(typeof(MockFields));
     string result = s.Serialize(src);
     MockFields dest = (MockFields) s.Deserialize(result);
     Assert.AreEqual(23, dest.IntValue);
 }
 public void SerializeLongTest(long expected)
 {
     Serializer s = new Serializer(typeof(long));
     s.Config.SetJsonStrictOptions();
     string result = s.Serialize(expected);
     Assert.AreEqual(expected.ToString(CultureInfo.InvariantCulture), result.Trim(), "long did not serialize correctly");
     long actual = (long)s.Deserialize(result);
     Assert.AreEqual(expected, actual, "long did not deserialize correctly");
 }
 public void OnReadOnlyObject_ObjectIsSerialized()
 {
     ObjectParent parent = new ObjectParent();
     parent.Item.Value = "TestValue";
     Serializer s = new Serializer(typeof(ObjectParent));
     string result = s.Serialize(parent);
     ObjectParent actual = (ObjectParent)s.Deserialize(result);
     Assert.AreEqual("TestValue", actual.Item.Value, "Readonly object value not set properly");
 }
        public void RMDJsonTest()
        {
            RawMarketData rmd = new RawMarketData("testCode", Detail.ProductType.KospiFuture);
            RawMarketDataJson rmdJson = new RawMarketDataJson(rmd);

            Serializer serializer = new Serializer(typeof(RawMarketDataJson));
            string jsonText = serializer.Serialize(rmdJson);

            RawMarketDataJson rmdJson2 = (RawMarketDataJson)serializer.Deserialize(jsonText);
        }
        public void GetPossibleNotionalByIndicatorTest()
        {
            string strategyName = "unittest_position";
            long maxNotional = 1000;

            StrategyManager.Ins().UnRegister(strategyName);
            AgentManager.Ins().Clear();

            STR_KtbSkel factory = new STR_KtbSkel();
            Input_KtbSkel input = new Input_KtbSkel();
            input.MaxNotional = maxNotional;
            input.Spot10yrCode = "KR1035027161";
            input.Future10yrCode = "167FC000";

            Serializer serializer = new Serializer(typeof(Input_KtbSkel));
            String jsonText = serializer.Serialize(input);

            STR_KtbSkel strategy = StrategyBuilder_KtbSkel.CreateStrategy(jsonText, strategyName);
            PrivateObject po = new PrivateObject(strategy);
            STR_KtbSkel_Accessor acc = new STR_KtbSkel_Accessor(po);
            acc.SetAccountOrderLimit();

            ProcessController_KtbSkel controller = acc.Controller;
            ProcessController_KtbSkel_Accessor accController = new ProcessController_KtbSkel_Accessor(
                new PrivateObject(controller));

            ProcessState_Default ps = accController._processState as ProcessState_Default;
            ProcessState_Default_Accessor psAcc = new ProcessState_Default_Accessor(
                new PrivateObject(ps));

            long notional = psAcc.GetPossibleNotionalByIndicator_Out(10F);
            Assert.AreEqual((-500), notional);

            Assert.AreEqual(false, accController.SortedPositionStack.IsFull(10F));

            notional = psAcc.GetPossibleNotionalByIndicator_Out(6F);
            Assert.AreEqual((-100), notional);
            Assert.AreEqual(false, accController.SortedPositionStack.IsFull(6F));

            notional = psAcc.GetPossibleNotionalByIndicator_Out(5F);
            Assert.AreEqual(0, notional);
            Assert.AreEqual(true, accController.SortedPositionStack.IsFull(5F));

            notional = psAcc.GetPossibleNotionalByIndicator_Out(3.0F);
            Assert.AreEqual(200, notional);
            Assert.AreEqual(true, accController.SortedPositionStack.IsFull(3F));

            notional = psAcc.GetPossibleNotionalByIndicator_Out(0F);
            Assert.AreEqual(500, notional);
            Assert.AreEqual(true, accController.SortedPositionStack.IsFull(0F));

            notional = psAcc.GetPossibleNotionalByIndicator_Out(-1F);
            Assert.AreEqual(500, notional);
            Assert.AreEqual(true, accController.SortedPositionStack.IsFull(-1F));
        }
 public void StringArrayListTest()
 {
     Serializer s = new Serializer(typeof(ArrayList));
     ArrayList strings = new ArrayList();
     strings.Add("one");
     strings.Add("two");
     strings.Add("3");
     string result = s.Serialize(strings);
     ArrayList actual = (ArrayList) s.Deserialize(result);
     CollectionAssert.AreEqual(strings, actual);            
 }
 public void OnReadOnlyCollection_CollectionIsSerialized()
 {
     CollParent parent = new CollParent();
     parent.Items.Add(new CollItem("2"));
     parent.Items.Add(new CollItem("Two"));
     Serializer s = new Serializer(typeof(CollParent));
     string result = s.Serialize(parent);
     CollParent actual = (CollParent)s.Deserialize(result);
     Assert.AreEqual(2, actual.Items.Count, "Wrong item count on readonly collection");
     Assert.AreEqual("2", actual.Items[0].Value, "Wrong item in first position");
     Assert.AreEqual("Two", actual.Items[1].Value, "Wrong item in first position");
 }
        public void WhenHasPublicObjectField_ObjectIsSerialized()
        {
            MockFields src = new MockFields();
            SimpleObject so = new SimpleObject();
            so.IntValue = 23;
            src.SimpleObj = so;
            Serializer s = new Serializer(typeof(MockFields));
            string result = s.Serialize(src);
            MockFields dest = (MockFields)s.Deserialize(result);
            Assert.AreEqual(23, dest.SimpleObj.IntValue);

        }
        public void CallbackTest()
        {
            MockCallbackObject expected = new MockCallbackObject();
            expected.Name = "callback";

            Serializer s = new Serializer(expected.GetType());
            string result = s.Serialize(expected);
            Assert.AreEqual(1, expected.BeforeSerializeCount, "BeforeSerialize incorrect count");
            Assert.AreEqual(1, expected.AfterSerializeCount, "AfterSerialize incorrect count");

            MockCallbackObject actual = (MockCallbackObject)s.Deserialize(result);
            Assert.AreEqual(1, actual.AfterDeserializeCount, "AfterDeserialize incorrect count");
        }
Example #21
0
        public void LogOutMarketData(String path)
        {
            Serializer serializer = new Serializer(typeof(MarketDataSaveCollection));
            String jsonText = serializer.Serialize(_data);

            FileStream fs = new FileStream(path, FileMode.CreateNew, FileAccess.Write, FileShare.Read);
            StreamWriter sw = new StreamWriter(fs);
            sw.AutoFlush = true;

            sw.Write(jsonText);

            sw.Close();
            fs.Close();
        }
        public void TestISODateTime()
        {
            DateTimeExpressionHandler handler = new DateTimeExpressionHandler("O");
            Serializer s = new Serializer(typeof(DateTime));
            s.Config.ExpressionHandlers.InsertBefore(typeof(DateTimeExpressionHandler), handler);
            s.Config.SetJsonStrictOptions();
            s.Config.IsCompact = true;
            DateTime source = new DateTime(2008, 10, 9, 13, 23, 45);
            string result = s.Serialize(source);
            Assert.AreEqual(string.Format("\"{0:O}\"", source), result, "DateTime not serialized correctly using ISO DateTime Format");

            DateTime deserialized = (DateTime)s.Deserialize(result);
            Assert.AreEqual(source, deserialized, "DateTime did not deserialize properly using ISO DateTime Format");
        }
 public void WhenCustomMetaDataIsReturn_ItsSerializedCorrectly()
 {
     Serializer s = new Serializer(typeof(CustomClass));
     s.Config.TypeHandlerFactory = new CustomTypeDataRepository(typeof(CustomClassTypeHandler), s.Config);
     CustomClass cust = new CustomClass();
     cust.SetID(23);
     cust.SetName("Frank");
     cust.Value = 999;
     string result = s.Serialize(cust);
     CustomClass dest = (CustomClass)s.Deserialize(result);
     Assert.AreEqual(23, dest.GetID());
     Assert.AreEqual("Frank", dest.GetName());
     Assert.AreEqual(999, dest.Value);
 }
 public void IntListTest()
 {
     Serializer s = new Serializer(typeof(List<int>));
     List<int> ints = new List<int>();
     ints.Add(0);
     ints.Add(int.MinValue);
     ints.Add(int.MaxValue);
     ints.Add(-23);
     ints.Add(456);
     ints.Add(int.MaxValue - 1);
     ints.Add(int.MinValue + 1);
     string result = s.Serialize(ints);
     List<int> actual = (List<int>)s.Deserialize(result);
     CollectionAssert.AreEqual(ints, actual);
 }
        public void IgnorePropertyTest()
        {
            MyLine line = new MyLine();
            line.Start = new MyImmutablePoint(1, 5);
            line.End = new MyImmutablePoint(2, 12);

            Serializer s = new Serializer(typeof(MyLine), "TestIgnoreProperties");
            string result = s.Serialize(line);
            MyLine actual = (MyLine)s.Deserialize(result);
            Assert.IsNull(actual.Start, "Line start should be ignored");
            Assert.IsNull(actual.End, "Line end should be ignored");
            // converters should not be called on ignored properties
            Assert.AreEqual(0, MyLinePointConverter.ConvertFromCount, "Property ConvertFrom not called correct amount of times");
            Assert.AreEqual(0, MyLinePointConverter.ConvertToCount, "Property ConvertTo not called correct amount of times");
        }
        void Generate()
        {
            Input_KtbSkel input = new Input_KtbSkel();
            input.MaxNotional = 1000;
            input.Spot10yrCode = "KR1035027161";
            input.Future10yrCode = "167FC000";
            Serializer serializer = new Serializer(typeof(Input_KtbSkel));
            String jsonText = serializer.Serialize(input);

            STR_KtbSkel strategy = StrategyBuilder_KtbSkel.CreateStrategy(jsonText, "test ktb skel scenario");
            PrivateObject po = new PrivateObject(strategy);
            _accSTR_KtbSkel = new STR_KtbSkel_Accessor(po);
            _accSTR_KtbSkel.SetAccountOrderLimit();

            _accController = new ProcessController_KtbSkel_Accessor(
                new PrivateObject(_accSTR_KtbSkel.Controller));
        }
        public void TestKtbSkelCreateStrategy()
        {
            STR_KtbSkel factory = new STR_KtbSkel();
            Input_KtbSkel input = new Input_KtbSkel();
            input.Spot10yrCode = "KR1035027161";
            input.Future10yrCode = "167FC000";
            Serializer serializer = new Serializer(typeof(Input_KtbSkel));
            String jsonText = serializer.Serialize(input);

            STR_KtbSkel strategy = StrategyBuilder_KtbSkel.CreateStrategy(jsonText, "test ktb skel");
            PrivateObject po = new PrivateObject(strategy);
            STR_KtbSkel_Accessor acc = new STR_KtbSkel_Accessor(po);
            acc.SetAccountOrderLimit();

            TestSTR_KtbSkel_Raw(acc);
            TestController_Raw(acc);
        }
        public void OnReadOnlyArray_ExceptionIsThrown()
        {
            ArrayParent parent = new ArrayParent();
            Serializer s = new Serializer(typeof(ArrayParent));
            string result = s.Serialize(parent);
            bool thrown = false;
            try
            {
                ArrayParent actual = (ArrayParent)s.Deserialize(result);
            }
            catch (InvalidOperationException)
            {
                thrown = true;
            }

            Assert.IsTrue(thrown, "Expected InvalidOperationException to be thrown when attempting to update get-only array property");
        }
        public void SimpleObjectLinkedList()
        {
            Serializer s = new Serializer(typeof(LinkedList<SimpleObject>));
            LinkedList<SimpleObject> objects = new LinkedList<SimpleObject>();
            SimpleObject obj = null;
            
            // object 1
            obj = new SimpleObject();
            obj.BoolValue = true;
            obj.ByteValue = 0xf1;
            obj.CharValue = 'a';
            obj.DoubleValue = double.MinValue;
            obj.FloatValue = float.MinValue;
            obj.IntValue = 32;
            obj.LongValue = 39000;
            obj.ShortValue = 255;
            obj.StringValue = "AA";

            objects.AddLast(obj);

            // object 2
            obj = new SimpleObject();
            obj.BoolValue = false;
            obj.ByteValue = 0xf2;
            obj.CharValue = 'b';
            obj.DoubleValue = double.MaxValue;
            obj.FloatValue = float.MaxValue;
            obj.IntValue = 33;
            obj.LongValue = 39001;
            obj.ShortValue = 256;
            obj.StringValue = "BB";

            objects.AddLast(obj);

            string result = s.Serialize(objects);

            LinkedList<SimpleObject> actual = (LinkedList<SimpleObject>)s.Deserialize(result);

            CollectionAssert.AreEqual(objects, actual);
        }
        public void DataTableSerialize()
        {
            DataTable dt = new DataTable("MyTable");
            dt.Columns.Add("IntColumn", typeof(int));
            dt.Columns.Add("StringColumn", typeof(string));
            dt.Columns.Add("BoolColumn", typeof(bool));
            dt.Columns.Add("DateTimeColumn", typeof(DateTime));
            dt.Columns.Add("DoubleColumn", typeof(double));
            dt.Rows.Add((int)32, "row 1", true, new DateTime(2009, 9, 1), 213.45d);
            dt.Rows.Add((int)64, "row 2", false, new DateTime(2005, 5, 15), 124.95d);

            Serializer s = new Serializer(typeof(DataTable));
            s.Config.ExpressionHandlers.Insert(0, new DataTableExpressionHandler());
            s.Config.RegisterTypeConverter(typeof(Type), new TypeToStringConverter()); // for DataType property of Column
            string result = s.Serialize(dt);

            DataTable dtResult = (DataTable) s.Deserialize(result);
            DataSet expected = new DataSet();
            expected.Tables.Add(dt);

            DataSet actual = new DataSet();
            actual.Tables.Add(dtResult);
            DataAssert.AreDataEqual(expected, actual);
        }