public void HttpResponseMessageMustNotBeNull(JSendError error)
 {
     // Exercise system and verify outcome
     Assert.Throws <ArgumentNullException>(() => new JSuccessWithDataResponse <int>(0, null));
     Assert.Throws <ArgumentNullException>(() => new JSuccessResponse <int>(null));
     Assert.Throws <ArgumentNullException>(() => new JErrorResponse <int>(error, null));
 }
Exemple #2
0
        public void EqualityOperator_ReturnsFalse_WhenRightOperandsIsNull(JSendError error)
        {
            // Exercise system
            var areEqual = error == null;

            // Verify outcome
            areEqual.Should().BeFalse();
        }
Exemple #3
0
        public void EqualityOperator_ReturnsFalse_WhenFieldsDoNotMatch(JSendError first, JSendError second)
        {
            // Exercise system
            var areEqual = first == second;

            // Verify outcome
            areEqual.Should().BeFalse();
        }
Exemple #4
0
        public void InequalityOperator_ReturnsTrue_WhenFieldsDoNotMatch(JSendError first, JSendError second)
        {
            // Exercise system
            var areNotEqual = first != second;

            // Verify outcome
            areNotEqual.Should().BeTrue();
        }
Exemple #5
0
        public void InequalityOperator_ReturnsTrue_WhenRightOperandsIsNull(JSendError error)
        {
            // Exercise system
            var areNotEqual = error != null;

            // Verify outcome
            areNotEqual.Should().BeTrue();
        }
Exemple #6
0
 /// <summary>Initializes a new instance of <see cref="JErrorResponse{T}"/>.</summary>
 /// <param name="error">The error details.</param>
 /// <param name="httpResponse">The HTTP response message.</param>
 public JErrorResponse(JSendError error, HttpResponseMessage httpResponse) : base(httpResponse)
 {
     if (error == null)
     {
         throw new ArgumentNullException(nameof(error));
     }
     Contract.Assert(error.Status != JSendStatus.Success);
     Error = error;
 }
Exemple #7
0
        public void Equals_IsSymmetric(JSendError first, JSendError second)
        {
            // Exercise system
            var firstEqualsSecond = first.Equals(second);
            var secondEqualsFirst = second.Equals(first);

            // Verify outcome
            firstEqualsSecond.Should().Be(secondEqualsFirst);
        }
        public static async Task <JSendResponse <T> > ParseFailMessageAsync <T>(JToken json, HttpResponseMessage responseMessage)
        {
            json.Validate(await GetFailSchemaAsync().IgnoreContext());

            var dataToken = json["data"];
            var error     = new JSendError(JSendStatus.Fail, null, null, dataToken);

            return(new JErrorResponse <T>(error, responseMessage));
        }
Exemple #9
0
        public void InequalityOperator_IsSymmetric(JSendError first, JSendError second)
        {
            // Exercise system
            var firstEqualsSecond = first != second;
            var secondEqualsFirst = second != first;

            // Verify outcome
            firstEqualsSecond.Should().Be(secondEqualsFirst);
        }
Exemple #10
0
        public void InequalityOperator_IsReflexive(JSendError error)
        {
#pragma warning disable 1718
            // Exercise system
            var areNotEqual = error != error;
            // Verify outcome
            areNotEqual.Should().BeFalse();
#pragma warning restore 1718
        }
Exemple #11
0
        public void InequalityOperator_ReturnsFalse_WhenBothErrorsAreNull()
        {
#pragma warning disable 1718
            // Fixture setup
            JSendError error = null;
            // Exercise system
            var areNotEqual = error != error;
            // Verify outcome
            areNotEqual.Should().BeFalse();
#pragma warning restore 1718
        }
        public static async Task <JSendResponse <T> > ParseErrorMessageAsync <T>(JToken json, HttpResponseMessage responseMessage)
        {
            json.Validate(await GetErrorSchemaAsync().IgnoreContext());

            var message   = json.Value <string>("message");
            var code      = json.Value <int?>("code");
            var dataToken = json["data"];

            // check if the "data" key exists, but has a null value
            if (dataToken != null && dataToken.Type == JTokenType.Null)
            {
                dataToken = null;
            }

            var error = new JSendError(JSendStatus.Error, message, code, dataToken);

            return(new JErrorResponse <T>(error, responseMessage));
        }
Exemple #13
0
        public async Task ParsesErrorResponse_WithoutCodeKey(string message, DateTime data,
                                                             HttpResponseMessage responseMessage, DefaultJSendParser 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 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 void ErrorIsNotEqualToNull(JSendError error)
 {
     // Exercise system and verify outcome
     error.Equals(null).Should().BeFalse();
 }
 public void ErrorIsNotEqualToInstanceOfAnotherType(JSendError error, string other)
 {
     // Exercise system and verify outcome
     error.Equals(other).Should().BeFalse();
 }
 public void Equals_IsReflexive(JSendError error)
 {
     // Exercise system and verify outcome
     error.Equals(error).Should().BeTrue();
 }
Exemple #18
0
 public void Equals_IsReflexive(JSendError error)
 {
     // Exercise system and verify outcome
     error.Equals(error).Should().BeTrue();
 }
Exemple #19
0
 public void ErrorIsNotEqualToInstanceOfAnotherType(JSendError error, string other)
 {
     // Exercise system and verify outcome
     error.Equals(other).Should().BeFalse();
 }
 public void InequalityOperator_ReturnsTrue_WhenRightOperandsIsNull(JSendError error)
 {
     // Exercise system
     var areNotEqual = error != null;
     // Verify outcome
     areNotEqual.Should().BeTrue();
 }
        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 void Equals_IsSymmetric(JSendError first, JSendError second)
 {
     // Exercise system
     var firstEqualsSecond = first.Equals(second);
     var secondEqualsFirst = second.Equals(first);
     // Verify outcome
     firstEqualsSecond.Should().Be(secondEqualsFirst);
 }
        public void EnsureSuccessStatus_DisposesOfHttpResponseMessage_WhenStatusIsNotSuccess(JSendError error,
                                                                                             HttpResponseMessageSpy spy)
        {
            // Fixture setup
            var response = new JErrorResponse <int>(error, spy);

            // Exercise system
            try
            {
                response.EnsureSuccessStatus();
            }
            catch
            {
            }
            // Verify outcome
            spy.Disposed.Should().BeTrue();
        }
 public void EqualityOperator_ReturnsFalse_WhenFieldsDoNotMatch(JSendError first, JSendError second)
 {
     // Exercise system
     var areEqual = first == second;
     // Verify outcome
     areEqual.Should().BeFalse();
 }
 public void EqualityOperator_ReturnsFalse_WhenRightOperandsIsNull(JSendError error)
 {
     // Exercise system
     var areEqual = error == null;
     // Verify outcome
     areEqual.Should().BeFalse();
 }
        public void InequalityOperator_IsReflexive(JSendError error)
        {
#pragma warning disable 1718
            // Exercise system
            var areNotEqual = error != error;
            // Verify outcome
            areNotEqual.Should().BeFalse();
#pragma warning restore 1718
        }
 public void TwoErrors_AreNotEqual_WhenTheirFieldsDoNotMatch(JSendError first, JSendError second)
 {
     // Exercise system and verify outcome
     first.Equals(second).Should().BeFalse();
 }
Exemple #28
0
 public void TwoErrors_AreNotEqual_WhenTheirFieldsDoNotMatch(JSendError first, JSendError second)
 {
     // Exercise system and verify outcome
     first.Equals(second).Should().BeFalse();
 }
        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);
        }
Exemple #30
0
 public void ErrorIsNotEqualToNull(JSendError error)
 {
     // Exercise system and verify outcome
     error.Equals(null).Should().BeFalse();
 }
 public void InequalityOperator_IsSymmetric(JSendError first, JSendError second)
 {
     // Exercise system
     var firstEqualsSecond = first != second;
     var secondEqualsFirst = second != first;
     // Verify outcome
     firstEqualsSecond.Should().Be(secondEqualsFirst);
 }
 public void InequalityOperator_ReturnsTrue_WhenFieldsDoNotMatch(JSendError first, JSendError second)
 {
     // Exercise system
     var areNotEqual = first != second;
     // Verify outcome
     areNotEqual.Should().BeTrue();
 }
Exemple #33
0
 public void EqualErrorsHaveTheSameHashCode(JSendError first, JSendError second)
 {
     // Exercise system and verify outcome
     first.GetHashCode().Should().Be(second.GetHashCode());
 }
 public void EqualErrorsHaveTheSameHashCode(JSendError first, JSendError second)
 {
     // Exercise system and verify outcome
     first.GetHashCode().Should().Be(second.GetHashCode());
 }