public async Task CallCorrectServiceMethod_WhenInvoked() { //Arrange projectionsServiceMock = new Mock <IProjectionService>(); projectionsServiceMock .Setup(ps => ps.GetByTownId(It.IsAny <int>(), It.IsAny <string>(), null)) .ReturnsAsync(projections); cityServiceMock = new Mock <ICityService>(); cityServiceMock .Setup(city => city.GetCityName(It.IsAny <int>())) .Returns(Task.FromResult(cityName)); //Act var controller = new BuyTicketController(projectionsServiceMock.Object, cityServiceMock.Object, mockUserManager.Object, memoryCacheMock); controller.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; var result = await controller.Movie(cityId) as ViewResult; //Assert projectionsServiceMock.Verify(projection => projection.GetByTownId(It.IsAny <int>(), It.IsAny <string>(), null), Times.Once); cityServiceMock.Verify(city => city.GetCityName(It.IsAny <int>()), Times.Once); }
public async Task ReturnViewResult_WhenParametersAreCorrect() { //Arrange projectionsServiceMock = new Mock <IProjectionService>(); cityServiceMock = new Mock <ICityService>(); //Act var controller = new BuyTicketController(projectionsServiceMock.Object, cityServiceMock.Object, mockUserManager.Object, memoryCacheMock); controller.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; var result = await controller.Movie(cityId); //Assert Assert.IsInstanceOfType(result, typeof(ViewResult)); }