Example #1
0
        public async Task Given_Spec_When_Build_Then_WriterSerializesObject()
        {
            var obj      = new { Test = true };
            var response = A.Dummy <IWebResponse>();

            var sut        = new JsonWebWriterSpecification();
            var jsonWriter = sut.Build();

            await jsonWriter(response, obj);

            const string expectedBody = "{\"Test\":true}";

            A.CallTo(() => response.WriteBodyAsync(A <string> .That.IsEqualTo(expectedBody))).MustHaveHappenedOnceExactly();
            A.CallToSet(() => response.ContentType).To("application/json").MustHaveHappened();
        }
Example #2
0
        public async Task Given_SpecWithOverrides_When_Build_Then_WriterSerializesObjectWithOptions()
        {
            var obj      = new { Test = true };
            var response = A.Dummy <IWebResponse>();

            var sut = new JsonWebWriterSpecification();

            sut.Options(new JsonSerializerOptions {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            });
            var jsonWriter = sut.Build();

            await jsonWriter(response, obj);

            const string expectedBody = "{\"test\":true}";

            A.CallTo(() => response.WriteBodyAsync(A <string> .That.IsEqualTo(expectedBody))).MustHaveHappenedOnceExactly();
            A.CallToSet(() => response.ContentType).To("application/json").MustHaveHappened();
        }