Esempio n. 1
0
        private static async Task CreateResponseOnException(HttpContext httpContext, int status, Exception ex)
        {
            var response = new CommonResponse <Exception>(status, ex.Message, ex);

            byte[] buffer = response.ToJsonBuffer();
            await httpContext.Response.Body.WriteAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
        }
        public void ShouldComputeBufferUtf8Model_WhenToJsonExtentsionMethodeCalled()
        {
            CommonResponse <string> response = new CommonResponse <string>(200, "Whoops, it failed!", "my_payload");

            byte[] buffer = response.ToJsonBuffer();

            Assert.NotNull(buffer);
            Assert.NotEmpty(buffer);
            Assert.Equal("{\"internalCode\":200,\"message\":\"Whoops, it failed!\",\"payload\":\"my_payload\"}", Encoding.UTF8.GetString(buffer));
        }