Exemplo n.º 1
0
        public AddressCommandsApiController Build()
        {
            var controller = new AddressCommandsApiController(_addressBookService, _currentUserService, _authorizationService);

            controller.SetupForUnitTest();

            return(controller);
        }
Exemplo n.º 2
0
        public void DeleteAddressBookEntry_ShouldReturn400BadRequest_WhenEntryNotFound()
        {
            // Arrange
            _addressCommandsApiController = _addressCommandsApiControllerBuilder.Build();

            // Act
            var response = _addressCommandsApiController.DeleteAddressBookEntry(null);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
Exemplo n.º 3
0
        public void DeleteAddressBookEntry_ShouldReturn403Forbidden_WhenUserIsNotFound()
        {
            // Arrange
            _mockCurrentUserService.Setup(cus => cus.GetCurrentUserId()).Returns((string)null);
            _addressCommandsApiController = _addressCommandsApiControllerBuilder.WithCurrentUserService(_mockCurrentUserService.Object).Build();

            // Act
            var response = _addressCommandsApiController.DeleteAddressBookEntry("AddressBookEntries/123");

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
        }
Exemplo n.º 4
0
        public void DeleteAddressBookEntry_ShouldReturn403Forbidden_WhenUserIsNotAuthorized()
        {
            // Arrange
            var userId = "Users/007";

            _mockCurrentUserService.Setup(cus => cus.GetCurrentUserId()).Returns(userId);
            _mockAuthorizationService.Setup(a => a.IsAuthorized(userId, ActivityEnum.View)).Returns(false);
            _addressCommandsApiController = _addressCommandsApiControllerBuilder.WithCurrentUserService(_mockCurrentUserService.Object).Build();

            // Act
            var response = _addressCommandsApiController.DeleteAddressBookEntry("AddressBookEntries/123");

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
        }
Exemplo n.º 5
0
        public void DeleteAddressBookEntry_ShouldReturn500Error_WhenUnhandledExceptionOccurs()
        {
            // Arrange
            const string addressBookEntryId = "AddressBookEntries/123";

            _mockAddressBookService.Setup(ab => ab.DeleteAddressBookEntry(addressBookEntryId)).Throws <NotImplementedException>();
            _addressCommandsApiController = _addressCommandsApiControllerBuilder
                                            .WithAddressBookService(_mockAddressBookService.Object)
                                            .WithUser("Users/007")
                                            .WithAllAuthority()
                                            .Build();

            // Act
            var response = _addressCommandsApiController.DeleteAddressBookEntry(addressBookEntryId);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.InternalServerError);
        }
Exemplo n.º 6
0
        public void DeleteAddressBookEntry_ShouldReturn500_WhenDeleteResultIsError()
        {
            // Arrange
            const string addressBookEntryId           = "AddressBookEntries/123";
            var          deleteAddressBookEntryResult = new DeleteAddressBookEntryResult {
                ResultType = AddressBookCommandResultType.Error
            };

            _mockAddressBookService.Setup(ab => ab.DeleteAddressBookEntry(addressBookEntryId)).Returns(deleteAddressBookEntryResult);
            _addressCommandsApiController = _addressCommandsApiControllerBuilder
                                            .WithAddressBookService(_mockAddressBookService.Object)
                                            .WithUser("Users/007")
                                            .WithAllAuthority()
                                            .Build();

            // Act
            var response = _addressCommandsApiController.DeleteAddressBookEntry(addressBookEntryId);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.InternalServerError);
        }