public void Details_When_No_Destination_Found() { // arrange var destinationServiceMock = new Mock <IDestinationService>(MockBehavior.Strict); var tagServiceMock = new Mock <ITagService>(MockBehavior.Strict); var tempDataMock = new Mock <ITempDataDictionary>(); var controller = new DestinationController(destinationServiceMock.Object, tagServiceMock.Object) { TempData = tempDataMock.Object }; int id = 1; destinationServiceMock.Setup(s => s.GetByIdAsync(id)).ReturnsAsync((DestinationDetailsServiceModel)null); // act var result = controller.Details(id); // assert Assert.IsAssignableFrom <RedirectToActionResult>(result.Result); var actionName = (result.Result as RedirectToActionResult)?.ActionName; Assert.True(actionName != null && actionName.Equals(nameof(DestinationController.All), StringComparison.CurrentCultureIgnoreCase)); destinationServiceMock.VerifyAll(); }
public void Details_When_Destination_Found() { // arrange var destinationServiceMock = new Mock <IDestinationService>(MockBehavior.Strict); var tagServiceMock = new Mock <ITagService>(MockBehavior.Strict); var controller = new DestinationController(destinationServiceMock.Object, tagServiceMock.Object); int id = 1; var serviceResult = new DestinationDetailsServiceModel(); destinationServiceMock.Setup(s => s.GetByIdAsync(id)).ReturnsAsync(serviceResult); // act var result = controller.Details(id); // assert Assert.IsAssignableFrom <ViewResult>(result.Result); var model = (result.Result as ViewResult)?.Model; Assert.True(model != null); Assert.IsAssignableFrom <DestinationDetailsServiceModel>(model); Assert.True((DestinationDetailsServiceModel)model == serviceResult); destinationServiceMock.VerifyAll(); }