public async Task ParsesNullToken_AsASuccessResponse(HttpResponseMessage message, NakedContentParser parser)
        {
            // Fixture setup
            message.Content = new StringContent("null");
            // Exercise system
            var response = await parser.ParseAsync <JToken>(null, message);

            // Verify outcome
            response.Status.Should().Be(JSendStatus.Success);
            response.HasData.Should().BeFalse();
        }
        public async Task ParsesNakedData_AsASuccessResponse(Model model, HttpResponseMessage message,
                                                             NakedContentParser parser)
        {
            // Fixture setup
            message.Content = new StringContent(JsonConvert.SerializeObject(model));
            // Exercise system
            var response = await parser.ParseAsync <Model>(null, message);

            // Verify outcome
            response.Status.Should().Be(JSendStatus.Success);
            response.Data.ShouldBeEquivalentTo(model);
        }
        public async Task Parses204NoContent(NakedContentParser parser)
        {
            // Fixture setup
            var message = new HttpResponseMessage(HttpStatusCode.NoContent)
            {
                Content = new StringContent("")
            };
            // Exercise system and verify outcome
            var response = await parser.ParseAsync <Model>(null, message);

            // Verify outcome
            response.Status.Should().Be(JSendStatus.Success);
            response.HasData.Should().BeFalse();
        }
 public async Task ParsesSuccessResponse_WithoutData(HttpResponseMessage message, NakedContentParser parser)
 {
     // Fixture setup
     message.Content = new StringContent(@"
     {
         ""status"": ""success"",
         ""data"": null
     }");
     // Exercise system
     var response = await parser.ParseAsync<Model>(null, message);
     // Verify outcome
     response.Status.Should().Be(JSendStatus.Success);
     response.HasData.Should().BeFalse();
 }
        public async Task ParsesSuccessResponse_WithoutData(HttpResponseMessage message, NakedContentParser parser)
        {
            // Fixture setup
            message.Content = new StringContent(@"
            {
                ""status"": ""success"",
                ""data"": null
            }");
            // Exercise system
            var response = await parser.ParseAsync <Model>(null, message);

            // Verify outcome
            response.Status.Should().Be(JSendStatus.Success);
            response.HasData.Should().BeFalse();
        }
        public async Task ParsesFailResponse(string reason, HttpResponseMessage message, NakedContentParser parser)
        {
            // Fixture setup
            message.Content = new StringContent(@"
            {
                ""status"": ""fail"",
                ""data"": """ + reason + @"""
            }");
            // Exercise system
            var response = await parser.ParseAsync <Model>(null, message);

            // Verify outcome
            response.Status.Should().Be(JSendStatus.Fail);
            response.Error.Data.Type.Should().Be(JTokenType.String);
            response.Error.Data.Value <string>().Should().Be(reason);
        }
        public async Task ParsesErrorResponse_WithoutDataKey(string message, int code,
                                                             HttpResponseMessage responseMessage, NakedContentParser parser)
        {
            // Fixture setup
            responseMessage.Content = new StringContent(@"
            {
                ""status"": ""error"",
                ""message"": """ + message + @""",
                ""code"": " + code + @"
            }");

            var expectedError = new JSendError(JSendStatus.Error, message, code, null);
            // Exercise system
            var response = await parser.ParseAsync <Model>(null, responseMessage);

            // Verify outcome
            response.Status.Should().Be(JSendStatus.Error);
            response.Error.ShouldBeEquivalentTo(expectedError);
        }
        public async Task ParsesErrorResponse_WithNullCode(string message, DateTime data,
                                                           HttpResponseMessage responseMessage, NakedContentParser parser)
        {
            // Fixture setup
            responseMessage.Content = new StringContent(@"
            {
                ""status"": ""error"",
                ""message"": """ + message + @""",
                ""code"": null,
                ""data"": """ + data + @"""
            }");

            var expectedError = new JSendError(JSendStatus.Error, message, null, JToken.FromObject(data));
            // Exercise system
            var response = await parser.ParseAsync <Model>(null, responseMessage);

            // Verify outcome
            response.Status.Should().Be(JSendStatus.Error);
            response.Error.ShouldBeEquivalentTo(expectedError);
        }
        public async Task ParsesFailResponse_UsingSerializerSettings(
            HttpResponseMessage message, NakedContentParser parser)
        {
            // Fixture setup
            message.Content = new StringContent(@"
            {
                ""status"": ""fail"",
                ""data"": ""1989-01-02T15:14:03.9030824""
            }");

            var serializerSettings = new JsonSerializerSettings
            {
                DateTimeZoneHandling = DateTimeZoneHandling.Utc
            };

            // Exercise system
            var response = await parser.ParseAsync <Model>(serializerSettings, message);

            // Verify outcome
            var date = response.Error.Data.Value <DateTime>();

            date.Kind.Should().Be(DateTimeKind.Utc);
        }
        public async Task ParsesSuccessResponse_WithData_UsingSerializerSettings(
            [NoAutoProperties] DefaultJSendParserTests.ModelWithPrivateDefaultConstructor model,
            HttpResponseMessage message,
            NakedContentParser parser)
        {
            // Fixture setup
            message.Content = new StringContent(@"
            {
                ""status"": ""success"",
                ""data"": " + JsonConvert.SerializeObject(model) + @"
            }");

            var serializerSettings = new JsonSerializerSettings
            {
                ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
            };

            // Exercise system
            var response = await parser.ParseAsync <DefaultJSendParserTests.ModelWithPrivateDefaultConstructor>(serializerSettings, message);

            // Verify outcome
            response.Data.PrivateDefaultConstructorCalled.Should().BeTrue();
        }
        public async Task ParsesErrorResponse_UsingSerializerSettings(
            HttpResponseMessage message, NakedContentParser parser)
        {
            // Fixture setup
            message.Content = new StringContent(@"
            {
                ""status"": ""error"",
                ""message"": ""message"",
                ""data"": ""1989-01-02T15:14:03.9030824""
            }");

            var serializerSettings = new JsonSerializerSettings
            {
                DateTimeZoneHandling = DateTimeZoneHandling.Utc
            };

            // Exercise system
            var response = await parser.ParseAsync<Model>(serializerSettings, message);
            // Verify outcome
            var date = response.Error.Data.Value<DateTime>();
            date.Kind.Should().Be(DateTimeKind.Utc);
        }
        public async Task ParsesErrorResponse_WithNullData(string message, int code,
            HttpResponseMessage responseMessage, NakedContentParser parser)
        {
            // Fixture setup
            responseMessage.Content = new StringContent(@"
            {
                ""status"": ""error"",
                ""message"": """ + message + @""",
                ""code"": " + code + @",
                ""data"": null
            }");

            var expectedError = new JSendError(JSendStatus.Error, message, code, null);
            // Exercise system
            var response = await parser.ParseAsync<Model>(null, responseMessage);
            // Verify outcome
            response.Status.Should().Be(JSendStatus.Error);
            response.Error.ShouldBeEquivalentTo(expectedError);
        }
        public async Task ParsesErrorResponse_WithoutCodeKey(string message, DateTime data,
            HttpResponseMessage responseMessage, NakedContentParser parser)
        {
            // Fixture setup
            responseMessage.Content = new StringContent(@"
            {
                ""status"": ""error"",
                ""message"": """ + message + @""",
                ""data"": """ + data + @"""
            }");

            var expectedError = new JSendError(JSendStatus.Error, message, null, JToken.FromObject(data));
            // Exercise system
            var response = await parser.ParseAsync<Model>(null, responseMessage);
            // Verify outcome
            response.Status.Should().Be(JSendStatus.Error);
            response.Error.ShouldBeEquivalentTo(expectedError);
        }
 public async Task ParsesFailResponse(string reason, HttpResponseMessage message, NakedContentParser parser)
 {
     // Fixture setup
     message.Content = new StringContent(@"
     {
         ""status"": ""fail"",
         ""data"": """ + reason + @"""
     }");
     // Exercise system
     var response = await parser.ParseAsync<Model>(null, message);
     // Verify outcome
     response.Status.Should().Be(JSendStatus.Fail);
     response.Error.Data.Type.Should().Be(JTokenType.String);
     response.Error.Data.Value<string>().Should().Be(reason);
 }
        public async Task ParsesSuccessResponse_WithData_UsingSerializerSettings(
            [NoAutoProperties] DefaultJSendParserTests.ModelWithPrivateDefaultConstructor model,
            HttpResponseMessage message,
            NakedContentParser parser)
        {
            // Fixture setup
            message.Content = new StringContent(@"
            {
                ""status"": ""success"",
                ""data"": " + JsonConvert.SerializeObject(model) + @"
            }");

            var serializerSettings = new JsonSerializerSettings
            {
                ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
            };

            // Exercise system
            var response = await parser.ParseAsync<DefaultJSendParserTests.ModelWithPrivateDefaultConstructor>(serializerSettings, message);
            // Verify outcome
            response.Data.PrivateDefaultConstructorCalled.Should().BeTrue();
        }
 public async Task ParsesNakedData_AsASuccessResponse(Model model, HttpResponseMessage message,
     NakedContentParser parser)
 {
     // Fixture setup
     message.Content = new StringContent(JsonConvert.SerializeObject(model));
     // Exercise system
     var response = await parser.ParseAsync<Model>(null, message);
     // Verify outcome
     response.Status.Should().Be(JSendStatus.Success);
     response.Data.ShouldBeEquivalentTo(model);
 }