public async Task AddAsync_ValidRequestAchievementModel_ReturnsIResponse(CreateRequestAchievementModel model)
        {
            //Arrange
            var user              = UserDumbData.GetRandomEntity();
            var achievement       = AchievementDumbData.GetRandomEntity();
            var cancellationToken = new CancellationToken();

            _userRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(user));
            _userRepository.Setup(x => x.GetAdminsEmailsAsync(cancellationToken)).Returns(Task.FromResult(new List <string>() as ICollection <string>));
            _achievementRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(achievement));
            _unitOfWork.Setup(x => x.SaveChangesAsync(cancellationToken)).Returns(Task.CompletedTask);
            _emailService.Setup(x => x.SendEmailsAsync(It.IsAny <string>(), It.IsAny <string>(), cancellationToken, It.IsAny <string[]>())).Returns(Task.CompletedTask);
            _requestAchievementRepository.Setup(x => x.AddAsync(It.IsAny <RequestAchievement>(), cancellationToken)).Returns(Task.FromResult(_mapper.Map <RequestAchievement>(model)));

            string key             = "RequestAchievementPage";
            var    localizedString = new LocalizedString(key, key);

            _stringLocalizer.Setup(_ => _[key]).Returns(localizedString);

            // Act
            var response = await _requestAchievementService.AddAsync(model, user.Id, cancellationToken);

            // Assert
            _userRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _userRepository.Verify(x => x.GetAdminsEmailsAsync(cancellationToken), Times.Once);
            _unitOfWork.Verify(x => x.SaveChangesAsync(cancellationToken), Times.Once);
            _emailService.Verify(x => x.SendEmailsAsync(It.IsAny <string>(), It.IsAny <string>(), cancellationToken, It.IsAny <string[]>()), Times.Once);
            _stringLocalizer.Verify(_ => _[key], Times.Once);
            _achievementRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _requestAchievementRepository.Verify(x => x.AddAsync(It.IsAny <RequestAchievement>(), cancellationToken), Times.Once);

            response.Should().BeEquivalentTo(new OkResponse());
        }
        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);
        }
Esempio n. 3
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 DeclineOrderRequestAsync_ValidGuid(Guid id)
        {
            //Arrange
            var user         = UserDumbData.GetRandomEntity();
            var order        = OrderDumbData.GetRandomEntity();
            var requestOrder = RequestOrderDumbData.GetEntity(user.Id, order.Id);

            id = requestOrder.Id;
            var cancellationToken = new CancellationToken();

            _requestOrderRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(requestOrder));
            _userRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(user));
            _orderRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(order));
            _userRepository.Setup(x => x.Update(It.IsAny <User>()));
            _requestOrderRepository.Setup(x => x.Update(It.IsAny <RequestOrder>()));
            _unitOfWork.Setup(x => x.SaveChangesAsync(cancellationToken)).Returns(Task.CompletedTask);

            // Act
            await _requestOrderService.DeclineOrderRequestAsync(id, cancellationToken);

            // Assert
            _requestOrderRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _userRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _orderRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _userRepository.Verify(x => x.Update(It.IsAny <User>()), Times.Once);
            _requestOrderRepository.Verify(x => x.Update(It.IsAny <RequestOrder>()), Times.Once);
            _unitOfWork.Verify(x => x.SaveChangesAsync(cancellationToken), Times.Once);
        }
        public async Task AddUserAsync_ValidCreateUserModels_ReturnsReadFullUserInfo(CreateUserModel model)
        {
            //Arrange
            var cancellationToken = new CancellationToken();
            var expectedValue     = UserDumbData.GetReadFullUserModel(model);

            _userRepository.Setup(x => x.AddAsync(It.IsAny <User>(), cancellationToken)).Returns(Task.CompletedTask);
            _unitOfWork.Setup(x => x.SaveChangesAsync(cancellationToken)).Returns(Task.CompletedTask);
            _emailService.Setup(x => x.SendEmailAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), cancellationToken)).Returns(Task.CompletedTask);

            string key             = "RegisterPage";
            var    localizedString = new LocalizedString(key, key);

            _stringLocalizer.Setup(_ => _[key]).Returns(localizedString);
            _hasher.Setup(x => x.GetHash(It.IsAny <string>())).Returns(model.Password);
            _fileService.Setup(x => x.AddOrUpdateFileByIdAsync(It.IsAny <IFormFile>(), It.IsAny <Guid?>(), cancellationToken)).Returns(Task.FromResult(expectedValue.AvatarId));
            _roleRepository.Setup(x => x.GetRoleByNameAsync(It.IsAny <string>(), cancellationToken)).Returns((string x) => Task.FromResult(RoleDumbData.GetEntity(x)));

            // Act
            var response = await _userService.AddUserAsync(model, cancellationToken);

            expectedValue.Id = response.Id;

            // Assert
            _userRepository.Verify(x => x.AddAsync(It.IsAny <User>(), cancellationToken), Times.Once);
            _unitOfWork.Verify(x => x.SaveChangesAsync(cancellationToken), Times.Once);
            _emailService.Verify(x => x.SendEmailAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), cancellationToken), Times.Once);
            _stringLocalizer.Verify(_ => _[key], Times.Once);
            _hasher.Verify(x => x.GetHash(It.IsAny <string>()), Times.Once);
            _fileService.Verify(x => x.AddOrUpdateFileByIdAsync(It.IsAny <IFormFile>(), It.IsAny <Guid?>(), cancellationToken), Times.Once);
            _roleRepository.Verify(x => x.GetRoleByNameAsync(It.IsAny <string>(), cancellationToken), Times.Once);
            Assert.IsNotNull(response);
            expectedValue.Should().BeEquivalentTo(response);
        }
        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);
        }
Esempio n. 7
0
        public async Task GetLastThankAsync()
        {
            //Arrange
            var cancellationToken = new CancellationToken();
            var user = UserDumbData.GetRandomEntity();

            _thankRepository.Setup(x => x.GetLastThankAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(ThankDumbData.GetRandomEntity()));

            // Act
            await _thankService.GetLastThankAsync(user.Id, cancellationToken);

            // Assert
            _thankRepository.Verify(x => x.GetLastThankAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
        }
        public async Task GetShortUserByIdAsync_ValidGuids_ReturnsReadShortUserModel()
        {
            //Arrange
            var expectedUser      = UserDumbData.GetRandomEntity();
            var expectedValue     = _mapper.Map <ReadShortUserModel>(expectedUser);
            var cancellationToken = new CancellationToken();

            _userRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(expectedUser));

            // Act
            var response = await _userService.GetShortUserByIdAsync(expectedUser.Id, cancellationToken);

            // Assert
            _userRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            response.Should().BeEquivalentTo(expectedValue);
        }
        public async Task AddAsync_CreateRequestOrderModel_ReturnsOkResponse(CreateRequestOrderModel model, Guid userId)
        {
            //Arrange
            var user = UserDumbData.GetRandomEntity();

            userId = user.Id;
            var order = OrderDumbData.GetRandomEntity();

            model.OrderId = order.Id;
            var enoughXP          = user.XP < order.Price;
            var cancellationToken = new CancellationToken();

            ICollection <string> emailCollection = new List <string> {
                RandomHelper.GetRandomString(),
                                 RandomHelper.GetRandomString(),
            };

            _userRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(user));
            _orderRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(order));
            _userRepository.Setup(x => x.GetAdminsEmailsAsync(cancellationToken)).Returns(Task.FromResult(emailCollection));
            _unitOfWork.Setup(x => x.SaveChangesAsync(cancellationToken)).Returns(Task.CompletedTask);
            _emailService.Setup(x => x.SendEmailsAsync(It.IsAny <string>(), It.IsAny <string>(), cancellationToken, It.IsAny <string[]>())).Returns(Task.CompletedTask);
            string key             = "RequestOrderPage";
            var    localizedString = new LocalizedString(key, key);

            _stringLocalizer.Setup(_ => _[key]).Returns(localizedString);

            // Act
            var response = await _requestOrderService.AddAsync(model, userId, cancellationToken);

            // Assert
            _userRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _orderRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            if (enoughXP)
            {
                response.Should().BeOfType <NotAllowedResponse>();
            }
            else
            {
                _userRepository.Verify(x => x.GetAdminsEmailsAsync(cancellationToken), Times.Once);
                _stringLocalizer.Verify(_ => _[key], Times.Once);
                _unitOfWork.Verify(x => x.SaveChangesAsync(cancellationToken), Times.Once);
                _emailService.Verify(x => x.SendEmailsAsync(It.IsAny <string>(), It.IsAny <string>(), cancellationToken, It.IsAny <string[]>()), Times.Once);
                response.Should().BeOfType <OkResponse>();
            }
        }
Esempio n. 10
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);
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
        public async Task DeleteUserAsync_ValidGuids()
        {
            //Arrange
            var user = UserDumbData.GetRandomEntity();
            var cancellationToken = new CancellationToken();

            _userRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).ReturnsAsync(user);
            _userRepository.Setup(x => x.Delete(It.IsAny <User>()));
            _unitOfWork.Setup(x => x.SaveChangesAsync(cancellationToken)).Returns(Task.CompletedTask);

            // Act
            await _userService.DeleteUserAsync(user.Id, cancellationToken);

            // Assert
            _userRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _userRepository.Verify(x => x.Delete(It.IsAny <User>()), Times.Once);
            _unitOfWork.Verify(x => x.SaveChangesAsync(cancellationToken), Times.Once);
        }
Esempio n. 13
0
        public async Task AddAsync_ValidCreateThankModel(CreateThankModel model)
        {
            //Arrange
            var cancellationToken = new CancellationToken();

            var user = UserDumbData.GetRandomEntity();

            _userRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(user));
            _thankRepository.Setup(x => x.AddAsync(It.IsAny <Thank>(), cancellationToken)).Returns(Task.CompletedTask);
            _unitOfWork.Setup(x => x.SaveChangesAsync(cancellationToken)).Returns(Task.CompletedTask);

            // Act
            await _thankService.AddAsync(model, user.Id, cancellationToken);

            // Assert
            _userRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _thankRepository.Verify(x => x.AddAsync(It.IsAny <Thank>(), cancellationToken), Times.Once);
            _unitOfWork.Verify(x => x.SaveChangesAsync(cancellationToken), Times.Once);
        }
Esempio n. 14
0
        public async Task GetFullUserByIdAsync_ValidGuids_ReturnsReadFullUserModel()
        {
            //Arrange
            var expectedUser  = UserDumbData.GetRandomEntity();
            var badgetCount   = RandomHelper.GetRandomNumber();
            var expectedValue = _mapper.Map <ReadFullUserModel>(expectedUser);

            expectedValue.BadgesCount = badgetCount;
            var cancellationToken = new CancellationToken();

            _userRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(expectedUser));
            _userAchievementRepository.Setup(x => x.GetCountAchievementsByUserAsync(It.IsAny <Guid>(), cancellationToken)).ReturnsAsync(badgetCount);

            // Act
            var response = await _userService.GetFullUserByIdAsync(expectedUser.Id, cancellationToken);

            // Assert
            _userRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            response.Should().BeEquivalentTo(expectedValue);
        }
Esempio n. 15
0
        public async Task UpdatePasswordAsync_ValidUpdatePasswordAsyncModels(string newPassword)
        {
            //Arrange
            var user = UserDumbData.GetRandomEntity();
            var cancellationToken = new CancellationToken();

            _userRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(user));
            _userRepository.Setup(x => x.Update(It.IsAny <User>()));
            _unitOfWork.Setup(x => x.SaveChangesAsync(cancellationToken)).Returns(Task.CompletedTask);
            _hasher.Setup(x => x.GetHash(It.IsAny <string>())).Returns(newPassword);

            // Act
            await _userService.UpdatePasswordAsync(user.Id, newPassword, cancellationToken);

            // Assert
            _userRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _userRepository.Verify(x => x.Update(It.IsAny <User>()), Times.Once);
            _unitOfWork.Verify(x => x.SaveChangesAsync(cancellationToken), Times.Once);
            _hasher.Verify(x => x.GetHash(It.IsAny <string>()), Times.Once);
        }
Esempio n. 16
0
        public async Task AddAsync_ValidUserId_AchievementId()
        {
            //Arrange
            var user              = UserDumbData.GetRandomEntity();
            var achievement       = AchievementDumbData.GetRandomEntity();
            var cancellationToken = new CancellationToken();

            _userRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).ReturnsAsync(user);
            _achievementRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).ReturnsAsync(achievement);
            _userAchievementRepository.Setup(x => x.AddAsync(It.IsAny <UserAchievement>(), cancellationToken)).Returns(Task.CompletedTask);
            _eventRepository.Setup(x => x.AddAsync(It.IsAny <Event>(), cancellationToken)).Returns(Task.CompletedTask);
            _unitOfWork.Setup(x => x.SaveChangesAsync(cancellationToken)).Returns(Task.CompletedTask);

            // Act
            await _userAchievementService.AddAsync(user.Id, achievement.Id, cancellationToken);

            // Assert
            _userRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _userAchievementRepository.Verify(x => x.AddAsync(It.IsAny <UserAchievement>(), cancellationToken), Times.Once);
            _achievementRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _eventRepository.Verify(x => x.AddAsync(It.IsAny <Event>(), cancellationToken), Times.Once);
            _unitOfWork.Verify(x => x.SaveChangesAsync(cancellationToken), Times.Once);
        }
Esempio n. 17
0
        public async Task UpdateUserAsync_ValidUpdateFullUserModelsWithIds_ReturnsReadFullUserModel(UpdateUserModel model)
        {
            //Arrange
            var expectedUser      = UserDumbData.GetEntity(model);
            var expectedValue     = _mapper.Map <ReadFullUserModel>(expectedUser);
            var cancellationToken = new CancellationToken();

            _userRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken)).Returns(Task.FromResult(expectedUser));
            _userRepository.Setup(x => x.Update(It.IsAny <User>()));
            _fileService.Setup(x => x.AddOrUpdateFileByIdAsync(It.IsAny <IFormFile>(), It.IsAny <Guid?>(), cancellationToken)).Returns(Task.FromResult(expectedValue.AvatarId));
            _roleRepository.Setup(x => x.GetRoleByNameAsync(It.IsAny <string>(), cancellationToken)).Returns((string x) => Task.FromResult(RoleDumbData.GetEntity(x))).Verifiable();
            _unitOfWork.Setup(x => x.SaveChangesAsync(cancellationToken)).Returns(Task.CompletedTask);

            // Act
            var response = await _userService.UpdateUserAsync(model, expectedUser.Id, cancellationToken);

            // Assert
            _userRepository.Verify(x => x.GetByIdAsync(It.IsAny <Guid>(), cancellationToken), Times.Once);
            _userRepository.Verify(x => x.Update(It.IsAny <User>()), Times.Once);
            _fileService.Verify(x => x.AddOrUpdateFileByIdAsync(It.IsAny <IFormFile>(), It.IsAny <Guid?>(), cancellationToken), Times.Once);
            _unitOfWork.Verify(x => x.SaveChangesAsync(cancellationToken), Times.Once);
            _roleRepository.Verify(x => x.GetRoleByNameAsync(It.IsAny <string>(), 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));
        }