Esempio n. 1
0
        public void Create_WhenCalled_ShouldReturnApiException()
        {
            // Arrange
            var sut = new ApiExceptionFactory();

            // Act
            var actual = sut.Create(HttpStatusCode.InternalServerError, string.Empty);

            // Assert
            actual.Should().BeOfType <ApiException>();
        }
Esempio n. 2
0
        public void Create_WhenCalledWithUnauthorized_ShouldReturnUnauthorizedException()
        {
            // Arrange
            var sut = new ApiExceptionFactory();

            // Act
            var actual = sut.Create(HttpStatusCode.Unauthorized, string.Empty);

            // Assert
            actual.Should().BeOfType <UnauthorizedException>();
        }
Esempio n. 3
0
        public void Create_WhenCalledWithForbidden_ShouldReturnForbiddenException()
        {
            // Arrange
            var sut = new ApiExceptionFactory();

            // Act
            var actual = sut.Create(HttpStatusCode.Forbidden, string.Empty);

            // Assert
            actual.Should().BeOfType <ForbiddenException>();
        }
Esempio n. 4
0
        public void Create_WhenCalledWithBadRequest_ShouldReturnBadRequestException()
        {
            // Arrange
            var sut = new ApiExceptionFactory();

            // Act
            var actual = sut.Create(HttpStatusCode.BadRequest, string.Empty);

            // Assert
            actual.Should().BeOfType <BadRequestException>();
        }
Esempio n. 5
0
        public void TestCreateApiExceptionTheory(int statusCode, string responseContent, bool isJsonResponse, Type expectedExceptionType)
        {
            //Arrange
            var clientConfiguration    = this.clientFixture.GetClientConfiguration("Client");
            var serializerService      = this.clientFixture.GetService <ISerializerService>();
            var mockHttpRequestMessage = GetHttpRequestMessageMock(); //same request for all
            var exceptionFactory       = new ApiExceptionFactory(clientConfiguration, serializerService);


            //Act
            var mockHttpResponseMessage = GetHttpResponseMessageMock(statusCode, responseContent, isJsonResponse);
            var exception =
                exceptionFactory.CreateApiException(mockHttpRequestMessage.Object, mockHttpResponseMessage.Object);

            //Assert Request
            Assert.NotNull(exception);
            Assert.NotNull(exception.Request);
            Assert.True(!string.IsNullOrEmpty(exception.CorrelationId));

            //Assert Response
            Assert.True(!string.IsNullOrEmpty(exception.HttpSummary));

            //Assert Exception
            Assert.IsType(expectedExceptionType, exception);

            //Conditional Asserts Based on Exception Types
            if (exception is ConcurrentModificationException)
            {
                var conCurrentException = (exception as ConcurrentModificationException);
                Assert.NotNull(conCurrentException.GetCurrentVersion());
                Assert.NotNull(conCurrentException.ErrorResponse);
                Assert.Single(conCurrentException.ErrorResponse.Errors);
                Assert.IsType <ConcurrentModificationError>(conCurrentException.ErrorResponse.Errors[0]);
            }

            if (exception is ApiServiceException)
            {
                var apiServiceException = (exception as ApiServiceException);
                //Assert.Equal(statusCode, apiServiceException.StatusCode);
            }
        }