Esempio n. 1
0
        public void ShouldReturnTheGeneratedFilenameWithCorrectExtension()
        {
            // Arrange
            var blobStorageUrl = "https://domchk53.blob.core.windows.net/domchk53pdfcontainer";

            var mockHtmlGenerator = Substitute.For<IHtmlGenerator>();
            var mockPdfGenerator = Substitute.For<IPdfGenerator>();
            var mockStorageProvider = Substitute.For<IStorageProvider>();
            var mockFilenameGenerator = Substitute.For<IFilenameGenerator>();

            mockFilenameGenerator.GenerateFilename()
                .Returns("testfile");

            var expectedOutput = $"{blobStorageUrl}/testfile.pdf";

            var controller = new PdfOutputController(mockHtmlGenerator, mockPdfGenerator, mockStorageProvider, mockFilenameGenerator);
            var model = new SearchResultModel() { Parameters = "", Results = new List<SearchResult>() { new SearchResult() { Tld = "com", Domain = "test", Availability = "Available", CheckDate = "Today", Status = "Completed" } } };

            // Act
            IHttpActionResult actionResult = controller.GetPdfUrl(model);

            // Assert
            var result = Assert.IsType<OkNegotiatedContentResult<PdfOutputResponse>>(actionResult);
            Assert.Equal(expectedOutput, result.Content.Url);
        }
Esempio n. 2
0
        public void AllGeneratorsShouldReceiveCalls()
        {
            // Arrange
            var mockHtmlGenerator = Substitute.For<IHtmlGenerator>();
            var mockPdfGenerator = Substitute.For<IPdfGenerator>();
            var mockStorageProvider = Substitute.For<IStorageProvider>();
            var mockFilenameGenerator = Substitute.For<IFilenameGenerator>();

            var controller = new PdfOutputController(mockHtmlGenerator, mockPdfGenerator, mockStorageProvider, mockFilenameGenerator);
            var model = new SearchResultModel();

            // Act
            IHttpActionResult actionResult = controller.GetPdfUrl(model);

            // Assert
            mockHtmlGenerator.Received().GenerateHtml(Arg.Any<string>(), Arg.Any<SearchResultModel>());
            mockStorageProvider.Received().DownloadTemplate("PdfTemplate.html");
            mockPdfGenerator.Received().GetPdfData(Arg.Any<string>());
            mockStorageProvider.Received().UploadFile(Arg.Any<string>(), Arg.Any<byte[]>());
        }