Exemple #1
0
        public async Task TheWriteToStreamAsyncMethodShouldAcceptNullRequest()
        {
            // Arrange
            var formatter = new PartialJsonMediaTypeFormatter();

            Mock.Get(this.httpResponse)
            .SetupGet(httpResponse => httpResponse.StatusCode)
            .Returns(200);

            // Act
            using (var memoryStream = new MemoryStream())
            {
                await formatter.WriteToStreamAsync(typeof(object), new { }, memoryStream, null, null);
            }
        }
Exemple #2
0
            private async static Task <T> Test <T>(HttpRequestMessage request, T value, bool ignoreCase = false)
            {
                var formatter = new PartialJsonMediaTypeFormatter()
                {
                    IgnoreCase = ignoreCase
                }.GetPerRequestFormatterInstance(null, request, null);

                using (var memoryStream = new MemoryStream())
                {
                    await formatter.WriteToStreamAsync(typeof(T), value, memoryStream, null, null);

                    memoryStream.Flush();
                    memoryStream.Position = 0;

                    return((T)await formatter.ReadFromStreamAsync(typeof(T), memoryStream, null, null));
                }
            }