public async Task GetAllAsync_ReturnsReadRequestAchievementModels()
        {
            //Arrange
            int entitiesCount     = 5;
            var cancellationToken = new CancellationToken();

            var achievements            = AchievementDumbData.GetRandomEntities(entitiesCount);
            var users                   = UserDumbData.GetRandomEntities(entitiesCount);
            var listRequestAchievements = RequestAchievementDumbData.GetEntities(achievements, users);
            var pagingInfo              = ReturnPagingInfoDumbData.GetForModel(new PagingInfo(), listRequestAchievements);

            var expectedValue = RequestAchievementDumbData.GetReadRequestAchievementModels(listRequestAchievements, achievements, users);


            _requestAchievementRepository.Setup(x => x.GetAllDataAsync(It.IsAny <PagingInfo>(), cancellationToken)).Returns(Task.FromResult(pagingInfo));
            _userRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns((Guid x) => Task.FromResult(users.FirstOrDefault(y => y.Id == x)));
            _achievementRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns((Guid x) => Task.FromResult(achievements.FirstOrDefault(y => y.Id == x)));

            // Act
            var response = await _requestAchievementService.GetAllAsync(cancellationToken);

            // Assert
            _requestAchievementRepository.Verify(x => x.GetAllDataAsync(It.IsAny <PagingInfo>(), cancellationToken), Times.Once);
            _userRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Exactly(listRequestAchievements.Count));
            _achievementRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Exactly(listRequestAchievements.Count));

            response.Should().BeEquivalentTo(expectedValue);
        }
Пример #2
0
        public async Task GetAllUsersWithFullInfoAsync_ValidPagingInfos_ReturnsReturnPagingInfo_ReadFullUserModel(PagingInfo pagingInfo)
        {
            //Arrange
            var listUsers         = UserDumbData.GetRandomEntities(5);
            var cancellationToken = new CancellationToken();
            var expectedUsers     = ReturnPagingInfoDumbData.GetForModel(pagingInfo, listUsers);
            var expectedValue     = ReturnPagingInfoDumbData.GetWithModels <ReadFullUserModel, User>(expectedUsers, _mapper);

            _userRepository.Setup(x => x.GetAllDataAsync(It.IsAny <PagingInfo>(), cancellationToken)).Returns(Task.FromResult(expectedUsers));

            // Act
            var response = await _userService.GetAllUsersWithFullInfoAsync(pagingInfo, cancellationToken);

            // Assert
            _userRepository.Verify(x => x.GetAllDataAsync(It.IsAny <PagingInfo>(), cancellationToken), Times.Once);
            response.Should().BeEquivalentTo(expectedValue);
        }
        public async Task GetAllAsync_ValidOrderId()
        {
            //Arrange
            var users             = UserDumbData.GetRandomEntities(5);
            var orders            = OrderDumbData.GetRandomEntities(users.Count);
            var requestOrders     = RequestOrderDumbData.GetEntities(users, orders);
            var cancellationToken = new CancellationToken();

            var expectedRequestOrders = ReturnPagingInfoDumbData.GetForModel(new PagingInfo(), requestOrders);
            var expectedValue         = ReturnPagingInfoDumbData.GetWithModels <ReadRequestOrderModel, RequestOrder>(expectedRequestOrders, _mapper);

            _requestOrderRepository.Setup(x => x.GetAllDataAsync(It.IsAny <PagingInfo>(), cancellationToken)).Returns(Task.FromResult(expectedRequestOrders));
            _userRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns((Guid x) => Task.FromResult(users.FirstOrDefault(y => y.Id == x)));
            _orderRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns((Guid x) => Task.FromResult(orders.FirstOrDefault(y => y.Id == x)));


            // Act
            var response = await _requestOrderService.GetAllAsync(cancellationToken);

            // Assert
            _requestOrderRepository.Verify(x => x.GetAllDataAsync(It.IsAny <PagingInfo>(), cancellationToken), Times.Once);
            _userRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Exactly(users.Count));
            _orderRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Exactly(orders.Count));
        }