Ejemplo n.º 1
0
        public void SystemTextJsonTest()
        {
            var serializer = new SystemTextJsonSerializer();

            var now = DateTimeOffset.Now;

            Assert.Equal(now, serializer.Deserialize <DateTimeOffset>(serializer.Serialize(now)));
        }
Ejemplo n.º 2
0
        public void Deserialize_String_Success()
        {
            // arrange
            var jsonString = File.ReadAllText(@"Data\card1.json");

            var serializer = new SystemTextJsonSerializer();

            // act
            var result = serializer.Deserialize <RootCardDto>(jsonString);

            // assert
            Assert.Equal("Abundance", result.Card.Name);
        }
Ejemplo n.º 3
0
        public void Deserialize_Stream_Success()
        {
            // arrange
            using var stream = File.OpenRead(@"Data\card1.json");

            var serializer = new SystemTextJsonSerializer();

            // act
            var result = serializer.Deserialize <RootCardDto>(stream);

            // assert
            Assert.Equal("Abundance", result.Card.Name);
        }
Ejemplo n.º 4
0
    public async Task CheckEncodingBug()
    {
        var utf32Serializer = new SystemTextJsonSerializer(new SimpleAssemblyQualifiedMessageTypeNameConvention(), encoding: Encoding.UTF32);
        var utf8Serializer  = new SystemTextJsonSerializer(new SimpleAssemblyQualifiedMessageTypeNameConvention(), encoding: Encoding.UTF8);

        var transportMessage = await utf8Serializer.Serialize(new Message(new Dictionary <string, string>(), new Something("hej")));

        var roundtripped = await utf32Serializer.Deserialize(transportMessage);

        var something = roundtripped.Body as Something ?? throw new AssertionException($"Message body {roundtripped.Body} was not Something");

        Assert.That(something.Text, Is.EqualTo("hej"));
    }
Ejemplo n.º 5
0
        public void Use_JsonNet_For_Requests()
        {
            using var server = HttpServerFixture.StartServer(CaptureBody);
            _body            = null;
            var serializer = new SystemTextJsonSerializer();

            var testData = Fixture.Create <TestClass>();

            var client  = new RestClient(server.Url).UseSystemTextJson();
            var request = new RestRequest().AddJsonBody(testData);

            var expected = testData;

            client.Post(request);

            var actual = serializer.Deserialize <TestClass>(new RestResponse {
                Content = _body
            });

            actual.Should().BeEquivalentTo(expected);

            void CaptureBody(HttpListenerRequest req, HttpListenerResponse response) => _body = req.InputStream.StreamToString();
        }