예제 #1
0
        public async Task SerializeClassNonIndented_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{CamelCaseEnumValues | CamelCasePropertyNames | RemoveDefaultValues | OmitGuidDashes}");

            var expected = _encoding.GetBytes(@"{""itemId"":""7e900426dbc246bcbe100d503644b830"",""itemName"":""alfa"",""subItems"":[""bravo"",""charlie""],""options"":""all"",""createTime"":""2019-01-02T03:04:05.0060007Z""}");

            var actual = await jsonSerializer.Serialize(TestItem);

            Assert.Equal(expected, actual);
        }
예제 #2
0
        public async Task SerializeStringDefaultOptions_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{Default}");

            var expected = _encoding.GetBytes("\"hello, world\"");

            var actual = await jsonSerializer.Serialize("hello, world");

            Assert.Equal(expected, actual);
        }
예제 #3
0
        public async Task SerializeClassDefaultOptions_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{Default}");

            var expected = _encoding.GetBytes(@"{""itemId"":""7e900426dbc246bcbe100d503644b830"",""itemName"":""alfa"",""subItems"":[""bravo"",""charlie""],""options"":""all"",""createTime"":""2019-01-02T03:04:05.0060007Z""}");

            var actual = await jsonSerializer.Serialize(TestItem);

            Assert.Equal(expected, actual);
        }
예제 #4
0
        public async Task DeserializeNullGuidDefaultOptions_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{Default}");

            var serialized = await jsonSerializer.Serialize(null as Guid?);

            var actual = await jsonSerializer.Deserialize <Guid?>(serialized);

            Assert.Null(actual);
        }
예제 #5
0
        public async Task SerializeNullClassDefaultOptions_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{Default}");

            var expected = _encoding.GetBytes("null");

            var actual = await jsonSerializer.Serialize(null as Item);

            Assert.Equal(expected, actual);
        }
예제 #6
0
        public async Task SerializeBigInteger_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{Default}");

            var sourceString = string.Join(string.Empty, Enumerable.Repeat("1234567890", 10));

            var actual = await jsonSerializer.Serialize(BigInteger.Parse(sourceString));

            Assert.Equal(
                _encoding.GetBytes($"\"{sourceString}\""),
                actual);
        }
예제 #7
0
        public async Task SerializeIReadOnlyListOfStringDefaultOptions_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{Default}");

            var expected = _encoding.GetBytes(@"[""alfa"",""bravo""]");

            var actual = await jsonSerializer.Serialize(new List <string> {
                "alfa", "bravo"
            } as IReadOnlyList <string>);

            Assert.Equal(expected, actual);
        }
예제 #8
0
        public async Task SerializeNullableGuidDefaultOptions_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{Default}");

            var guid = new Guid("7e900426dbc246bcbe100d503644b830") as Guid?;

            var expected = _encoding.GetBytes("\"7e900426dbc246bcbe100d503644b830\"");

            var actual = await jsonSerializer.Serialize(guid);

            Assert.Equal(expected, actual);
        }
예제 #9
0
        public async Task DeserializeGuidDefaultOptions_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{Default}");

            var expected = new Guid("7e900426dbc246bcbe100d503644b830");

            var serialized = await jsonSerializer.Serialize(expected);

            var actual = await jsonSerializer.Deserialize <Guid>(serialized);

            Assert.Equal(expected, actual);
        }
예제 #10
0
        public async Task DeserializeDateTimeDefaultOptions_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{Default}");

            var expected = new DateTime(2019, 01, 02, 03, 04, 05, 006, DateTimeKind.Utc).AddTicks(0007);

            var serialized = await jsonSerializer.Serialize(expected);

            var actual = await jsonSerializer.Deserialize <DateTime>(serialized);

            Assert.Equal(expected, actual);
        }
예제 #11
0
        public async Task SerializeGuidWithGuidDashes_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{CamelCaseEnumValues | CamelCasePropertyNames | RemoveDefaultValues}");

            var guid = new Guid("7e900426dbc246bcbe100d503644b830");

            var expected = _encoding.GetBytes("\"7e900426-dbc2-46bc-be10-0d503644b830\"");

            var actual = await jsonSerializer.Serialize(guid);

            Assert.Equal(expected, actual);
        }
예제 #12
0
        public async Task SerializeDateTimeDefaultOptions_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{Default}");

            var dateTime = new DateTime(2019, 01, 02, 03, 04, 05, 006, DateTimeKind.Utc).AddTicks(0007);

            var expected = _encoding.GetBytes("\"2019-01-02T03:04:05.0060007Z\"");

            var actual = await jsonSerializer.Serialize(dateTime);

            Assert.Equal(expected, actual);
        }
예제 #13
0
        public async Task DeserializeClassDefaultOptions_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{Default}");

            var serialized = await jsonSerializer.Serialize(TestItem);

            var actual = await jsonSerializer.Deserialize <Item>(serialized);

            Assert.Equal(
                JsonConvert.SerializeObject(TestItem),
                JsonConvert.SerializeObject(actual));
        }
예제 #14
0
        public async Task DeserializeClassWithByteOrderMark_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{Default}");

            var serialized = new byte[] { 0xEF, 0xBB, 0xBF }
            .Concat(await jsonSerializer.Serialize(TestItem))
            .ToArray();

            var actual = await jsonSerializer.Deserialize <Item>(serialized);

            Assert.Equal(
                JsonConvert.SerializeObject(TestItem),
                JsonConvert.SerializeObject(actual));
        }
예제 #15
0
        public async Task DeserializeIReadOnlyListOfStringDefaultOptions_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{Default}");

            var expected = new List <string> {
                "alfa", "bravo"
            } as IReadOnlyList <string>;

            var serialized = await jsonSerializer.Serialize(expected);

            var actual = await jsonSerializer.Deserialize <IReadOnlyList <string> >(serialized);

            Assert.Equal(expected, actual);
        }
예제 #16
0
        public async Task DeserializeArrayOfClassDefaultOptions_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{Default}");

            var expected = new[] { TestItem, TestItem };

            var serialized = await jsonSerializer.Serialize(expected);

            var actual = await jsonSerializer.Deserialize <Item[]>(serialized);

            Assert.Equal(
                JsonConvert.SerializeObject(expected),
                JsonConvert.SerializeObject(actual));
        }
예제 #17
0
        public async Task SerializeImmutableBigInteger_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{Default}");

            var sourceString = string.Join(string.Empty, Enumerable.Repeat("1234567890", 10));

            var source = new Immutable <BigInteger>(BigInteger.Parse(sourceString));

            var expected = _encoding.GetBytes($@"{{""property"":""{sourceString}""}}");

            var actual = await jsonSerializer.Serialize(source);

            Assert.Equal(expected, actual);
        }
예제 #18
0
        public async Task DeserializeIReadOnlyListOfClassDefaultOptions_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{Default}");

            var expected = new List <Item> {
                TestItem, TestItem
            } as IReadOnlyList <Item>;

            var serialized = await jsonSerializer.Serialize(expected);

            var actual = await jsonSerializer.Deserialize <IReadOnlyList <Item> >(serialized);

            Assert.Equal(
                JsonConvert.SerializeObject(expected),
                JsonConvert.SerializeObject(actual));
        }
예제 #19
0
        public async Task SerializeJObjectDefaultOptions_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{Default}");

            var jObject = JObject.FromObject(new
            {
                Alfa = "Bravo",

                Charlie = 123
            });

            var expected = _encoding.GetBytes(@"{""Alfa"":""Bravo"",""Charlie"":123}");

            var actual = await jsonSerializer.Serialize(jObject);

            Assert.Equal(expected, actual);
        }
예제 #20
0
        public async Task DeserializeJObjectDefaultOptions_Success()
        {
            var jsonSerializer = new HalforbitJsonSerializer($"{Default}");

            var expected = JObject.FromObject(new
            {
                alfa = "Bravo",

                charlie = "Delta"
            });

            var serialized = await jsonSerializer.Serialize(expected);

            var actual = await jsonSerializer.Deserialize <JObject>(serialized);

            Assert.Equal(
                JsonConvert.SerializeObject(expected),
                JsonConvert.SerializeObject(actual));
        }