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"); }
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 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 TestClearAddBinding() { Serializer s = new Serializer(typeof(object), "TypeBindingClearAdd"); Assert.AreEqual("SimpleObject", s.Config.TypeAliases[typeof(SimpleObject)]); // check that defaults are not mapped Assert.IsNull(s.Config.TypeAliases[typeof(int)]); }
private static Serializer GetSerializer() { Serializer s = new Serializer(typeof(object)); s.Context.OutputTypeComment = false; s.Context.IsCompact = true; return s; }
public SyncRegions GetSyncRegions() { Serializer serializer = new Serializer(typeof(SyncRegions)); serializer.Config.TypeHandlerFactory.SetPropertyNamingStrategy(new CamelCaseNamingStrategy()); return (SyncRegions)doGet("SyncRegions", new NameValueCollection(), serializer); }
public String GetInputTemplate() { EDoorInput input = new EDoorInput(); Serializer serializer = new Serializer(typeof(EDoorInput)); String jsonText = serializer.Serialize(input); return jsonText; }
public static STR_ArbInput GetInput(String inputJson) { Serializer serializer = new Serializer(typeof(STR_ArbInput)); STR_ArbInput input = (STR_ArbInput)serializer.Deserialize(inputJson); return input; }
static STR_Test_PB_HTSInput GetInput(String inputJson) { Serializer serializer = new Serializer(typeof(STR_Test_PB_HTSInput)); STR_Test_PB_HTSInput input = (STR_Test_PB_HTSInput)serializer.Deserialize(inputJson); return input; }
public void VerifyConfigSet() { ValueExpressionHandler handler = new ValueExpressionHandler(); Serializer s = new Serializer(typeof(object)); s.Config.ExpressionHandlers.Insert(0, handler); Assert.AreSame(s.Config, handler.Config, "IConfigurationAware.Config not set on ExpressionHandler when inserted into Handlers collection"); }
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 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 SelfConversionTest() { SelfConverter expected = new SelfConverter(); Serializer s = new Serializer(typeof(SelfConverter)); string result = s.Serialize(expected); SelfConverter actual = (SelfConverter)s.Deserialize(result); Assert.AreEqual(expected, actual, "Selfconversion failed"); }
public void TestRegisterTypeConverter() { Serializer s = new Serializer(typeof(object), "TestRegisterTypeConverter"); IJsonTypeConverter typeConverter = s.Config.GetTypeHandler(typeof(SimpleObject)).TypeConverter; IJsonTypeConverter propConverter = s.Config.GetTypeHandler(typeof(SimpleObject)).FindProperty("BoolValue").TypeConverter; Assert.IsNotNull(typeConverter, "No converter for simple object registered"); Assert.IsNotNull(propConverter, "No converter for simple object, BoolValue property registered"); }
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 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 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 Deserialize_NewConstructorStyle_WorksSameAsCast() { Serializer s = new Serializer(typeof(CtorMock)); s.Config.TypeAliases.Add(typeof(CtorMock), "CtorMock"); s.Config.TypeAliases.Add(typeof(CtorMock2), "CtorMock2"); string text = "new CtorMock2(1, 'test')"; CtorMock x = (CtorMock)s.Deserialize(text); Assert.IsInstanceOfType(typeof(CtorMock2), x, "Wrong Type"); }
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 override void UpdateUI(String strategyName, String header, String jsonData) { if (header.CompareTo(StrategyCommand.WAS_DIFF_DATA) == 0) { Serializer ser = new Serializer(typeof(Was_Diff_DataForUI)); Was_Diff_DataForUI data = (Was_Diff_DataForUI)ser.Deserialize(jsonData); DrawDiffData(data); } }
public void TestRemoveBinding() { Serializer s = new Serializer(typeof(object), "TypeBindingRemove"); // verify int is not mapped // <remove type="System.Int32, mscorlib" /> Assert.IsNull(s.Config.TypeAliases[typeof(int)]); // verify float is not mapped // <remove alias="float" /> Assert.IsNull(s.Config.TypeAliases[typeof(float)]); }
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 TestResolveConcreteTypeToInterfaceProperty() { Serializer serializer = new Serializer(typeof(Message)); string json = @"{ type:'Type1', value: {A:1, B: 2} }"; serializer.Context.ParsingStages.Add(new CustomTypeResolver()); Message result = (Message)serializer.Deserialize(json); IType value = result.value; Assert.IsNotNull(value, "value not deserialized"); Assert.IsInstanceOfType(typeof(Type1), value, "Incorrect type on value"); Assert.AreEqual(1, ((Type1)value).A, "obj1.A"); Assert.AreEqual(2, ((Type1)value).B, "obj1.B"); }
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"); }