public void AddUserPost_UserNull_ActionResult() { // Arrange var mainUser = new User { Id = 1, FirstName = "Unit", LastName = "Test", UserName = "******", Mail = "*****@*****.**", Notifications = new List <Notification>() }; var users = new List <User>() { mainUser }.AsQueryable(); var mainGroup = new Group { Id = 1, }; var groups = new List <Group>() { mainGroup, }.AsQueryable(); var notifications = new List <Notification>().AsQueryable(); var mockContext = new Mock <Context>(); var mockGroups = MockHelper.MockDbSet(groups); mockContext.SetupGet(c => c.Groups).Returns(mockGroups.Object); var mockUsers = MockHelper.MockDbSet(users); mockContext.SetupGet(c => c.Users).Returns(mockUsers.Object); var mockNotifications = MockHelper.MockDbSet(notifications); mockContext.SetupGet(c => c.Notifications).Returns(mockNotifications.Object); var controller = new GroupController(mockContext.Object); var vmUserNullMail = new Models.Group.AddUserVM { Id = mainGroup.Id, UserName = "******", GroupId = mainGroup.Id }; var vmUserNullUsernameHalf = new Models.Group.AddUserVM { Id = mainGroup.Id, UserName = "******", GroupId = mainGroup.Id }; var vmUserNullUsernameNone = new Models.Group.AddUserVM { Id = mainGroup.Id, UserName = "******", GroupId = mainGroup.Id }; // Act //ViewResult resultValidMail = controller.AddUser(vmUserNullMail) as ViewResult; TODO: Moq Request ViewResult resultUsernameWithPossibleUsers = controller.AddUser(vmUserNullUsernameHalf) as ViewResult; RedirectToRouteResult resultUsernameNoPossibleUsers = controller.AddUser(vmUserNullUsernameNone) as RedirectToRouteResult; // Assert //Assert.IsNotNull(resultValidMail); TODO: Moq Request Assert.IsNotNull(resultUsernameWithPossibleUsers); Assert.IsNotNull(resultUsernameNoPossibleUsers); }
public void AddUserPost_UserNotNull_ActionResult() { // Arrange var mainUser = new User { Id = 1, FirstName = "Unit", LastName = "Test", UserName = "******", Mail = "*****@*****.**" }; var users = new List <User>() { mainUser }.AsQueryable(); var mainGroup = new Group { Id = 1, Archived = true }; var secondGroup = new Group { Id = 2, Archived = false }; var groups = new List <Group>() { mainGroup, secondGroup }.AsQueryable(); var newRegisters = new List <NewRegister>().AsQueryable(); var mockContext = new Mock <Context>(); var mockGroups = MockHelper.MockDbSet(groups); mockContext.SetupGet(c => c.Groups).Returns(mockGroups.Object); var mockUsers = MockHelper.MockDbSet(users); mockContext.SetupGet(c => c.Users).Returns(mockUsers.Object); var mockNewRegisters = MockHelper.MockDbSet(newRegisters); mockContext.SetupGet(c => c.NewRegisters).Returns(mockNewRegisters.Object); var controller = new GroupController(mockContext.Object); var vmGroupArchived = new Models.Group.AddUserVM { Id = mainGroup.Id, UserName = mainUser.UserName, GroupId = mainGroup.Id }; var vmGroupNotArchived = new Models.Group.AddUserVM { Id = secondGroup.Id, UserName = mainUser.UserName, GroupId = secondGroup.Id }; // Act RedirectToRouteResult resultGroupArchived = controller.AddUser(vmGroupArchived) as RedirectToRouteResult; RedirectToRouteResult resultGroupNotArchived = controller.AddUser(vmGroupNotArchived) as RedirectToRouteResult; //fails is RedirexctToRoute? // Assert Assert.IsNotNull(resultGroupArchived); Assert.IsNotNull(resultGroupNotArchived); }