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); }
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(); }
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"); }