public async Task ReturnsCorrectViewModel_WhenParametersAreCorrect() { //Arrange projectionsServiceMock = new Mock <IProjectionService>(); projectionsServiceMock .Setup(ps => ps.GetTopProjections(projectionsCount)) .ReturnsAsync(projections); cityServiceMock = new Mock <ICityService>(); cityServiceMock .Setup(city => city.GetCities()) .Returns(Task.FromResult(cities)); //Act var controller = new BuyTicketController(projectionsServiceMock.Object, cityServiceMock.Object, mockUserManager.Object, memoryCacheMock); var result = await controller.Index() as ViewResult; //Assert Assert.IsInstanceOfType(result.Model, typeof(CityListViewModel)); }
public async Task CallCorrectServiceMethod_WhenInvoked() { //Arrange projectionsServiceMock = new Mock <IProjectionService>(); projectionsServiceMock .Setup(ps => ps.GetTopProjections(projectionsCount)) .ReturnsAsync(projections); cityServiceMock = new Mock <ICityService>(); cityServiceMock .Setup(city => city.GetCities()) .Returns(Task.FromResult(cities)); //Act var controller = new BuyTicketController(projectionsServiceMock.Object, cityServiceMock.Object, mockUserManager.Object, memoryCacheMock); var result = await controller.Index() as ViewResult; //Assert projectionsServiceMock.Verify(projection => projection.GetTopProjections(It.IsAny <int>()), Times.Once); cityServiceMock.Verify(city => city.GetCities(), Times.Once); }