public async Task Handle_Success() { UnpublishLogbookEntry request = new UnpublishLogbookEntry(validLogbookEntryId); var result = await interactor.Handle(request, CancellationToken.None); result.Should().BeTrue(); A.CallTo(() => repository.UpdateAsync( A <LogbookEntry> .That.Matches(l => l.Id == validLogbookEntryId && !l.IsPublished))) .MustHaveHappenedOnceExactly(); }
public async Task Handle_Success() { A.CallTo(() => dataAccess.FindByIdAsync(ValidLogbookEntryId)) .ReturnsLazily(() => Task.FromResult(new LogbookEntry { Id = ValidLogbookEntryId })); var result = await publishLogbookEntryInteractor.Handle(request, new CancellationToken()); result.Should().BeTrue(); A.CallTo(() => dataAccess.UpdateAsync( A <LogbookEntry> .That.Matches(l => l.Id == ValidLogbookEntryId))) .MustHaveHappenedOnceExactly(); }
public async Task <bool> Handle([NotNull] UnpublishLogbookEntry request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } logger.LogInformation("Unpublish Logbook-Entry {logbookEntryId}", request.LogbookEntryId); var logbookEntry = await dataAccess.FindByIdAsync(request.LogbookEntryId); if (logbookEntry == null) { logger.LogError("Logbook-Entry {logbookEntryId} not found", request.LogbookEntryId); return(false); } try { logbookEntry.Unpublish(); await dataAccess.UpdateAsync(logbookEntry); logger.LogInformation("Logbook-Entry {logbookEntryId} unpublished successfull.", request.LogbookEntryId); } catch (Exception ex) { logger.LogError(ex, "Error unpublishing logbook entry {logbookEntryId} {logbookEntryTitle}", logbookEntry.Id, logbookEntry.Title); } return(true); }
public async Task <UseCaseResult> Handle([NotNull] EditLogbookEntry request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } logger.LogInformation("Editing existing LogbookEntry with Id [{id}] and title [{title}]", request.LogbookEntryId, request.Title); var existingLogbookEntry = await repository.FindByIdAsync(request.LogbookEntryId); if (existingLogbookEntry == null) { logger.LogError("Error editing logbook-entry because the entry with with ID [{}] can not be found!", request.LogbookEntryId); return(UseCaseResult.NotFound()); } PhotoAndThumbnailIdentifiers teaserIdentifiers = null; if (request.TeaserImage != null && request.TeaserImageContentType != null) { logger.LogInformation("Storing teaser image in photo store: [{filename}]", request.TeaserImageFileName); teaserIdentifiers = await photoService.AddPhotoAsync( PhotoCategory.LogbookTeaser, request.TeaserImage, request.TeaserImageContentType, request.TeaserImageFileName); logger.LogInformation("Teaser image stored in photo store: [{filename}]", request.TeaserImageFileName); } var currentDiver = await currentUser.GetCurrentDiverAsync(); if (currentDiver == null) { logger.LogError("Could not find diver for current user!"); return(UseCaseResult.Fail()); } existingLogbookEntry.Edit( request.Title, request.Teaser, request.Text, request.IsFavorite, currentDiver.Id, request.ExternalPhotoAlbumUrl, request.RelatedEventId, teaserIdentifiers); await repository.UpdateAsync(existingLogbookEntry); logger.LogInformation( "LogbookEntry with ID [{id}] and title [{title}] editeted successfully.", existingLogbookEntry.Id, existingLogbookEntry.Title); return(UseCaseResult.Success()); }