public async Task GetByIdShouldSucceed() { // Arrange var id = TeamId.New; var name = new Name("name"); RepositoryHelper.ForTeam.CreateTeam(id, name); // Act var result = await _repository.GetAsync(id.GetGuid()); // Assert result.Should().NotBeNull(); result.Id.Should().Be(id); result.Name.Should().Be(name); }
public async Task <Result> Handle(GetTeamQuery query, CancellationToken cancellationToken) { Result result; try { List <MemberModel> memberModels = new List <MemberModel>(); var teamDomain = await _teamReadRepository.GetAsync(query.Id); foreach (var member in teamDomain.Members) { var operatorDomain = await _operatorReadRepository.GetAsync(member); memberModels.Add(_mapper.Map <MemberModel>(operatorDomain)); } var teamModel = _mapper.Map <TeamModel>(teamDomain); teamModel.Members = new List <MemberModel>(memberModels); result = Result.Ok(teamModel, teamDomain.Version); } catch (EntityNotFoundDbException) { result = Result.Fail(new List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.NotFound.Name, Message = HandlerFailures.TeamNotFound, Target = "id" } }); } catch { result = Result.Fail(CustomFailures.GetTeamFailure); } return(result); }
public async Task <Result> Handle(UpdateTeamCommand command, CancellationToken cancellationToken) { Result result; try { var team = await _teamReadRepository.GetAsync(command.Id); if (team.Version != command.Version) { throw new CommandVersionException(); } team.ChangeName(new Name(command.Name)); team.SetImage(command.Image); team.SetDescription((Description)command.Description); if (Guid.TryParse(command.Layout, out Guid layoutId) && layoutId != default(Guid)) { var layout = new Layout(layoutId); team.SetLayout(layout); } team.SetFilterContent(command.FilterContent); team.ChangeDriverWait(DriverWait.Parse(command.DriverWait)); team.ClearMembers(); foreach (var operatorId in command.Members) { var member = new Member(operatorId); team.AddMember(member); } team.SetVersion(_versionProvider.Generate()); await _teamWriteRepository.UpdateAsync(team); result = Result.Ok(team.Version); } catch (EntityNotFoundDbException) { result = Result.Fail(new List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.NotFound.Name, Message = HandlerFailures.TeamNotFound, Target = "id" } }); } catch (CommandVersionException) { result = Result.Fail(new List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.NotMet.Name, Message = HandlerFailures.NotMet, Target = "version" } }); } catch (UniqueKeyException) { result = Result.Fail(new List <Failure>() { new HandlerFault() { Code = HandlerFaultCode.Conflict.Name, Message = HandlerFailures.ConflictTeam, Target = "name" } }); } catch { result = Result.Fail(CustomFailures.UpdateTeamFailure); } return(result); }