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); }