예제 #1
0
        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);
        }
예제 #2
0
        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");
        }
예제 #3
0
        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();
        }
예제 #4
0
        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();
        }
예제 #5
0
        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));
        }