Ejemplo n.º 1
0
        public async Task UpdateImageCaption_PublishesImageCaptionUpdatedEventToEventGrid()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();
            var fullImageBlob      = new CloudBlockBlob(new Uri("https://fakeblobrepository/fullimages/fakeuserid/fakeid"));

            fullImageBlob.Metadata[ImagesService.CaptionMetadataName] = "oldcaption";
            fakeBlobRepository.AddFakeBlob(ImagesService.FullImagesBlobContainerName, "fakeuserid/fakeid", fullImageBlob);
            fakeBlobRepository.AddFakeBlob(ImagesService.PreviewImagesBlobContainerName, "fakeuserid/fakeid");
            var mockImageCaptionService = new Mock <IImageCaptionService>();

            mockImageCaptionService
            .Setup(m => m.GetImageCaptionAsync(It.IsAny <byte[]>()))
            .ReturnsAsync("newcaption");
            var mockEventGridPublisherService = new Mock <IEventGridPublisherService>();
            var service = new ImagesService(fakeBlobRepository, new Mock <ImageValidatorService>().Object, new Mock <IImagePreviewService>().Object, mockImageCaptionService.Object, mockEventGridPublisherService.Object);

            // act
            await service.UpdateImageNoteCaptionAsync("fakeid", "fakeuserid");

            // assert
            mockEventGridPublisherService.Verify(m =>
                                                 m.PostEventGridEventAsync(EventTypes.Images.ImageCaptionUpdated,
                                                                           "fakeuserid/fakeid",
                                                                           It.Is <ImageCaptionUpdatedEventData>(i => i.Caption == "newcaption")),
                                                 Times.Once);
        }
Ejemplo n.º 2
0
        public async Task DeleteImageNote_IncorrectUserId_DoesNotDeleteImage()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();

            fakeBlobRepository.AddFakeBlob(ImagesService.FullImagesBlobContainerName, "fakeuserid2/fakeid");
            fakeBlobRepository.AddFakeBlob(ImagesService.PreviewImagesBlobContainerName, "fakeuserid2/fakeid");
            var service = new ImagesService(fakeBlobRepository, new Mock <ImageValidatorService>().Object, new Mock <IImagePreviewService>().Object, new Mock <IImageCaptionService>().Object, new Mock <IEventGridPublisherService>().Object);

            // act
            await service.DeleteImageNoteAsync("fakeid", "fakeuserid");

            // assert
            Assert.Equal(2, fakeBlobRepository.Blobs.Count);
        }
Ejemplo n.º 3
0
        public async Task GetImageNote_CaptionMissing()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();

            fakeBlobRepository.AddFakeBlob(ImagesService.FullImagesBlobContainerName, "fakeuserid/fakeid");
            fakeBlobRepository.AddFakeBlob(ImagesService.PreviewImagesBlobContainerName, "fakeuserid/fakeid");
            var service = new ImagesService(fakeBlobRepository, new Mock <ImageValidatorService>().Object, new Mock <IImagePreviewService>().Object, new Mock <IImageCaptionService>().Object, new Mock <IEventGridPublisherService>().Object);

            // act
            var result = await service.GetImageNoteAsync("fakeid", "fakeuserid");

            // assert
            Assert.Equal("https://fakeblobrepository/fullimages/fakeuserid/fakeid?sasToken=Read", result.ImageUrl);
            Assert.Null(result.Caption);
        }
Ejemplo n.º 4
0
        public async Task UpdateImageCaption_IncorrectUserId_ReturnsNotFound()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();
            var fullImageBlob      = new CloudBlockBlob(new Uri("https://fakeblobrepository/fullimages/fakeuserid2/fakeid"));

            fullImageBlob.Metadata[ImagesService.CaptionMetadataName] = "oldcaption";
            fakeBlobRepository.AddFakeBlob(ImagesService.FullImagesBlobContainerName, "fakeuserid2/fakeid", fullImageBlob);
            fakeBlobRepository.AddFakeBlob(ImagesService.PreviewImagesBlobContainerName, "fakeuserid2/fakeid");
            var service = new ImagesService(fakeBlobRepository, new Mock <ImageValidatorService>().Object, new Mock <IImagePreviewService>().Object, new Mock <IImageCaptionService>().Object, new Mock <IEventGridPublisherService>().Object);

            // act
            var result = await service.UpdateImageNoteCaptionAsync("fakeid", "fakeuserid");

            // assert
            Assert.Equal(UpdateImageNoteCaptionResult.NotFound, result);
        }
Ejemplo n.º 5
0
        public async Task ListImageNotes_DoesNotReturnsIdsForAnotherUser()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();

            fakeBlobRepository.AddFakeBlob(ImagesService.FullImagesBlobContainerName, "fakeuserid1/fakeid1", new CloudBlockBlob(new Uri("https://fakeblobrepository/fullimages/fakeuserid1/fakeid1")));
            fakeBlobRepository.AddFakeBlob(ImagesService.PreviewImagesBlobContainerName, "fakeuserid1/fakeid1", new CloudBlockBlob(new Uri("https://fakeblobrepository/previewimages/fakeuserid1/fakeid1")));
            fakeBlobRepository.AddFakeBlob(ImagesService.FullImagesBlobContainerName, "fakeuserid2/fakeid2", new CloudBlockBlob(new Uri("https://fakeblobrepository/fullimages/fakeuserid2/fakeid2")));
            fakeBlobRepository.AddFakeBlob(ImagesService.PreviewImagesBlobContainerName, "fakeuserid2/fakeid2", new CloudBlockBlob(new Uri("https://fakeblobrepository/previewimages/fakeuserid2/fakeid2")));
            var service = new ImagesService(fakeBlobRepository, new Mock <ImageValidatorService>().Object, new Mock <IImagePreviewService>().Object, new Mock <IImageCaptionService>().Object, new Mock <IEventGridPublisherService>().Object);

            // act
            var result = await service.ListImageNotesAsync("fakeuserid1");

            // assert
            Assert.Single(result);
            Assert.Equal("fakeid1", result.Single().Id);
        }
Ejemplo n.º 6
0
        public async Task GetImageNote_ReturnsImage()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();
            var fullImageBlob      = new CloudBlockBlob(new Uri("https://fakeblobrepository/fullimages/fakeuserid/fakeid"));

            fullImageBlob.Metadata[ImagesService.CaptionMetadataName] = "fakecaption";
            fakeBlobRepository.AddFakeBlob(ImagesService.FullImagesBlobContainerName, "fakeuserid/fakeid", fullImageBlob);
            fakeBlobRepository.AddFakeBlob(ImagesService.PreviewImagesBlobContainerName, "fakeuserid/fakeid");
            var service = new ImagesService(fakeBlobRepository, new Mock <ImageValidatorService>().Object, new Mock <IImagePreviewService>().Object, new Mock <IImageCaptionService>().Object, new Mock <IEventGridPublisherService>().Object);

            // act
            var result = await service.GetImageNoteAsync("fakeid", "fakeuserid");

            // assert
            Assert.Equal("https://fakeblobrepository/fullimages/fakeuserid/fakeid?sasToken=Read", result.ImageUrl);
            Assert.Equal("https://fakeblobrepository/previewimages/fakeuserid/fakeid?sasToken=Read", result.PreviewUrl);
            Assert.Equal("fakecaption", result.Caption);
        }
Ejemplo n.º 7
0
        public async Task CompleteAddImageNote_IncorrectUserId_ReturnsImageNotUploaded()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();

            fakeBlobRepository.AddFakeBlob(ImagesService.FullImagesBlobContainerName, "fakeuserid2/fakeid");
            fakeBlobRepository.AddFakeBlob(ImagesService.PreviewImagesBlobContainerName, "fakeuserid2/fakeid");
            var mockImageValidatorService = new Mock <IImageValidatorService>();

            mockImageValidatorService
            .Setup(m => m.ValidateImage(It.IsAny <Stream>()))
            .Returns(new ValueTuple <bool, string>(false, ""));
            var service = new ImagesService(fakeBlobRepository, mockImageValidatorService.Object, new Mock <IImagePreviewService>().Object, new Mock <IImageCaptionService>().Object, new Mock <IEventGridPublisherService>().Object);

            // act
            var output = await service.CompleteAddImageNoteAsync("fakeid", "fakeuserid", "fakecategory");

            // assert
            Assert.Equal(CompleteAddImageNoteResult.ImageNotUploaded, output.result);
        }
Ejemplo n.º 8
0
        public async Task DeleteImageNote_PublishesImageDeletedEventToEventGrid()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();

            fakeBlobRepository.AddFakeBlob(ImagesService.FullImagesBlobContainerName, "fakeuserid/fakeid");
            fakeBlobRepository.AddFakeBlob(ImagesService.PreviewImagesBlobContainerName, "fakeuserid/fakeid");
            var mockEventGridPublisherService = new Mock <IEventGridPublisherService>();
            var service = new ImagesService(fakeBlobRepository, new Mock <ImageValidatorService>().Object, new Mock <IImagePreviewService>().Object, new Mock <IImageCaptionService>().Object, mockEventGridPublisherService.Object);

            // act
            await service.DeleteImageNoteAsync("fakeid", "fakeuserid");

            // assert
            mockEventGridPublisherService.Verify(m =>
                                                 m.PostEventGridEventAsync(EventTypes.Images.ImageDeleted,
                                                                           "fakeuserid/fakeid",
                                                                           It.IsAny <ImageDeletedEventData>()),
                                                 Times.Once);
        }
Ejemplo n.º 9
0
        public async Task UpdateImageCaption_UpdatesImageCaption()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();
            var fullImageBlob      = new CloudBlockBlob(new Uri("https://fakeblobrepository/fullimages/fakeuserid/fakeid"));

            fullImageBlob.Metadata[ImagesService.CaptionMetadataName] = "oldcaption";
            fakeBlobRepository.AddFakeBlob(ImagesService.FullImagesBlobContainerName, "fakeuserid/fakeid", fullImageBlob);
            fakeBlobRepository.AddFakeBlob(ImagesService.PreviewImagesBlobContainerName, "fakeuserid/fakeid");
            var mockImageCaptionService = new Mock <IImageCaptionService>();

            mockImageCaptionService
            .Setup(m => m.GetImageCaptionAsync(It.IsAny <byte[]>()))
            .ReturnsAsync("newcaption");
            var service = new ImagesService(fakeBlobRepository, new Mock <ImageValidatorService>().Object, new Mock <IImagePreviewService>().Object, mockImageCaptionService.Object, new Mock <IEventGridPublisherService>().Object);

            // act
            await service.UpdateImageNoteCaptionAsync("fakeid", "fakeuserid");

            // assert
            Assert.Equal("newcaption", fakeBlobRepository.Blobs.Single(b => b.ContainerName == ImagesService.FullImagesBlobContainerName).Blob.Metadata[ImagesService.CaptionMetadataName]);
        }
Ejemplo n.º 10
0
        public async Task ListAudioNotes_DoesNotReturnsSummariesForAnotherUser()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();
            var blob1 = new CloudBlockBlob(new Uri("https://fakeblobrepository/audio/fakeuserid1/fakeid1"));

            blob1.Metadata.Add(AudioService.TranscriptMetadataName, "transcript1");
            fakeBlobRepository.AddFakeBlob(AudioService.AudioBlobContainerName, "fakeuserid1/fakeid1", blob1);
            var blob2 = new CloudBlockBlob(new Uri("https://fakeblobrepository/audio/fakeuserid2/fakeid2"));

            blob2.Metadata.Add(AudioService.TranscriptMetadataName, "transcript2");
            fakeBlobRepository.AddFakeBlob(AudioService.AudioBlobContainerName, "fakeuserid2/fakeid2", blob2);
            var service = new AudioService(fakeBlobRepository, new Mock <IAudioTranscriptionService>().Object, new Mock <IEventGridPublisherService>().Object);

            // act
            var result = await service.ListAudioNotesAsync("fakeuserid1");

            // assert
            Assert.Single(result);
            Assert.Equal("fakeid1", result.Single().Id);
            Assert.Equal("transcript1", result.Single().Preview);
        }
Ejemplo n.º 11
0
        public async Task CompleteAddAudioNote_ReturnsSuccess()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();

            fakeBlobRepository.AddFakeBlob(AudioService.AudioBlobContainerName, "fakeuserid/fakeid");
            var service = new AudioService(fakeBlobRepository, new Mock <IAudioTranscriptionService>().Object, new Mock <IEventGridPublisherService>().Object);

            // act
            var result = await service.CompleteAddAudioNoteAsync("fakeid", "fakeuserid", "fakecategory");

            // assert
            Assert.Equal(CompleteAddAudioNoteResult.Success, result);
        }
Ejemplo n.º 12
0
        public async Task DeleteAudioNote_IncorrectUserId_AudioNotFound()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();

            fakeBlobRepository.AddFakeBlob(AudioService.AudioBlobContainerName, "fakeuserid/fakeid");
            var service = new AudioService(fakeBlobRepository, new Mock <IAudioTranscriptionService>().Object, new Mock <IEventGridPublisherService>().Object);

            // act
            await service.DeleteAudioNoteAsync("fakeid", "fakeuserid");

            // assert
            // no exception thrown
        }
Ejemplo n.º 13
0
        public async Task DeleteAudioNote_DeletesBlob()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();

            fakeBlobRepository.AddFakeBlob(AudioService.AudioBlobContainerName, "fakeuserid/fakeid");
            var service = new AudioService(fakeBlobRepository, new Mock <IAudioTranscriptionService>().Object, new Mock <IEventGridPublisherService>().Object);

            // act
            await service.DeleteAudioNoteAsync("fakeid", "fakeuserid");

            // assert
            Assert.Empty(fakeBlobRepository.Blobs);
        }
Ejemplo n.º 14
0
        public async Task CompleteAddAudioNote_UpdatesBlobMetadata()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();

            fakeBlobRepository.AddFakeBlob(AudioService.AudioBlobContainerName, "fakeuserid/fakeid");
            var service = new AudioService(fakeBlobRepository, new Mock <IAudioTranscriptionService>().Object, new Mock <IEventGridPublisherService>().Object);

            // act
            await service.CompleteAddAudioNoteAsync("fakeid", "fakeuserid", "fakecategory");

            // assert
            Assert.Equal("fakecategory", fakeBlobRepository.Blobs.Single().Blob.Metadata[AudioService.CategoryIdMetadataName]);
            Assert.Equal("fakeuserid", fakeBlobRepository.Blobs.Single().Blob.Metadata[AudioService.UserIdMetadataName]);
        }
Ejemplo n.º 15
0
        public async Task GetAudioNote_TranscriptMissing()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();

            fakeBlobRepository.AddFakeBlob(AudioService.AudioBlobContainerName, "fakeuserid/fakeid");
            var service = new AudioService(fakeBlobRepository, new Mock <IAudioTranscriptionService>().Object, new Mock <IEventGridPublisherService>().Object);

            // act
            var result = await service.GetAudioNoteAsync("fakeid", "fakeuserid");

            // assert
            Assert.Equal("https://fakeblobrepository/audio/fakeuserid/fakeid?sasToken=Read", result.AudioUrl);
            Assert.Null(result.Transcript);
        }
Ejemplo n.º 16
0
        public async Task GetAudioNote_IncorrectUserId_ReturnsNull()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();
            var fullAudioBlob      = new CloudBlockBlob(new Uri("https://fakeblobrepository/audio/fakeuserid/audio"));

            fullAudioBlob.Metadata[AudioService.TranscriptMetadataName] = "faketranscript";
            fakeBlobRepository.AddFakeBlob(AudioService.AudioBlobContainerName, "fakeuserid2/fakeid", fullAudioBlob);
            var service = new AudioService(fakeBlobRepository, new Mock <IAudioTranscriptionService>().Object, new Mock <IEventGridPublisherService>().Object);

            // act
            var result = await service.GetAudioNoteAsync("fakeid", "fakeuserid");

            // assert
            Assert.Null(result);
        }
Ejemplo n.º 17
0
        public async Task GetAudioNote_ReturnsAudio()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();
            var fullAudioBlob      = new CloudBlockBlob(new Uri("https://fakeblobrepository/audio/fakeuserid/fakeid"));

            fullAudioBlob.Metadata[AudioService.TranscriptMetadataName] = "faketranscript";
            fakeBlobRepository.AddFakeBlob(AudioService.AudioBlobContainerName, "fakeuserid/fakeid", fullAudioBlob);
            var service = new AudioService(fakeBlobRepository, new Mock <IAudioTranscriptionService>().Object, new Mock <IEventGridPublisherService>().Object);

            // act
            var result = await service.GetAudioNoteAsync("fakeid", "fakeuserid");

            // assert
            Assert.Equal("https://fakeblobrepository/audio/fakeuserid/fakeid?sasToken=Read", result.AudioUrl.OriginalString);
            Assert.Equal("faketranscript", result.Transcript);
        }
Ejemplo n.º 18
0
        public async Task CompleteAddAudioNote_ReturnsAudioAlreadyCreated()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();
            var blob = new CloudBlockBlob(new Uri("https://fakeblobrepository/audio/fakeuserid/fakeid"));

            blob.Metadata.Add(AudioService.CategoryIdMetadataName, "fakecategory");
            blob.Metadata.Add(AudioService.UserIdMetadataName, "fakeuserid");
            fakeBlobRepository.AddFakeBlob(AudioService.AudioBlobContainerName, "fakeuserid/fakeid", blob);
            var mockEventGridPublisherService = new Mock <IEventGridPublisherService>();
            var service = new AudioService(fakeBlobRepository, new Mock <IAudioTranscriptionService>().Object, mockEventGridPublisherService.Object);

            // act
            var result = await service.CompleteAddAudioNoteAsync("fakeid", "fakeuserid", "fakecategory");

            // assert
            Assert.Equal(CompleteAddAudioNoteResult.AudioAlreadyCreated, result);
        }
Ejemplo n.º 19
0
        public async Task UpdateAudioTranscript_IncorrectUserId_ReturnsTranscript()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();

            fakeBlobRepository.AddFakeBlob(AudioService.AudioBlobContainerName, "fakeuserid2/fakeid");
            var mockAudioTranscriptionService = new Mock <IAudioTranscriptionService>();

            mockAudioTranscriptionService
            .Setup(m => m.GetAudioTranscriptFromCognitiveServicesAsync(It.IsAny <Stream>()))
            .ReturnsAsync("transcript");
            var service = new AudioService(fakeBlobRepository, mockAudioTranscriptionService.Object, new Mock <IEventGridPublisherService>().Object);

            // act
            var result = await service.UpdateAudioTranscriptAsync("fakeid", "fakeuserid");

            // assert
            Assert.Null(result);
        }
Ejemplo n.º 20
0
        public async Task CompleteAddAudioNote_PublishesAudioCreatedEventToEventGrid()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();

            fakeBlobRepository.AddFakeBlob(AudioService.AudioBlobContainerName, "fakeuserid/fakeid");
            var mockEventGridPublisherService = new Mock <IEventGridPublisherService>();
            var service = new AudioService(fakeBlobRepository, new Mock <IAudioTranscriptionService>().Object, mockEventGridPublisherService.Object);

            // act
            await service.CompleteAddAudioNoteAsync("fakeid", "fakeuserid", "fakecategory");

            // assert
            mockEventGridPublisherService.Verify(m =>
                                                 m.PostEventGridEventAsync(EventTypes.Audio.AudioCreated,
                                                                           "fakeuserid/fakeid",
                                                                           It.Is <AudioCreatedEventData>(d => d.Category == "fakecategory")),
                                                 Times.Once);
        }
Ejemplo n.º 21
0
        public async Task UpdateAudioTranscript_UpdatesTranscriptBlobMetadata()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();

            fakeBlobRepository.AddFakeBlob(AudioService.AudioBlobContainerName, "fakeuserid/fakeid");
            var mockAudioTranscriptionService = new Mock <IAudioTranscriptionService>();

            mockAudioTranscriptionService
            .Setup(m => m.GetAudioTranscriptFromCognitiveServicesAsync(It.IsAny <Stream>()))
            .ReturnsAsync("transcript");
            var service = new AudioService(fakeBlobRepository, mockAudioTranscriptionService.Object, new Mock <IEventGridPublisherService>().Object);

            // act
            await service.UpdateAudioTranscriptAsync("fakeid", "fakeuserid");

            // assert
            Assert.True(fakeBlobRepository.Blobs.Single().Blob.Metadata.ContainsKey(AudioService.TranscriptMetadataName));
            Assert.Equal("transcript", fakeBlobRepository.Blobs.Single().Blob.Metadata[AudioService.TranscriptMetadataName]);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Gets an audio operations class with a blob uploaded to the mock
        /// blob repository.
        /// </summary>
        /// <param name="mockUserAuth">Returns the mock user auth.</param>
        /// <param name="fakeBlobRepo">Returns the fake blob repository with the added blob.</param>
        /// <param name="mockEventPub">Returns the fake event publisher.</param>
        /// <returns>An instance of the <see cref="Api.Functions"/> class.</returns>
        public static Api.Functions GetApiFunctionsWithBlobUploaded(
            out Mock <IUserAuthenticationService> mockUserAuth,
            out FakeBlobRepository fakeBlobRepo,
            out Mock <IEventGridPublisherService> mockEventPub)
        {
            mockUserAuth = Mockers.MockUserAuth();

            mockEventPub = new Mock <IEventGridPublisherService>();
            var mockEventSub = new Mock <IEventGridSubscriberService>();
            var mockAudioTranscriptionService = new Mock <Api.IAudioTranscriptionService>();

            fakeBlobRepo = new FakeBlobRepository();
            fakeBlobRepo.AddFakeBlob(Mockers.AudioContainerName, $"{Mockers.DefaultUserId}/{Mockers.DefaultId}");

            return(new Api.Functions(
                       mockUserAuth.Object,
                       fakeBlobRepo,
                       mockEventSub.Object,
                       mockEventPub.Object,
                       mockAudioTranscriptionService.Object));
        }
Ejemplo n.º 23
0
        public async Task CompleteAddImageNote_ReturnsImageTooLarge()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();
            var largeImageStream   = new MemoryStream();

            Fill(largeImageStream, 0, ImagesService.MaximumImageSize + 1);

            fakeBlobRepository.AddFakeBlob(ImagesService.FullImagesBlobContainerName, "fakeuserid/fakeid", largeImageStream);
            var mockImageValidatorService = new Mock <IImageValidatorService>();

            mockImageValidatorService
            .Setup(m => m.ValidateImage(It.IsAny <Stream>()))
            .Returns(new ValueTuple <bool, string>(true, ""));
            var service = new ImagesService(fakeBlobRepository, mockImageValidatorService.Object, new Mock <IImagePreviewService>().Object, new Mock <IImageCaptionService>().Object, new Mock <IEventGridPublisherService>().Object);

            // act
            var output = await service.CompleteAddImageNoteAsync("fakeid", "fakeuserid", "fakecategory");

            // assert
            Assert.Equal(CompleteAddImageNoteResult.ImageTooLarge, output.result);
        }
Ejemplo n.º 24
0
        public async Task CompleteAddImageNote_UpdatesBlobMetadata()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();

            fakeBlobRepository.AddFakeBlob(ImagesService.FullImagesBlobContainerName, "fakeuserid/fakeid");
            var mockImageValidatorService = new Mock <IImageValidatorService>();

            mockImageValidatorService
            .Setup(m => m.ValidateImage(It.IsAny <Stream>()))
            .Returns(new ValueTuple <bool, string>(true, ""));
            var service = new ImagesService(fakeBlobRepository, mockImageValidatorService.Object, new Mock <IImagePreviewService>().Object, new Mock <IImageCaptionService>().Object, new Mock <IEventGridPublisherService>().Object);

            // act
            await service.CompleteAddImageNoteAsync("fakeid", "fakeuserid", "fakecategory");

            // assert
            Assert.Equal("fakecategory",
                         fakeBlobRepository.Blobs.Single(b => b.ContainerName == ImagesService.FullImagesBlobContainerName).Blob.Metadata[ImagesService.CategoryIdMetadataName]);
            Assert.Equal("fakeuserid",
                         fakeBlobRepository.Blobs.Single(b => b.ContainerName == ImagesService.FullImagesBlobContainerName).Blob.Metadata[ImagesService.UserIdMetadataName]);
        }
Ejemplo n.º 25
0
        public async Task CompleteAddImageNote_CreatesAndUploadsPreviewBlob()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();

            fakeBlobRepository.AddFakeBlob(ImagesService.FullImagesBlobContainerName, "fakeuserid/fakeid");
            var mockImagePreviewService   = new Mock <IImagePreviewService>();
            var mockImageValidatorService = new Mock <IImageValidatorService>();

            mockImageValidatorService
            .Setup(m => m.ValidateImage(It.IsAny <Stream>()))
            .Returns(new ValueTuple <bool, string>(true, ""));
            var service = new ImagesService(fakeBlobRepository, mockImageValidatorService.Object, mockImagePreviewService.Object, new Mock <IImageCaptionService>().Object, new Mock <IEventGridPublisherService>().Object);

            // act
            await service.CompleteAddImageNoteAsync("fakeid", "fakeuserid", "fakecategory");

            // assert
            mockImagePreviewService.Verify(m =>
                                           m.CreatePreviewImage(It.IsAny <Stream>()),
                                           Times.Once);
            Assert.Contains(fakeBlobRepository.Blobs, f => f.ContainerName == ImagesService.PreviewImagesBlobContainerName);
            Assert.Equal("image/jpeg", fakeBlobRepository.Blobs.Single(b => b.ContainerName == ImagesService.PreviewImagesBlobContainerName).ContentType);
        }
Ejemplo n.º 26
0
        public async Task UpdateAudioTranscript_PublishesAudioTranscriptUpdatedEventToEventGrid()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();

            fakeBlobRepository.AddFakeBlob(AudioService.AudioBlobContainerName, "fakeuserid/fakeid");
            var mockAudioTranscriptionService = new Mock <IAudioTranscriptionService>();

            mockAudioTranscriptionService
            .Setup(m => m.GetAudioTranscriptFromCognitiveServicesAsync(It.IsAny <Stream>()))
            .ReturnsAsync("transcript");
            var mockEventGridPublisherService = new Mock <IEventGridPublisherService>();
            var service = new AudioService(fakeBlobRepository, mockAudioTranscriptionService.Object, mockEventGridPublisherService.Object);

            // act
            await service.UpdateAudioTranscriptAsync("fakeid", "fakeuserid");

            // assert
            mockEventGridPublisherService.Verify(m =>
                                                 m.PostEventGridEventAsync(EventTypes.Audio.AudioTranscriptUpdated,
                                                                           "fakeuserid/fakeid",
                                                                           It.Is <AudioTranscriptUpdatedEventData>(d => d.TranscriptPreview == "transcript")),
                                                 Times.Once);
        }
Ejemplo n.º 27
0
        public async Task CompleteAddImageNote_PublishesImageCreatedEventToEventGrid()
        {
            // arrange
            var fakeBlobRepository = new FakeBlobRepository();

            fakeBlobRepository.AddFakeBlob(ImagesService.FullImagesBlobContainerName, "fakeuserid/fakeid");
            var mockImageValidatorService = new Mock <IImageValidatorService>();

            mockImageValidatorService
            .Setup(m => m.ValidateImage(It.IsAny <Stream>()))
            .Returns(new ValueTuple <bool, string>(true, ""));
            var mockEventGridPublisherService = new Mock <IEventGridPublisherService>();
            var service = new ImagesService(fakeBlobRepository, mockImageValidatorService.Object, new Mock <IImagePreviewService>().Object, new Mock <IImageCaptionService>().Object, mockEventGridPublisherService.Object);

            // act
            await service.CompleteAddImageNoteAsync("fakeid", "fakeuserid", "fakecategory");

            // assert
            mockEventGridPublisherService.Verify(m =>
                                                 m.PostEventGridEventAsync(EventTypes.Images.ImageCreated,
                                                                           "fakeuserid/fakeid",
                                                                           It.Is <ImageCreatedEventData>(d => d.Category == "fakecategory")),
                                                 Times.Once);
        }
Ejemplo n.º 28
0
        public async Task CompleteAddImageNote_ReturnsImageAlreadyCreated()
        {
            // arrange
            var blob = new CloudBlockBlob(new Uri("https://fakeblobrepository/fullimages/fakeuserid/fakeid"));

            blob.Metadata.Add(ImagesService.CategoryIdMetadataName, "fakecategory");
            blob.Metadata.Add(ImagesService.UserIdMetadataName, "fakeuserid");
            var fakeBlobRepository = new FakeBlobRepository();

            fakeBlobRepository.AddFakeBlob(ImagesService.FullImagesBlobContainerName, "fakeuserid/fakeid", blob);
            var mockImagePreviewService   = new Mock <IImagePreviewService>();
            var mockImageValidatorService = new Mock <IImageValidatorService>();

            mockImageValidatorService
            .Setup(m => m.ValidateImage(It.IsAny <Stream>()))
            .Returns(new ValueTuple <bool, string>(true, ""));
            var service = new ImagesService(fakeBlobRepository, mockImageValidatorService.Object, mockImagePreviewService.Object, new Mock <IImageCaptionService>().Object, new Mock <IEventGridPublisherService>().Object);

            // act
            var output = await service.CompleteAddImageNoteAsync("fakeid", "fakeuserid", "fakecategory");

            // assert
            Assert.Equal(CompleteAddImageNoteResult.ImageAlreadyCreated, output.result);
        }