public ActionResult AddSkill(Models.Group.EditVM vm) { var group = Context.Groups.GetById(vm.Id); var userId = UserHelper.GetCurrentUser().Id; if (!group.Archived) { Skill NewSkill = new Skill { Name = vm.NewSkillName, Description = vm.NewSkillDescription, CreatedBy = Context.Users.GetById(userId), }; group.Skills.Add(NewSkill); Context.SaveChanges(); return(RedirectToAction("details", new { id = group.Id, state = "success" })); } else { return(RedirectToAction("details", new { id = group.Id, state = "archived" })); } }
public void AddSkillPost_Flow_ViewResult() { // 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 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 mockUserHelper = new Mock <IUserHelper>(); mockUserHelper.Setup(x => x.GetCurrentUser().Id).Returns(mainUser.Id); var controller = new GroupController(mockContext.Object, mockUserHelper.Object); var vmArchived = new Models.Group.EditVM { Id = mainGroup.Id }; var vmNotArchived = new Models.Group.EditVM { Id = secondGroup.Id, NewSkillName = "Unit Skill", NewSkillDescription = "Unit Skill Description" }; // Act ViewResult resultGroupArchived = controller.AddSkill(vmArchived) as ViewResult; ViewResult resultGroupNotArchived = controller.AddSkill(vmNotArchived) as ViewResult; // Assert Assert.IsNotNull(resultGroupArchived); Assert.IsNotNull(resultGroupNotArchived); }