public async Task GivenInvalidTypeFilePassed_WhenPostCalled_ThenReturnBadRequest()
        {
            PDFLibraryController controller = GetController();

            var result = await controller.Post(GetInvalidTypeFormFile());

            Assert.IsInstanceOf <BadRequestObjectResult>(result);

            _mockStorage.Verify(s => s.CheckExists(TEST_FILENAME1), Times.Never);
            _mockStorage.Verify(s => s.Add(It.IsAny <PdfFile>()), Times.Never);
        }
        public void GivenStoreThrowsOnCheckExists_WhenPostCalled_ThenReThrow()
        {
            PDFLibraryController controller = GetController();

            Exception thrown      = new Exception();
            var       testPdfFile = GetTestPdfFile();
            FormFile  formFile    = GetFormFile(testPdfFile);

            _mockStorage.Setup(s => s.CheckExists(testPdfFile.Name)).Throws(thrown);

            var ex = Assert.Throws <AggregateException>(() =>
            {
                var ret = controller.Post(formFile).Result;
            });

            Assert.AreEqual(thrown, ex.InnerException);
        }
        public async Task GivenPdfInStore_WhenPostCalled_ThenReturnBadRequest()
        {
            PDFLibraryController controller = GetController();

            _mockStorage.Setup(s => s.CheckExists(TEST_FILENAME1)).
            Returns(Task.Factory.StartNew(() => true));

            var testPdfFile = GetTestPdfFile();

            FormFile formFile = GetFormFile(testPdfFile);

            var result = await controller.Post(formFile);

            Assert.IsInstanceOf <BadRequestObjectResult>(result);

            _mockStorage.Verify(s => s.CheckExists(TEST_FILENAME1), Times.Once);
            _mockStorage.Verify(s => s.Add(It.IsAny <PdfFile>()), Times.Never);
        }
        public void GivenStoreThrowsOnAdd_WhenPostCalled_ThenReThrow()
        {
            PDFLibraryController controller = GetController();

            Exception thrown      = new Exception();
            var       testPdfFile = GetTestPdfFile();
            FormFile  formFile    = GetFormFile(testPdfFile);

            _mockStorage.Setup(s => s.CheckExists(TEST_FILENAME1)).
            Returns(Task.Factory.StartNew(() => false));
            _mockStorage.Setup(s => s.Add(It.IsAny <PdfFile>())).Throws(thrown);

            var ex = Assert.Throws <AggregateException>(() =>
            {
                var ret = controller.Post(formFile).Result;
            });

            Assert.AreEqual(thrown, ex.InnerException);
        }