예제 #1
0
        public void WhenGetAccountFails_ShouldRedirectToBadRequest()
        {
            // Arrange
            var sut = new LevyEmployerTypeOnly();

            _accountApiClientMock
            .Setup(mock => mock.GetAccount(It.IsAny <string>()))
            .Throws(new Exception());

            // Act
            sut.OnActionExecuting(_filterContext);
            var result = _filterContext.Result as ViewResult;

            // Assert
            result.Should().NotBeNull();
            result.ViewName.Should().Be(ControllerConstants.BadRequestViewName);
        }
예제 #2
0
        public void WhenLevyEmployer_ShouldAllowAccess()
        {
            // Arrange
            var sut = new LevyEmployerTypeOnly();

            _accountApiClientMock
            .Setup(mock => mock.GetAccount(It.IsAny <string>()))
            .ReturnsAsync(new AccountDetailViewModel {
                ApprenticeshipEmployerType = "Levy"
            });

            // Act
            sut.OnActionExecuting(_filterContext);
            var result = _filterContext.Result as ViewResult;

            // Assert
            _filterContext.Result.Should().BeNull();
        }
예제 #3
0
        public void WhenNonLevyEmployer_ShouldDenyAccess()
        {
            // Arrange
            var sut = new LevyEmployerTypeOnly();

            _accountApiClientMock
            .Setup(mock => mock.GetAccount(It.IsAny <string>()))
            .ReturnsAsync(new AccountDetailViewModel {
                ApprenticeshipEmployerType = "NonLevy"
            });

            // Act
            sut.OnActionExecuting(_filterContext);
            var result = _filterContext.Result as RedirectToRouteResult;

            // Assert
            result.Should().NotBeNull();
            result.RouteValues["controller"].Should().Be("AccessDenied");
        }