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 void TestInitialize() { //Arrange memoryCacheMock = new MemoryCache(new MemoryCacheOptions()); mockUserManager = new Mock <UserManager <User> >( new Mock <IUserStore <User> >().Object, new Mock <IOptions <IdentityOptions> >().Object, new Mock <IPasswordHasher <User> >().Object, new IUserValidator <User> [0], new IPasswordValidator <User> [0], new Mock <ILookupNormalizer>().Object, new Mock <IdentityErrorDescriber>().Object, new Mock <IServiceProvider>().Object, new Mock <ILogger <UserManager <User> > >().Object); projectionsServiceMock = new Mock <IProjectionService>(); cityServiceMock = new Mock <ICityService>(); controller = new BuyTicketController(projectionsServiceMock.Object, cityServiceMock.Object, mockUserManager.Object, memoryCacheMock); controller.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; controller.TempData = new Mock <ITempDataDictionary>().Object; user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, userId), new Claim(ClaimTypes.Name, userName), })); }
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); }
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)); }
public BuyTicketForm(AviaSalesConnectionProvider provider, IAviaSalesView parent) { InitializeComponent(); Parent = parent; _controller = new BuyTicketController(provider, this); }