public void TestGoalToUserEdit() { // Generate db entry to test var rnd = new Random(); var count = rnd.Next(1, 13); for (var i = 0; i < count; i++) { _ = _userEditRepo.Create(RandomUserEdit()).Result; } var origUserEdit = _userEditRepo.Create(RandomUserEdit()).Result; // Generate correct result for comparison var modUserEdit = origUserEdit.Clone(); const string stringUserEdit = "This is another step added"; modUserEdit.Edits[0].StepData.Add(stringUserEdit); // Create wrapper object const int modGoalIndex = 0; var wrapperObj = new UserEditObjectWrapper(modGoalIndex, stringUserEdit); var action = _userEditController.Put(_projId, origUserEdit.Id, wrapperObj); Assert.That(_userEditRepo.GetAllUserEdits(_projId).Result, Has.Count.EqualTo(count + 1)); Assert.Contains(stringUserEdit, _userEditRepo.GetUserEdit( _projId, origUserEdit.Id).Result.Edits[modGoalIndex].StepData); }
public async Task <IActionResult> Put(string projectId, string userEditId, [FromBody] UserEditObjectWrapper userEdit) { if (!_permissionService.HasProjectPermission(Permission.WordEntry, HttpContext)) { return(new ForbidResult()); } // Check to see if user is changing the correct user edit if (_permissionService.IsViolationEdit(HttpContext, userEditId, projectId)) { return(new BadRequestObjectResult("You can not edit another users UserEdit")); } // Ensure project exists var proj = _projectService.GetProject(projectId); if (proj == null) { return(new NotFoundObjectResult(projectId)); } // Ensure userEdit exists var document = await _repo.GetUserEdit(projectId, userEditId); if (document == null) { return(new NotFoundResult()); } // Ensure index exists if (userEdit.GoalIndex >= document.Edits.Count) { return(new BadRequestObjectResult("Goal index out of range")); } await _userEditService.AddStepToGoal(projectId, userEditId, userEdit.GoalIndex, userEdit.NewEdit); return(new OkObjectResult(document.Edits[userEdit.GoalIndex].StepData.Count - 1)); }