public void StopCrisis_CrisisOngoing_ReturnOk() { var crisisName = CrisisName.Create("crisis 1"); var crisis = new Crisis(crisisName.Value, "crisis description"); var result = crisis.StopCrisis(); result.IsSuccess.Should().BeTrue(); crisis.Status.Should().Be(CrisisStatus.Ended); }
public void StopCrisis_AlreadyEnded_ReturnFail() { var crisisName = CrisisName.Create("crisis 1"); var crisis = new Crisis(crisisName.Value, "crisis description"); crisis.StopCrisis(); var result = crisis.StopCrisis(); result.IsFailed.Should().BeTrue(); result.WithError("Crisis is already stopped"); }
public void AddTeam_TeamAlreadyExist_ReturnFail() { var team1 = new Team { Id = 1, Name = "Team 1", Description = "desc 1" }; var crisisName = CrisisName.Create("crisis 1"); var crisis = new Crisis(crisisName.Value, "crisis description"); crisis.AddTeam(team1); var result = crisis.AddTeam(team1); result.IsSuccess.Should().BeFalse(); }
public void AddTeam_TeamAdded_ReturnOk() { var team1 = new Team { Id = 1, Name = "Team 1", Description = "desc 1" }; var team2 = new Team { Id = 2, Name = "Team 2", Description = "desc 2" }; var crisisName = CrisisName.Create("crisis 1"); var crisis = new Crisis(crisisName.Value, "crisis description"); crisis.AddTeam(team1); var result = crisis.AddTeam(team2); result.IsSuccess.Should().BeTrue(); }
public async Task <Result <BaseCrisisViewModel> > Handle(CreateCrisisRequest request, CancellationToken cancellationToken) { if (request.TeamIds.Count == 0) { return(Result.Fail("Request team empty")); } var teams = await _dbContext .Teams .Where(t => request.TeamIds.Contains(t.Id)) .ToListAsync(cancellationToken); if (teams.Count != request.TeamIds.Count) { return(Result.Fail("Not all teams found")); } var crisisName = CrisisName.Create(request.Name); if (crisisName.IsFailed) { // TODO return result error } var crisis = new Crisis(crisisName.Value, request.Description); foreach (var team in teams) { var result = crisis.AddTeam(team); } _dbContext.Crisises.Add(crisis); await _dbContext.SaveChangesAsync(cancellationToken); var viewModel = BaseCrisisViewModel.Map(crisis); return(Result.Ok(viewModel)); }