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 PublishAsync( NotificationType notificationType, string message, IEnumerable <Diver> recipients, Diver currentDiver = null, Guid?relatedEventId = null, Guid?relatedLogbookEntryId = null) { if (recipients == null) { return; } var relatedEvent = relatedEventId != null ? await eventRepository.FindByIdAsync(relatedEventId.Value) : null; var relatedLogbookEntry = relatedLogbookEntryId != null ? await logbookEntryRepository.FindByIdAsync(relatedLogbookEntryId.Value) : null; foreach (var recipient in GetRelevantRecipients(recipients, currentDiver)) { await notificationRepository.InsertAsync( new Notification( recipient, notificationType, message, relatedEvent, relatedLogbookEntry)); } }
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] DeleteLogbookEntry request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } logger.LogInformation("Deleting LogbookEntry with Id [{id}]", request.LogbookEntryId); var existingLogbookEntry = await repository.FindByIdAsync(request.LogbookEntryId); if (existingLogbookEntry == null) { return(UseCaseResult.Fail(new List <ValidationFailure> { new ValidationFailure(nameof(request.LogbookEntryId), $"Logbookeintrag [{request.LogbookEntryId}] nicht gefunden!") })); } existingLogbookEntry.Delete(); await repository.DeleteAsync(existingLogbookEntry); logger.LogInformation("Deleted LogbookEntry with Id [{id}] successfully", request.LogbookEntryId); return(UseCaseResult.Success()); }
public async Task <UseCaseResult> Handle([NotNull] GetLogbookEntryDetails request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } logger.LogDebug("Get details for LogbookEntry [{id}]", request.LogbookEntryId); var details = await repository.FindByIdAsync(request.LogbookEntryId); if (details == null) { return(UseCaseResult <LogbookEntry> .NotFound( nameof(LogbookEntry), nameof(GetLogbookEntryDetails.LogbookEntryId), request.LogbookEntryId)); } var allowEdit = await currentUser.GetIsTauchboldOrAdminAsync(); var output = new GetLogbookEntryDetailOutput( details.Id, allowEdit, details.Title, details.TeaserText, details.Text, details.ExternalPhotoAlbumUrl, details.TeaserImage, details.TeaserImageThumb, details.Event?.Name, details.EventId, details.IsFavorite, details.IsPublished, details.OriginalAuthor.Fullname, details.OriginalAuthor.User?.Email, details.OriginalAuthor.AvatarId, details.EditorAuthor?.Fullname, details.EditorAuthor?.User?.Email, details.EditorAuthor?.AvatarId, details.CreatedAt, details.ModifiedAt); request.OutputPort.Output(output); logger.LogDebug("Got details for LogbookEntry [{id}] successful", request.LogbookEntryId); return(UseCaseResult.Success()); }
public DeleteLogbookEntryInteractorTests() { validLogbookEntry = CreateValidLogbookEntry(); A.CallTo(() => repository.FindByIdAsync(A <Guid> ._)) .ReturnsLazily(call => { return(Task.FromResult( (Guid)call.Arguments[0] == validLogbookEntryId ? validLogbookEntry : null)); }); interactor = new DeleteLogbookEntryInteractor(logger, repository); }
public UnpublishLogbookEntryInteractorTests() { var logger = A.Fake <ILogger <UnpublishLogbookEntryInteractor> >(); repository = A.Fake <ILogbookEntryRepository>(); A.CallTo(() => repository.FindByIdAsync(A <Guid> ._)) .ReturnsLazily(call => Task.FromResult( (Guid)call.Arguments[0] == validLogbookEntryId ? new LogbookEntry { Id = validLogbookEntryId, Title = "TheTitle" } : null )); interactor = new UnpublishLogbookEntryInteractor(logger, repository); }
public async Task Handle([NotNull] LogbookEntryPublishedEvent notification, CancellationToken cancellationToken) { if (notification == null) { throw new ArgumentNullException(nameof(notification)); } var recipients = await diverRepository.GetAllTauchboldeUsersAsync(); var logbookEntry = await logbookEntryRepository.FindByIdAsync(notification.LogbookEntryId); var author = await diverRepository.FindByIdAsync(logbookEntry.OriginalAuthorId); var message = $"Neuer Logbucheintrag '{logbookEntry.Title}' von {author.Realname}."; await notificationPublisher.PublishAsync( NotificationType.NewLogbookEntry, message, recipients, relatedLogbookEntryId : notification.LogbookEntryId); }
public GetLogbookEntryDetailsInteractorTests() { A.CallTo(() => repository.FindByIdAsync(A <Guid> ._)) .ReturnsLazily(call => Task.FromResult( (Guid)call.Arguments[0] == validId ? new LogbookEntry { Id = validId, Title = "Test", OriginalAuthor = new Diver { Fullname = "John Doe", AvatarId = "joe1", User = new IdentityUser { Email = "*****@*****.**" } } } : null)); presenter = new MvcLogbookDetailsPresenter(relativeUrlGenerator, detailsUrlGenerator); interactor = new GetLogbookEntryDetailsInteractor(logger, repository, currentUser); }
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()); }