Пример #1
0
        public async Task <bool> UpdateTimeEntry(TimeEntryModel data)
        {
            UpdateTimeEntry request = new UpdateTimeEntry()
            {
                Hours       = data.Hours,
                ProjectId   = data.ProjectId,
                ProjectName = data.ProjectName
            };

            var response = await timeTrackerApiClient.PutAsync <UpdateTimeEntry, UpdateTimeEntryResponse>($"/timeentries/{data.Id}", request);

            return(response.Success);
        }
        public void UpdateTimeSheetEntry_InvalidId([Frozen] Mock <ITimeTrackerRepository> repository,
                                                   Guid id,
                                                   UpdateTimeEntry input,
                                                   TimeTrackerCommandService sut)
        {
            // Arrange
            repository.Setup(o => o.GetById(id)).Returns <TimeEntry>(null);
            // Act
            Action act = () =>
            {
                var response = sut.UpdateTimeSheetEntry(id, input).GetAwaiter().GetResult();
            };

            //Assert
            act.Should().Throw <Exception>("because the id is invalid").And.Message.Contains($"User:{id} not found");
        }
Пример #3
0
        public async Task <UpdateTimeEntryResponse> UpdateTimeSheetEntry(Guid id, UpdateTimeEntry input)
        {
            var timeSheetEntry = Repository.GetById(id);

            if (timeSheetEntry == null)
            {
                // This can be a custom exception so that NotFound (404) could be thrown from the controller
                throw new Exception($"User:{id} not found");
            }
            ;
            timeSheetEntry.Update(input.ProjectId, input.ProjectName, input.Hours);
            await UnitOfWork.Commit();

            return(new UpdateTimeEntryResponse {
                Success = true
            });
        }
        public async void UpdateTimeSheetEntry_Success([Frozen] Mock <ITimeTrackerRepository> repository,
                                                       Guid id,
                                                       UpdateTimeEntry input,
                                                       TimeEntry entry,
                                                       TimeTrackerCommandService sut)
        {
            // Arrange
            repository.Setup(o => o.GetById(id)).Returns(entry);
            input.Hours = 2; // Valid value as fixture might set an invalid hours value - This can also be handled by using Fixture specimen builder
            // Act
            var response = await sut.UpdateTimeSheetEntry(id, input);

            //Assert
            response.Success.Should().BeTrue("because the action is successful");
            entry.Hours.Should().Be(input.Hours, "because the timesheet entry is updated");
            entry.ProjectId.Should().Be(input.ProjectId, "because the timesheet entry is updated");
            entry.ProjectName.Should().Be(input.ProjectName, "because the timesheet entry is updated");
        }
Пример #5
0
        public async Task <Guid> Handle(UpdateTimeEntry request, CancellationToken cancellationToken)
        {
            var toUpdateEntry = await _writeRepository.GetOrDefault <Domain.TimeEntry>(request.Entry.Id.ToString());

            if (toUpdateEntry == null)
            {
                throw new NotFoundItemException();
            }

            toUpdateEntry.Update(request.Entry.ToEventDto());

            var events = await _writeRepository.Save(WriteRepository.DefaultKeyTaker, toUpdateEntry);

            foreach (var evt in events)
            {
                await _mediator.Publish(evt, cancellationToken);
            }

            return(toUpdateEntry.Id);
        }
Пример #6
0
 public async Task <IHttpActionResult> UpdateTimeSheetEntry([FromUri] Guid id, [FromBody] UpdateTimeEntry input)
 {
     try
     {
         return(Ok(await CommandService.UpdateTimeSheetEntry(id, input)));
     }
     catch (Exception ex)
     {
         // To do -Logging
         // Can be fine tuned to throw a general exception instead of sending the server exception
         return(InternalServerError(ex));
     }
 }