コード例 #1
0
        public void EscapingAndEncodingStrings()
        {
            var msg = context.NewMessage(new Field("s", "\\\b\f\t\n\r\"\u0001"));

            var stringWriter = new StringWriter();
            var writer = new FudgeJSONStreamWriter(context, stringWriter);
            writer.WriteMsg(msg);
            string s = stringWriter.ToString();

            AssertEqualsNoWhiteSpace(@"{""s"" : ""\\\b\f\t\n\r\""\u0001""
        }

        [Fact]
        public void FieldsWithSameNameBecomeArrays()
        {
            var msg = context.NewMessage(new Field("outer",
                                            new Field("a", false),
                                            new Field("b", 17.3),
                                            new Field("a", "test")));

            var stringWriter = new StringWriter();
            var writer = new FudgeJSONStreamWriter(context, stringWriter);
            writer.WriteMsg(msg);
            string s = stringWriter.ToString();

            AssertEqualsNoWhiteSpace("{\"outer\" : {\"a\" : [false, \"test\"], \"b\" : 17.3} }", s);
        }
コード例 #2
0
        public void EscapingAndEncodingStrings()
        {
            var msg = context.NewMessage(new Field("s", "\\\b\f\t\n\r\"\u0001"));

            var stringWriter = new StringWriter();
            var writer = new FudgeJSONStreamWriter(context, stringWriter);
            writer.WriteMsg(msg);
            string s = stringWriter.ToString();

            AssertEqualsNoWhiteSpace(@"{""s"" : ""\\\b\f\t\n\r\""\u0001""}", s);
        }
コード例 #3
0
        public void SimpleExample()
        {
            var msg = context.NewMessage(new Field("outer",
                                            new Field("a", 7),
                                            new Field("b", "fred")));
            var stringWriter = new StringWriter();
            var writer = new FudgeJSONStreamWriter(context, stringWriter);
            writer.WriteMsg(msg);
            string s = stringWriter.ToString();

            AssertEqualsNoWhiteSpace("{\"outer\" : {\"a\" : 7, \"b\" : \"fred\"} }", s);
        }
コード例 #4
0
        public void FieldsWithSameNameBecomeArrays()
        {
            var msg = context.NewMessage(new Field("outer",
                                            new Field("a", false),
                                            new Field("b", 17.3),
                                            new Field("a", "test")));

            var stringWriter = new StringWriter();
            var writer = new FudgeJSONStreamWriter(context, stringWriter);
            writer.WriteMsg(msg);
            string s = stringWriter.ToString();

            AssertEqualsNoWhiteSpace("{\"outer\" : {\"a\" : [false, \"test\"], \"b\" : 17.3} }", s);
        }
コード例 #5
0
        public void ArraysOfPrimitiveTypes()
        {
            var msg = context.NewMessage(new Field("bytes", new byte[] {123, 76, 2, 3}),
                                         new Field("shorts", new short[] {10, 11, 12}),
                                         new Field("ints", new int[] {13, 14, 15}),
                                         new Field("longs", new long[] {16, 17, 18}),
                                         new Field("floats", new float[] {1.2f, 3.4f, 5.6f}),
                                         new Field("doubles", new double[] {-1.2, -3.4, -5.6}));

            var stringWriter = new StringWriter();
            var writer = new FudgeJSONStreamWriter(context, stringWriter);
            writer.WriteMsg(msg);
            string s = stringWriter.ToString();

            var testString = "{\"bytes\" : [123, 76, 2, 3]," +
                              "\"shorts\" : [10, 11, 12]," +
                              "\"ints\" : [13, 14, 15]," +
                              "\"longs\" : [16, 17, 18]," +
                              "\"floats\" : [1.2, 3.4, 5.6]," +
                              "\"doubles\" : [-1.2, -3.4, -5.6]}";
            AssertEqualsNoWhiteSpace(testString, s);
        }
コード例 #6
0
        public void LargeMsg()
        {
            var stringWriter = new StringWriter();
            var streamWriter = new FudgeJSONStreamWriter(context, stringWriter);
            FudgeMsg inMsg = StandardFudgeMessages.CreateLargeMessage(context);
            streamWriter.WriteMsg(inMsg);

            var msg = new FudgeJSONStreamReader(context, stringWriter.GetStringBuilder().ToString()).ReadMsg();

            FudgeUtils.AssertAllFieldsMatch(inMsg, msg);
        }
コード例 #7
0
        public void ArraysOfObjects()
        {
            var msg = context.NewMessage(new Field("a",
                                            new Field("x", 1),
                                            new Field("y", 2)),
                                         new Field("a",
                                             new Field("z", 3)));

            var stringWriter = new StringWriter();
            var writer = new FudgeJSONStreamWriter(context, stringWriter);
            writer.WriteMsg(msg);
            string s = stringWriter.ToString();

            AssertEqualsNoWhiteSpace("{\"a\" : [ {\"x\" : 1, \"y\" : 2}, {\"z\" : 3} ] }", s);
        }
コード例 #8
0
        public void StringRepresentations_FRN89()
        {
            var stringWriter = new StringWriter();
            var writer = new FudgeJSONStreamWriter(context, stringWriter);
            writer.WriteMsg(StringsTestMsg);

            // Float/double as per IEEE7 54-2008, string escaped as per RFC 3339, dates and times as per RFC 3339.
            AssertEqualsNoWhiteSpace(StringsTestString, stringWriter.ToString());
        }
コード例 #9
0
        public void FieldNamesAndOrdinalsLogic_FRN86()
        {
            var stringWriter = new StringWriter();
            var writer = new FudgeJSONStreamWriter(context, stringWriter);

            var msg = context.NewMessage(new Field(1, "ord"),
                                         new Field("A", "name"),
                                         new Field("B", 2, "name and ord"),
                                         new Field(null, null, "empty"));
            writer.WriteMsg(msg);
            AssertEqualsNoWhiteSpace("{\"1\" : \"ord\", \"A\" : \"name\", \"B\" : \"name and ord\", \"\" : \"empty\"}", stringWriter.ToString());

            // Now try it preferring ordinals to names
            var stringWriter2 = new StringWriter();
            var settings = new JSONSettings() { PreferFieldNames = false };
            var writer2 = new FudgeJSONStreamWriter(context, settings, stringWriter2);
            writer2.WriteMsg(msg);
            AssertEqualsNoWhiteSpace("{\"1\" : \"ord\", \"A\" : \"name\", \"2\" : \"name and ord\", \"\" : \"empty\"}", stringWriter2.ToString());
        }
コード例 #10
0
        public void DepthChecks()
        {
            var writer = new FudgeJSONStreamWriter(context, new StringWriter());

            Assert.Throws<InvalidOperationException>(() => writer.StartSubMessage("test", null));
            Assert.Throws<InvalidOperationException>(() => writer.WriteField("test", null, null, "test"));
            Assert.Throws<InvalidOperationException>(() => writer.EndSubMessage());
            Assert.Throws<InvalidOperationException>(() => writer.EndMessage());

            writer.StartMessage();
            Assert.Throws<InvalidOperationException>(() => writer.StartMessage());
            Assert.Throws<InvalidOperationException>(() => writer.EndSubMessage());

            writer.StartSubMessage("test", null);
            Assert.Throws<InvalidOperationException>(() => writer.EndMessage());
        }
コード例 #11
0
        public void IndicatorWrittenAsNull()
        {
            var msg = context.NewMessage(new Field("test", IndicatorType.Instance));

            var stringWriter = new StringWriter();
            var writer = new FudgeJSONStreamWriter(context, stringWriter);
            writer.WriteMsg(msg);
            string s = stringWriter.ToString();
            AssertEqualsNoWhiteSpace("{\"test\" : null }", s);
        }
コード例 #12
0
        public void SubMessageAsValueHandled()
        {
            var subMsg = context.NewMessage(new Field("a", 1));
            var stringWriter = new StringWriter();
            var writer = new FudgeJSONStreamWriter(context, stringWriter);

            writer.StartMessage();
            writer.WriteField("test", null, null, subMsg);
            writer.EndMessage();

            string s = stringWriter.ToString();
            AssertEqualsNoWhiteSpace("{\"test\" : {\"a\" : 1} }", s);
        }
コード例 #13
0
        public void RoundTrip()
        {
            var msg = context.NewMessage(new Field("outer",
                                            new Field("a", 7),
                                            new Field("b", "fred")));
            var stringWriter = new StringWriter();
            var writer = new FudgeJSONStreamWriter(context, stringWriter);
            writer.WriteMsg(msg);
            string s = stringWriter.ToString();

            var reader = new FudgeJSONStreamReader(context, s);
            var msg2 = reader.ReadMsg();

            FudgeUtils.AssertAllFieldsMatch(msg, msg2);
        }