Ejemplo n.º 1
0
        public void DoesNotHaveAnError()
        {
            string             json      = ReadDataFile("ConsumerInfo.json");
            TestingApiResponse jsApiResp = new TestingApiResponse(json);

            Assert.False(jsApiResp.HasError);
            Assert.Null(jsApiResp.Error);
        }
Ejemplo n.º 2
0
        public void MiscErrorResponsesAreUnderstood()
        {
            string text = ReadDataFile("ErrorResponses.json.txt");

            String[] jsons = text.Split('~');

            TestingApiResponse jsApiResp = new TestingApiResponse(jsons[0]);

            Assert.True(jsApiResp.HasError);
            Assert.Equal("code_and_desc_response", jsApiResp.Type);
            Assert.Equal(500, jsApiResp.ErrorCode);
            Assert.Equal("the description", jsApiResp.ErrorDescription);
            Assert.Equal("the description (500)", jsApiResp.Error.ToString());
            NATSJetStreamException jsApiEx = new NATSJetStreamException(jsApiResp);

            Assert.Equal(500, jsApiEx.ErrorCode);
            Assert.Equal("the description (500)", jsApiEx.ErrorDescription);

            jsApiResp = new TestingApiResponse(jsons[1]);
            Assert.True(jsApiResp.HasError);
            Assert.Equal("zero_and_desc_response", jsApiResp.Type);
            Assert.Equal(0, jsApiResp.ErrorCode);
            Assert.Equal("the description", jsApiResp.ErrorDescription);
            Assert.Equal("the description (0)", jsApiResp.Error.ToString());
            jsApiEx = new NATSJetStreamException(jsApiResp);
            Assert.Equal(0, jsApiEx.ErrorCode);
            Assert.Equal("the description (0)", jsApiEx.ErrorDescription);

            jsApiResp = new TestingApiResponse(jsons[2]);
            Assert.True(jsApiResp.HasError);
            Assert.Equal("non_zero_code_only_response", jsApiResp.Type);
            Assert.Equal(500, jsApiResp.ErrorCode);
            Assert.Equal("Unknown JetStream Error (500)", jsApiResp.Error.ToString());
            jsApiEx = new NATSJetStreamException(jsApiResp);
            Assert.Equal(500, jsApiEx.ErrorCode);

            jsApiResp = new TestingApiResponse(jsons[3]);
            Assert.True(jsApiResp.HasError);
            Assert.Equal("no_code_response", jsApiResp.Type);
            Assert.Equal(Error.NOT_SET, jsApiResp.ErrorCode);
            Assert.Equal("no code", jsApiResp.ErrorDescription);
            Assert.Equal("no code", jsApiResp.Error.ToString());
            jsApiEx = new NATSJetStreamException(jsApiResp);
            Assert.Equal(-1, jsApiEx.ErrorCode);
            Assert.Equal("no code", jsApiEx.ErrorDescription);

            jsApiResp = new TestingApiResponse(jsons[4]);
            Assert.True(jsApiResp.HasError);
            Assert.Equal("empty_response", jsApiResp.Type);
            Assert.Equal(Error.NOT_SET, jsApiResp.ErrorCode);
            Assert.Empty(jsApiResp.ErrorDescription);
            jsApiEx = new NATSJetStreamException(jsApiResp);
            Assert.Equal(-1, jsApiEx.ErrorCode);
            Assert.Equal(-1, jsApiEx.ApiErrorCode);
            Assert.Empty(jsApiEx.ErrorDescription);

            jsApiResp = new TestingApiResponse(jsons[5]);
            Assert.True(jsApiResp.HasError);
            Assert.Equal(ApiResponse.NoType, jsApiResp.Type);
            Assert.Equal(ApiResponse.NoType, jsApiResp.Type); // coverage!
        }