Esempio n. 1
0
        public async Task DownloadImageReturns500WhenExceptionIsNotKnown()
        {
            var imageStoreMock = new Mock <IImageStore>();

            imageStoreMock.Setup(store => store.Download(_testImageUpload.ImageId)).ThrowsAsync(new Exception("Test Exception"));

            var           loggerStub = new ImagesControllerLoggerStub();
            var           controller = new ImagesController(imageStoreMock.Object, loggerStub, new TelemetryClient());
            IActionResult result     = await controller.DownloadImage(_testImageUpload.ImageId);

            AssertUtils.HasStatusCode(HttpStatusCode.InternalServerError, result);
            Assert.Contains(LogLevel.Error, loggerStub.LogEntries.Select(entry => entry.Level));
        }
Esempio n. 2
0
        public async Task DeleteImageReturns503WhenStorageIsDown()
        {
            var imageStoreMock = new Mock <IImageStore>();

            imageStoreMock.Setup(store => store.Delete(_testImageUpload.ImageId)).ThrowsAsync(new StorageErrorException());

            var           loggerStub = new ImagesControllerLoggerStub();
            var           controller = new ImagesController(imageStoreMock.Object, loggerStub, new TelemetryClient());
            IActionResult result     = await controller.DeleteImage(_testImageUpload.ImageId);

            AssertUtils.HasStatusCode(HttpStatusCode.ServiceUnavailable, result);
            Assert.Contains(LogLevel.Warning, loggerStub.LogEntries.Select(entry => entry.Level));
        }
Esempio n. 3
0
        public async Task UploadImageReturns500WhenExceptionIsNotKnown()
        {
            var       stream         = new MemoryStream(_testImageDowload.ImageData);
            IFormFile file           = new FormFile(stream, 0, _testImageDowload.ImageData.Length, "file", "fileName");
            var       imageStoreMock = new Mock <IImageStore>();

            imageStoreMock.Setup(store => store.Upload(_testImageDowload.ImageData)).ThrowsAsync(new Exception("Test Exception"));

            var           loggerStub = new ImagesControllerLoggerStub();
            var           controller = new ImagesController(imageStoreMock.Object, loggerStub, new TelemetryClient());
            IActionResult result     = await controller.UploadImage(file);

            AssertUtils.HasStatusCode(HttpStatusCode.InternalServerError, result);
            Assert.Contains(LogLevel.Error, loggerStub.LogEntries.Select(entry => entry.Level));
        }