public async Task ShouldCreateTeamCorrectly() { //Arrange Team createdTeam = null; var teamsRepository = new Mock <ITeamsRepository>(); var author = new User("test", "*****@*****.**", "test", "test"); teamsRepository.Setup(x => x.AddAsync(It.IsAny <Team>())).Callback <Team>(x => createdTeam = x).Returns(Task.CompletedTask); var createTeamHandler = new CreateNewTeamHandler(teamsRepository.Object); var command = new CreateNewTeamCommand(author, "test", "test"); //Act await createTeamHandler.HandleAsync(command); //Assert Assert.That(createdTeam.Description, Is.EqualTo(command.Description)); }
public ActionResult Create(CreateTeamViewModel viewModel) { if (ModelState.IsValid) { try { IQuery <ApplicationUser> currentUser = new GetUserByIdQuery(HttpContext.User.Identity.GetUserId()); var command = new CreateNewTeamCommand(viewModel.TeamName, dispatcher.ExecuteQuery(currentUser)); dispatcher.ExecuteCommand(command); return(RedirectToAction("Details", new { id = command.TeamId })); } catch (ArgumentException argumentException) { ViewBag.ErrorMessage = argumentException.Message; return(View()); } catch { return(View()); } } return(View()); }