public async Task Details_ReturnsCorrectViewModel() { var solutions = new[] { new Solution { Id = 1, Title = "First Solution", Content = "First Content", Author = new User() }, new Solution { Id = 2, Title = "Second Solution", Content = "Second Content", Author = new User() }, new Solution { Id = 3, Title = "Third Solution", Content = "Third Content", Author = new User() }, }; var context = TestsDbContext.GetDbContext(); context.Solutions.AddRange(solutions); context.SaveChanges(); var controller = new SolutionsController(context, TestsAutoMapper.GetMapper()); var expectedSolution = solutions[1]; var result = await controller.Details(expectedSolution.Id); var model = (result as ViewResult).ViewData.Model as SolutionDetailsViewModel; Assert.IsNotNull(model); Assert.AreEqual(model.Id, expectedSolution.Id); Assert.AreEqual(model.Title, expectedSolution.Title); Assert.AreEqual(model.Content, expectedSolution.Content); Assert.IsInstanceOfType(model, typeof(SolutionDetailsViewModel)); }
public async Task Ban_ReturnsCorrectViewModel() { var users = new[] { new User { Id = "123" }, new User { Id = "321" }, new User { Id = "456" } }; var context = TestsDbContext.GetDbContext(); context.Users.AddRange(users); context.SaveChanges(); var mockUserManager = TestsUserManager.GetUserManager(); mockUserManager.Setup(um => um.FindByIdAsync(It.IsAny <string>())) .ReturnsAsync(users[0]); var controller = new UsersController(context, TestsAutoMapper.GetMapper(), mockUserManager.Object); var result = await controller.Ban(users[0].Id); var model = (result as ViewResult).ViewData.Model as UserDetailsViewModel; Assert.AreEqual(model.Id, users[0].Id); Assert.IsInstanceOfType(model, typeof(UserDetailsViewModel)); }
public async Task Index_ShouldReturnAllUsers_ExceptCurrent() { var users = new[] { new User { Id = "123" }, new User { Id = "321" }, new User { Id = "456" } }; var context = TestsDbContext.GetDbContext(); context.Users.AddRange(users); context.SaveChanges(); var mockUserManager = TestsUserManager.GetUserManager(); mockUserManager.Setup(um => um.GetUserAsync(null)) .ReturnsAsync(users[0]); mockUserManager.Setup(um => um.GetRolesAsync(It.IsAny <User>())) .ReturnsAsync(new List <string> { "Whatever" }); var controller = new UsersController(context, TestsAutoMapper.GetMapper(), mockUserManager.Object); var result = await controller.Index() as ViewResult; var model = result.Model as IEnumerable <UserConciseViewModel>; var expectedCollection = users.Where(u => u.Id != users[0].Id) .Select(u => u.Id).ToArray(); var resultCollection = model.Select(u => u.Id).ToArray(); Assert.IsNotNull(result); CollectionAssert.AreEqual(expectedCollection, resultCollection); }
public async Task Ban_ReturnsCorrectView() { var mockUserManager = TestsUserManager.GetUserManager(); var user = new User { Id = "1" }; var context = TestsDbContext.GetDbContext(); context.Users.Add(user); mockUserManager.Setup(um => um.FindByIdAsync(It.IsAny <string>())) .ReturnsAsync(user); var controller = new UsersController(context, TestsAutoMapper.GetMapper(), TestsUserManager.GetUserManager().Object); var result = await controller.Ban(user.Id); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(ViewResult)); }
public void InitializeTests() { this.dbContext = TestsDbContext.GetDbContext(); }