public async Task UpdateTitleTest(string title, string description, int goalNumber, int projectId, GoalState state, GoalPriority priority) { //Arrange int goalId = 1; var vmGoal = new VmGoal { Id = goalId, Title = title, Description = description, ProjectId = projectId, State = state, Priority = priority, GoalNumber = goalNumber, IsRemoved = true }; //Act await _service.Update(_currentUser, vmGoal); var goal = _dataContext.Goals.First(g => g.Id == goalId); //Assert Assert.AreEqual(title, goal.Title); Assert.AreEqual(description, goal.Description); Assert.AreEqual(projectId, goal.ProjectId); Assert.AreEqual(priority, goal.Priority); Assert.AreEqual(state, goal.State); Assert.AreEqual(0, (goal.CreationDate - DateTime.Now).TotalMinutes, 1); Assert.IsFalse(goal.IsRemoved); }
private Goal CreateGoalHierarchy(VmGoal vmGoal, string creatorId, ICollection <Goal> creatingGoals) { var goal = _vmConverter.ToModel(vmGoal); goal.Id = 0; goal.CreationDate = DateTime.Now.ToUniversalTime(); goal.OwnerId = creatorId; goal.MetadataList = vmGoal.MetadataList?.Select(m => new Metadata { Key = m.Key, Value = m.Value }).ToList(); goal.Observers = vmGoal.ObserverIds? .Select(observerId => new GoalObserver(vmGoal.Id, observerId)) .ToList(); creatingGoals.Add(goal); if (vmGoal.Children == null) { return(goal); } foreach (var vmChildGoal in vmGoal.Children) { var childGoal = CreateGoalHierarchy(vmChildGoal, creatorId, creatingGoals); childGoal.ParentGoal = goal; } return(goal); }
public async Task <IActionResult> Update([FromBody] VmGoal goal) { var currentUser = await _currentUserService.GetCurrentUser(User); await _service.Update(currentUser, goal); return(NoContent()); }
public async Task <ActionResult <VmGoal> > Create([FromBody] VmGoal goal) { var currentUser = await _currentUserService.GetCurrentUser(User); var vmGoal = await _service.Create(currentUser, goal); //return Ok(vmGoal); return(CreatedAtAction("Get", new { id = vmGoal.Id }, vmGoal)); }
public void CreateInvalidTitleTest(string title) { //Arrange var vmGoal = new VmGoal { Id = 0, Title = title, ProjectId = _testData.Projects.First().Id, IsRemoved = false }; //Assert Assert.ThrowsAsync <HttpResponseException>(async() => await _service.Create(_currentUser, vmGoal)); }
public async Task CreationTimeTest() { //Arrange var vmGoal = new VmGoal { Title = "NewGoal", ProjectId = _testData.Projects.First().Id, CreationDate = DateTime.MinValue, IsRemoved = false }; //Act var result = await _service.Create(_currentUser, vmGoal); var delta = Math.Abs((DateTime.Now.ToUniversalTime() - result.CreationDate).TotalSeconds); //Assert Assert.AreEqual(0, delta, 10); }
private async Task <Goal> CreateGoal(ApplicationUser currentUser, VmGoal vmGoal) { if (vmGoal == null) { throw new HttpResponseException(BadRequest, $"Parameter '{nameof(vmGoal)}' cannot be null"); } if (string.IsNullOrWhiteSpace(vmGoal.Title)) { throw new HttpResponseException(BadRequest, "Goal title cannot be empty"); } var creatingGoals = new List <Goal>(); var goal = CreateGoalHierarchy(vmGoal, currentUser.Id, creatingGoals); await _dataContext.Goals.AddRangeAsync(creatingGoals); await _dataContext.SaveChangesAsync(); NotifyChanged(currentUser, creatingGoals, EntityOperation.Create); return(goal); }
/// <inheritdoc /> public async Task Update(ApplicationUser currentUser, VmGoal goal) { await UpdateGoals(currentUser, new[] { goal }); }
/// <inheritdoc /> public async Task <VmGoal> Create(ApplicationUser currentUser, VmGoal goal) { var model = await CreateGoal(currentUser, goal); return(_vmConverter.ToViewModel(model)); }