public ActionResult GenerateTeams(GenerateTeamsVM vm) { if (vm.TeamSize < 1) { vm.Message = "Please make sure you have filled in a max team size"; return(View("GenerateTeamsForm", vm)); } var currentEvent = Context.Events.GetById(vm.EventId); switch (vm.AlgorithmType) { case AlgorithmType.AverageTeams: _generateAverageTeams(currentEvent, vm.TeamSize); break; case AlgorithmType.BestTeam: _generateBestTeams(currentEvent, vm.TeamSize); break; default: return(HttpNotFound()); } foreach (var user in currentEvent.Group.Users) { user.Notifications.Add(new Notification { Title = "Added to eventTeam for event: " + currentEvent.EventName, Content = $"An event has started and you've been added to a team. " + $"You can now rate your team members through the following link: " + Url.Action("RateUser", "Group", new { id = currentEvent.Group.Id }, this.Request.Url.Scheme), Date = DateTime.Now, IsRead = false }); } return(RedirectToAction("Details", new { id = vm.EventId })); }
public void GenerateTeamsPost_Flow_ActionResult() { // Arrange var mainUser = new User { Id = 1, FirstName = "Unit", LastName = "Test", UserName = "******", Mail = "*****@*****.**", Notifications = new List <Notification>(), }; var secondUser = new User { Id = 2, FirstName = "Unit2", LastName = "Test2", UserName = "******", Mail = "*****@*****.**", Notifications = new List <Notification>() }; var ratings = new List <Rating>() { new Rating { Mark = 6.0, Id = 1 } }.AsQueryable(); var mainSkill = new Skill { Id = 1, Name = "Unit Skill" }; var userSkills1 = new List <UserSkill>() { new UserSkill { Id = 1, Ratings = ratings.ToList(), User = mainUser, Skill = mainSkill }, }.AsQueryable(); var userSkills2 = new List <UserSkill>() { new UserSkill { Id = 2, Ratings = ratings.ToList(), User = secondUser, Skill = mainSkill } }.AsQueryable(); mainUser.UserSkills = userSkills1.ToList(); secondUser.UserSkills = userSkills2.ToList(); var users = new List <User>() { mainUser }.AsQueryable(); var mainTeam = new EventTeam { Id = 1, Users = users.ToList() }; var teams = new List <EventTeam>() { mainTeam }.AsQueryable(); var mainGroup = new Group { Id = 1, Category = "Unit Category", CreatedOn = DateTime.Now, GroupName = "Unit Group", GroupCreator = mainUser.Id, Users = users.ToList() }; var groups = new List <Group>() { mainGroup }.AsQueryable(); var mainEvent = new Event { Id = 1, CreatedOn = DateTime.Now, EventCreator = mainUser, EventName = "Unit Event", Group = mainGroup, Teams = teams.ToList() }; var events = new List <Event>() { mainEvent }.AsQueryable(); var notifications = new List <Notification>().AsQueryable(); var mockContext = new Mock <Context>(); var mockTeams = MockHelper.MockDbSet(teams); mockContext.SetupGet(c => c.EventTeams).Returns(mockTeams.Object); var mockEvents = MockHelper.MockDbSet(events); mockContext.SetupGet(c => c.Events).Returns(mockEvents.Object); 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 mockUserSkills1 = MockHelper.MockDbSet(userSkills1); mockContext.SetupGet(c => c.UserSkills).Returns(mockUserSkills1.Object); var mockUserSkills2 = MockHelper.MockDbSet(userSkills2); mockContext.SetupGet(c => c.UserSkills).Returns(mockUserSkills2.Object); var mockRatings = MockHelper.MockDbSet(ratings); mockContext.SetupGet(c => c.Ratings).Returns(mockRatings.Object); var controller = new EventController(mockContext.Object); var vmTeamSizeBelowOne = new GenerateTeamsVM { TeamSize = 0, EventId = mainEvent.Id }; var vmAlgorithmTypeAverageTeams = new GenerateTeamsVM { TeamSize = 4, EventId = mainEvent.Id, AlgorithmType = Helpers.Enums.AlgorithmType.AverageTeams }; var vmAlgorithmTypeBestTeam = new GenerateTeamsVM { TeamSize = 4, EventId = mainEvent.Id, AlgorithmType = Helpers.Enums.AlgorithmType.BestTeam }; // Act ViewResult resultTeamSizeBelowOne = controller.GenerateTeams(vmTeamSizeBelowOne) as ViewResult; //RedirectToRouteResult resultAlgorithmTypeAverageTeams = controller.GenerateTeams(vmAlgorithmTypeAverageTeams) as RedirectToRouteResult; //RedirectToRouteResult resultAlgorithmTypeBestTeam = controller.GenerateTeams(vmAlgorithmTypeBestTeam) as RedirectToRouteResult; // Assert Assert.IsNotNull(resultTeamSizeBelowOne); //Assert.IsNotNull(resultAlgorithmTypeAverageTeams); TODO: Remove or fix unit test //Assert.IsNotNull(resultAlgorithmTypeBestTeam); TODO: Remove or fix unit test }