コード例 #1
0
        public async Task ListShouldReturnAllRecords()
        {
#if DEBUG
            // Arrange
            RepositoryHelper.CreateUser(Guid.NewGuid(), "login-1", "password", "FirstName", "LastName");
            RepositoryHelper.CreateUser(Guid.NewGuid(), "login-2", "password", "FirstName", "LastName");
            RepositoryHelper.CreateUser(Guid.NewGuid(), "login-3", "password", "FirstName", "LastName");

            // Act
            var result = await _finder.List(null, null, null);

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

            try
            {
                Expression <Func <User, bool> > filter = _odataProvider.GetFilterPredicate(query.Filter);
                int?skip        = query.Skip.ToNullableInt();
                int?limit       = query.Top.ToNullableInt();
                var userDomains = await _userFinder.List(filter, skip, limit);

                var userModels = _mapper.Map <IEnumerable <UserModel> >(userDomains);
                var count      = userModels.Count();
                var usersModel = new UsersModel {
                    Value = userModels, Count = count, NextLink = null
                };

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



            return(result);
        }