コード例 #1
0
        public async Task ListShouldReturnAllRecords()
        {
            // Arrange
            RepositoryHelper.ForTeam.CreateTeam(TeamId.New, new Name("Team Name 1"));
            RepositoryHelper.ForTeam.CreateTeam(TeamId.New, new Name("Team Name 2"));
            RepositoryHelper.ForTeam.CreateTeam(TeamId.New, new Name("Team Name 3"));

            // Act
            var result = await _repository.ListAsync(null, null, null);

            // Assert
            result.Should().HaveCount(3);
        }
コード例 #2
0
        public async Task <Result> Handle(ListTeamQuery request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                var filter      = request.Filter;
                int?skip        = request.Skip.ToNullableInt();
                int?top         = request.Top.ToNullableInt();
                var teamDomains = await _teamReadRepository.ListAsync(filter, skip, top);

                var teamModels = new List <TeamModel>();

                foreach (var teamDomain in teamDomains)
                {
                    var members = new List <MemberModel>();
                    foreach (var member in teamDomain.Members)
                    {
                        var operatorDomain = await _operatorReadRepository.GetAsync(member);

                        members.Add(_mapper.Map <MemberModel>(operatorDomain));
                    }
                    var teamModel = _mapper.Map <TeamModel>(teamDomain);
                    teamModel.Members = new List <MemberModel>(members);
                    teamModels.Add(teamModel);
                }

                var count      = teamModels.Count;
                var teamsModel = new TeamsModel {
                    Value = teamModels, Count = count, NextLink = null
                };

                result = Result.Ok(teamsModel);
            }
            catch (FilterODataException)
            {
                result = Result.Fail(new List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.InvalidQueryFilter.Name,
                        Message = HandlerFailures.InvalidQueryFilter,
                        Target  = "$filter"
                    }
                });
            }
            catch
            {
                result = Result.Fail(CustomFailures.ListTeamFailure);
            }

            return(result);
        }
コード例 #3
0
        public async Task <Result> Handle(DeleteOperatorCommand command, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                IEnumerable <Team> teams = await _teamReadRepository.ListAsync(string.Format("members/id eq '{0}'", command.Id), null, null);

                foreach (var item in teams)
                {
                    item.RemoveMember(command.Id);
                    await _teamWriteRepository.UpdateAsync(item);
                }

                await _operatorWriteRepository.DeleteAsync(command.Id, 0);

                return(Result.Ok());
            }
            catch (EntityNotFoundDbException)
            {
                result = Result.Fail(new List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotFound.Name,
                        Message = HandlerFailures.OperatorNotFound,
                        Target  = "id"
                    }
                });
            }
            catch (EntityVersionDbException)
            {
                result = Result.Fail(new List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.NotMet.Name,
                        Message = HandlerFailures.NotMet,
                        Target  = "version"
                    }
                });
            }
            catch
            {
                result = Result.Fail(CustomFailures.DeleteOperatorFailure);
            }

            return(result);
        }