public void ShouldReturnStandardNotFound() { _mockMediator.Setup(x => x.Send(It.IsAny <GetStandardQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new GetStandardResponse { StatusCode = GetStandardResponse.ResponseCodes.StandardNotFound }); var result = _sut.Standard("2", "test").Result as HttpNotFoundResult; result.Should().NotBeNull(); result.StatusCode.Should().Be(404); }
public void StandardDetailPageWithErrorParameter(string hasErrorParmeter, bool expected) { var mockStandardRepository = new Mock <IGetStandards>(); var standard = new Standard { Title = "Hello", }; mockStandardRepository.Setup(x => x.GetStandardById(It.IsAny <int>())).Returns(standard); var mockMappingServices = new Mock <IMappingService>(); mockMappingServices.Setup( x => x.Map <Standard, StandardViewModel>(It.IsAny <Standard>())) .Returns(new StandardViewModel()); var mockRequest = new Mock <HttpRequestBase>(); mockRequest.Setup(x => x.UrlReferrer).Returns(new Uri("http://www.abba.co.uk")); var context = new Mock <HttpContextBase>(); context.SetupGet(x => x.Request).Returns(mockRequest.Object); ApprenticeshipController controller = new ApprenticeshipController(null, mockStandardRepository.Object, null, null, mockMappingServices.Object, new Mock <IProfileAStep>().Object, new Mock <IListCollection <int> >().Object, null); controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller); controller.Url = new UrlHelper( new RequestContext(context.Object, new RouteData()), new RouteCollection()); var result = controller.Standard(1, string.Empty) as ViewResult; Assert.NotNull(result); }
public void StandardDetailPageStandardIsNull() { var mockStandardRepository = new Mock <IGetStandards>(); var mockRequest = new Mock <HttpRequestBase>(); mockRequest.Setup(x => x.UrlReferrer).Returns(new Uri("http://www.abba.co.uk")); var moqLogger = new Mock <ILog>(); ApprenticeshipController controller = new ApprenticeshipController(null, mockStandardRepository.Object, null, moqLogger.Object, null, new Mock <IProfileAStep>().Object, null, null); HttpNotFoundResult result = (HttpNotFoundResult)controller.Standard(1, "false"); Assert.NotNull(result); Assert.AreEqual(404, result.StatusCode); Assert.AreEqual("Cannot find standard: 1", result.StatusDescription); moqLogger.Verify(m => m.Warn("404 - Cannot find standard: 1")); }
public void ShouldSetViewModelShortListValueToTrueIfStandardIsInShortList( IEnumerable <int> shortListItems, int standardId, bool expectedResult) { // Arrange var mockStandardRepository = new Mock <IGetStandards>(); mockStandardRepository.Setup(x => x.GetStandardById(It.IsAny <int>())).Returns(new Standard()); var mockMappingServices = new Mock <IMappingService>(); mockMappingServices.Setup(x => x.Map <Standard, StandardViewModel>(It.IsAny <Standard>())) .Returns(new StandardViewModel()); var mockCookieRepository = new Mock <IListCollection <int> >(); var controller = new ApprenticeshipController( null, mockStandardRepository.Object, null, null, mockMappingServices.Object, new Mock <IProfileAStep>().Object, mockCookieRepository.Object, null); controller.SetRequestUrl("http://www.abba.co.uk"); mockCookieRepository.Setup(x => x.GetAllItems(Constants.StandardsShortListCookieName)) .Returns(new List <int>(shortListItems)); // Act var result = controller.Standard(standardId, string.Empty) as ViewResult; var viewModel = result?.Model as StandardViewModel; // Assert Assert.IsNotNull(viewModel); mockCookieRepository.Verify(x => x.GetAllItems(Constants.StandardsShortListCookieName)); Assert.AreEqual(expectedResult, viewModel.IsShortlisted); }