public void CanPatchAndMapToViewModel() { //// ARRANGE var learningModuleCreatedBy = Guid.NewGuid(); var userAadObjectId = Guid.NewGuid(); this.learningModule.CreatedBy = learningModuleCreatedBy; var learningModuleVote = new LearningModuleVote { Id = Guid.NewGuid(), UserId = userAadObjectId, }; List <LearningModuleVote> learningModuleVotes = new List <LearningModuleVote>(); learningModuleVotes.Add(learningModuleVote); var userDetail = new UserDetail { UserId = this.learningModule.CreatedBy, DisplayName = "User3", }; this.userDetails.Add(userDetail); //// ACT var result = this.learningModuleMapper.PatchAndMapToViewModel(FakeData.GetLearningModule(), Guid.Parse(FakeData.UserID), learningModuleVotes, 2, FakeData.GetUserDetails()); //// ASSERT Assert.AreEqual(FakeData.GetLearningModules().First().Id, result.Id); Assert.AreEqual(FakeData.GetLearningModules().First().Title, result.Title); Assert.AreEqual(FakeData.GetLearningModules().First().CreatedBy, result.CreatedBy); Assert.AreEqual(FakeData.GetUserDetails().First().Value, result.UserDisplayName); }
public void CanPatchAndMapToViewModel() { //// ARRANGE var learningModuleCreatedBy = Guid.NewGuid(); var userAadObjectId = Guid.NewGuid(); this.learningModule.CreatedBy = learningModuleCreatedBy; var learningModuleVote = new LearningModuleVote { Id = Guid.NewGuid(), UserId = userAadObjectId, }; List <LearningModuleVote> learningModuleVotes = new List <LearningModuleVote>(); learningModuleVotes.Add(learningModuleVote); var userDetail = new UserDetail { UserId = this.learningModule.CreatedBy, DisplayName = "User3", }; this.userDetails.Add(userDetail); //// ACT var result = this.learningModuleMapper.PatchAndMapToViewModel(this.learningModule, userAadObjectId, learningModuleVotes, 2, this.userDetails); //// ASSERT Assert.AreEqual(result.CreatedBy, learningModuleCreatedBy); }
/// <summary> /// Make fake ResourceVote data for unit testing. /// </summary> /// <returns>Tag collection</returns> public static IEnumerable <LearningModuleVote> GetLearningModuleVotes() { var resourceVotes = new List <LearningModuleVote>(); var resourceVote = new LearningModuleVote() { Id = Guid.Parse(UserID), ModuleId = Guid.Parse(Id), UserId = Guid.Parse(UserID), }; resourceVotes.Add(resourceVote); return(resourceVotes); }
public async Task <IActionResult> PostVoteAsync(Guid id) { this.logger.LogInformation("Learning module vote - HTTP Post call initiated."); this.RecordEvent("Learning module vote - HTTP Post call initiated.", RequestType.Initiated); if (id == null || id == Guid.Empty) { this.logger.LogError($"Learning Module Id is either null or empty guid for userId: {this.UserObjectId}"); this.RecordEvent("Learning module vote - HTTP Post call failed.", RequestType.Failed); return(this.BadRequest("Learning Module Id cannot be null or empty.")); } try { var learningModuleVotes = await this.unitOfWork.LearningModuleVoteRepository.FindAsync(moduleVote => moduleVote.UserId == this.UserObjectId && moduleVote.ModuleId == id); if (learningModuleVotes.Any()) { this.logger.LogError(StatusCodes.Status409Conflict, $"Learning module vote already exists for learning module Id: {id} and user Id: {this.UserObjectId}."); this.RecordEvent("Learning module vote - HTTP Post call failed.", RequestType.Failed); return(this.Conflict($"Learning module vote already exists for learning module Id: {id} and user Id: {this.UserObjectId}.")); } LearningModuleVote vote = new LearningModuleVote { ModuleId = id, UserId = this.UserObjectId, CreatedOn = DateTime.UtcNow, }; this.unitOfWork.LearningModuleVoteRepository.Add(vote); await this.unitOfWork.SaveChangesAsync(); this.logger.LogInformation("Learning module vote - HTTP Post call succeeded."); this.RecordEvent("Learning module vote - HTTP Post call succeeded.", RequestType.Succeeded); return(this.Ok(true)); } catch (Exception ex) { this.RecordEvent("Learning module vote - HTTP Post call failed.", RequestType.Failed); this.logger.LogError(ex, $"Error while saving vote details for userId: {this.UserObjectId}"); throw; } }