示例#1
0
        public async Task ChangeUserAchievementsAsync_ValidAssignAchievementsToUserModel(AssignAchievementsToUserModel model)
        {
            //Arrange
            var user              = UserDumbData.GetRandomEntity();
            var userAchievements  = UserAchievementDumbData.GetRandomEntities(5, user);
            var returnpagingInfo  = ReturnPagingInfoDumbData.GetForModel(new PagingInfo(), userAchievements);
            var cancellationToken = new CancellationToken();

            _userRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).ReturnsAsync(user);
            _userAchievementRepository.Setup(x => x.GetCountAchievementsByUserAsync(It.IsAny <Guid>(), cancellationToken)).ReturnsAsync(RandomHelper.GetRandomNumber());
            _userAchievementRepository.Setup(x => x.GetAllAchievementsByUserAsync(It.IsAny <PagingInfo>(), It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(returnpagingInfo));
            _userAchievementRepository.Setup(x => x.AddAsync(It.IsAny <UserAchievement>(), cancellationToken)).Returns(Task.CompletedTask);
            _userAchievementRepository.Setup(x => x.Delete(It.IsAny <UserAchievement>()));
            _achievementRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken))
            .Returns(Task.FromResult(AchievementDumbData.GetRandomEntity()));
            _unitOfWork.Setup(x => x.SaveChangesAsync(cancellationToken)).Returns(Task.CompletedTask);

            // Act
            await _userAchievementService.ChangeUserAchievementsAsync(model, user.Id, cancellationToken);

            // Assert
            _userRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _userAchievementRepository.Verify(x => x.GetCountAchievementsByUserAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _userAchievementRepository.Verify(x => x.GetAllAchievementsByUserAsync(It.IsAny <PagingInfo>(), It.IsAny <Guid>(), cancellationToken), Times.Once);
            _userAchievementRepository.Verify(x => x.AddAsync(It.IsAny <UserAchievement>(), cancellationToken), Times.Once);
            _userAchievementRepository.Verify(x => x.Delete(It.IsAny <UserAchievement>()), Times.Once);
            _achievementRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _unitOfWork.Verify(x => x.SaveChangesAsync(cancellationToken), Times.Once);
        }
        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);
        }
        public async Task UpdateAchievementAsync_UpdateAchievementModel_ReturnsReadAchievementModel(UpdateAchievementModel model)
        {
            //Arrange
            var achievement       = AchievementDumbData.GetEntity(model);
            var user              = UserDumbData.GetRandomEntity();
            var userAchievements  = UserAchievementDumbData.GetRandomEntities(5, user, achievement);
            var returnPagingInfo  = ReturnPagingInfoDumbData.GetForModel(new PagingInfo(), userAchievements);
            var expectedValue     = _mapper.Map <ReadAchievementModel>(achievement);
            var cancellationToken = new CancellationToken();

            _achievementRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(achievement));
            _userAchievementRepository.Setup(x => x.GetAllUsersByAchievementAsync(It.IsAny <PagingInfo>(), It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(returnPagingInfo));
            _userRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(user));
            _achievementRepository.Setup(x => x.Update(It.IsAny <Achievement>()));
            _fileService.Setup(x => x.AddOrUpdateFileByIdAsync(It.IsAny <IFormFile>(), It.IsAny <Guid?>(), cancellationToken)).Returns(Task.FromResult(expectedValue.IconId));
            _unitOfWork.Setup(x => x.SaveChangesAsync(cancellationToken)).Returns(Task.CompletedTask);

            // Act
            var response = await _achievementService.UpdateAchievementAsync(model, achievement.Id, cancellationToken);

            // Assert
            _achievementRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _achievementRepository.Verify(x => x.Update(It.IsAny <Achievement>()), Times.Once);
            _fileService.Verify(x => x.AddOrUpdateFileByIdAsync(It.IsAny <IFormFile>(), It.IsAny <Guid?>(), cancellationToken), Times.Once);
            _unitOfWork.Verify(x => x.SaveChangesAsync(cancellationToken), Times.Once);
            response.Should().BeEquivalentTo(expectedValue);
        }
示例#4
0
        public async Task GetAllEventAsync_PagingInfo_ReturnsReturnPagingInfo_EventModel(PagingInfo pagingInfo)
        {
            //Arrange
            var listOfEvents      = EventDumbData.GetRandomEntities(5);
            var paging            = ReturnPagingInfoDumbData.GetForModel(pagingInfo, listOfEvents);
            var expectedValue     = ReturnPagingInfoDumbData.GetWithModels <EventModel, Event>(paging, _mapper);
            var cancellationToken = new CancellationToken();

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

            // Act
            var response = await _eventService.GetAllEventAsync(pagingInfo, cancellationToken);

            // Assert
            _eventRepository.Verify(x => x.GetAllDataAsync(It.IsAny <PagingInfo>(), cancellationToken), Times.Once);
            response.Should().BeEquivalentTo(expectedValue);
        }
示例#5
0
        public async Task GetAllOrderAsync_ValidOrderId(PagingInfo pagingInfo)
        {
            //Arrange
            var orders            = OrderDumbData.GetRandomEntities(5);
            var cancellationToken = new CancellationToken();

            var expectedOrders = ReturnPagingInfoDumbData.GetForModel(pagingInfo, orders);
            var expectedValue  = ReturnPagingInfoDumbData.GetWithModels <ReadOrderModel, Order>(expectedOrders, _mapper);

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

            // Act
            var response = await _orderService.GetAllOrderAsync(pagingInfo, cancellationToken);

            // Assert
            _orderRepository.Verify(x => x.GetAllDataAsync(It.IsAny <PagingInfo>(), cancellationToken), Times.Once);
        }
        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);
        }
示例#7
0
        public async Task GetAllAchievementsByUserAsync(PagingInfo pagingInfo)
        {
            //Arrange
            var user              = UserDumbData.GetRandomEntity();
            var returnPage        = ReturnPagingInfoDumbData.GetForModel(pagingInfo, UserAchievementDumbData.GetRandomEntities(5, user));
            var expectedValue     = ReturnPagingInfoDumbData.GetWithModels <ReadUserAchievementModel, UserAchievement>(returnPage, _mapper);
            var cancellationToken = new CancellationToken();

            _userAchievementRepository.Setup(x => x.GetAllAchievementsByUserAsync(It.IsAny <PagingInfo>(), It.IsAny <Guid>(), cancellationToken)).ReturnsAsync(returnPage);

            // Act
            var response = await _userAchievementService.GetAllAchievementsByUserAsync(pagingInfo, user.Id, cancellationToken);

            // Assert
            _userAchievementRepository.Verify(x => x.GetAllAchievementsByUserAsync(It.IsAny <PagingInfo>(), It.IsAny <Guid>(), 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));
        }