Exemple #1
0
        public async Task HandleAsync_Should_Return_CollectionOutputQuery_With_GetAccountsOutputQuery_When_Input_Is_Not_Null()
        {
            var getAccountsInputQuery = new GetAccountsInputQuery(1, 100, "email:asc", "*****@*****.**", true);
            var account = Account.Builder()
                          .SetId(Guid.NewGuid())
                          .SetEmail(getAccountsInputQuery.Email)
                          .SetConfirmed(true)
                          .SetPasswordHash("PasswordHash")
                          .SetSecurityStamp(Guid.NewGuid())
                          .SetCreated(DateTimeOffset.UtcNow)
                          .SetRoles(new List <Guid> {
                Guid.NewGuid()
            })
                          .Build();
            var accounts = new List <Account> {
                account
            };
            var getAccountsOutputQueries = accounts
                                           .Select(x => new GetAccountsOutputQuery(x.Id, x.Email, x.Confirmed, x.Created,
                                                                                   !string.IsNullOrWhiteSpace(x.PasswordHash), x.LastLogin)).ToList();
            var collectionOutputQuery = new CollectionOutputQuery <GetAccountsOutputQuery>(getAccountsOutputQueries.Count, getAccountsOutputQueries);

            _accountRepositoryMock.Setup(x => x.FindAsync(It.IsAny <int?>(), It.IsAny <int?>(), It.IsAny <string>(),
                                                          It.IsAny <string>(), It.IsAny <bool>())).ReturnsAsync(accounts);
            _accountRepositoryMock.Setup(x => x.CountAsync(It.IsAny <string>(), It.IsAny <bool>())).ReturnsAsync(accounts.Count);
            _mapperMock.Setup(x => x.Map <List <Account>, IEnumerable <GetAccountsOutputQuery> >(It.IsAny <List <Account> >()))
            .Returns(getAccountsOutputQueries);

            var result = await _queryHandler.HandleAsync(getAccountsInputQuery);

            result.Should().BeEquivalentTo(collectionOutputQuery);
        }
Exemple #2
0
        public async Task GetAccountsAsync_Should_Return_OkObjectResult_With_CollectionResponse_With_GetAccountsCollectionItemResponses()
        {
            var getAccountsRequest = new GetAccountsRequest
            {
                Email     = "*****@*****.**",
                Confirmed = true,
                Sort      = "email:asc",
                Page      = 1,
                PageSize  = 100
            };
            var getAccountsInputQuery = new GetAccountsInputQuery(getAccountsRequest.Page, getAccountsRequest.PageSize,
                                                                  getAccountsRequest.Sort, getAccountsRequest.Email, getAccountsRequest.Confirmed);
            var getAccountsOutputQueries = new List <GetAccountsOutputQuery>
            {
                new GetAccountsOutputQuery(Guid.NewGuid(), getAccountsRequest.Email, getAccountsRequest.Confirmed.Value,
                                           DateTimeOffset.UtcNow, true, null)
            };
            var collectionOutputQuery = new CollectionOutputQuery <GetAccountsOutputQuery>(getAccountsOutputQueries.Count, getAccountsOutputQueries);
            var getAccountsCollectionItemResponses = getAccountsOutputQueries.Select(x =>
                                                                                     new GetAccountsCollectionItemResponse(x.Id, x.Email, x.Confirmed, x.Created, x.PasswordAssigned, x.LastLogin));
            var collectionResponse = new CollectionResponse <GetAccountsCollectionItemResponse>(getAccountsOutputQueries.Count, getAccountsCollectionItemResponses);

            _mapperMock.Setup(x => x.Map <GetAccountsRequest, GetAccountsInputQuery>(It.IsAny <GetAccountsRequest>()))
            .Returns(getAccountsInputQuery);
            _getAccountsQueryHandlerMock
            .Setup(x => x.HandleAsync(It.IsAny <GetAccountsInputQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(collectionOutputQuery);
            _mapperMock.Setup(x =>
                              x.Map <CollectionOutputQuery <GetAccountsOutputQuery>,
                                     CollectionResponse <GetAccountsCollectionItemResponse> >(
                                  It.IsAny <CollectionOutputQuery <GetAccountsOutputQuery> >())).Returns(collectionResponse);

            var result = await _controller.GetAccountsAsync(getAccountsRequest);

            var okResult = result.As <OkObjectResult>();

            okResult.Value.Should().BeEquivalentTo(collectionResponse);
        }
Exemple #3
0
        public async Task <CollectionOutputQuery <GetAccountsOutputQuery> > HandleAsync(GetAccountsInputQuery inputQuery, CancellationToken cancellationToken = default)
        {
            List <Account> accounts;
            long           totalCount;

            if (inputQuery != null)
            {
                accounts = await _accountRepository.FindAsync(inputQuery.Page, inputQuery.PageSize, inputQuery.Sort,
                                                              inputQuery.Email, inputQuery.Confirmed);

                totalCount = await _accountRepository.CountAsync(inputQuery.Email, inputQuery.Confirmed);
            }
            else
            {
                accounts = await _accountRepository.GetAllAsync();

                totalCount = await _accountRepository.CountAsync();
            }

            var results = _mapper.Map <List <Account>, IEnumerable <GetAccountsOutputQuery> >(accounts);

            return(new CollectionOutputQuery <GetAccountsOutputQuery>(totalCount, results));
        }