Пример #1
0
        public async Task Should_Fail_On_CreatePdfDocument_WithHtmlContentNullOrEmpty()
        {
            var buildModel = new DefaultBuildModel("DocumentTitle", string.Empty);

            var mockConverter = new Mock <IConverter>();

            mockConverter.Setup(s => s.Convert(It.IsAny <IDocument>())).Returns(new byte[] { });

            IPdfConverter pdfConverterCore = new PdfConverter(mockConverter.Object);

            Exception exception = await Record.ExceptionAsync(async() => await pdfConverterCore.CreatePdfDocument(buildModel, new TestPdfSpecification()));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentException>(exception);
            Assert.NotNull(exception.InnerException);
            Assert.IsType <ArgumentNullException>(exception.InnerException);

            buildModel = new DefaultBuildModel("DocumentTitle", null);

            exception = await Record.ExceptionAsync(async() => await pdfConverterCore.CreatePdfDocument(buildModel, new TestPdfSpecification()));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentException>(exception);
            Assert.NotNull(exception.InnerException);
            Assert.IsType <ArgumentNullException>(exception.InnerException);

            mockConverter.Verify(v => v.Convert(It.IsAny <IDocument>()), Times.Never);
        }
Пример #2
0
        public async Task Should_Return_ByteArray_On_CreatePdfDocument()
        {
            var buildModel    = new DefaultBuildModel("DocumentTitle", "<html></html>");
            var mockConverter = new Mock <IConverter>();

            mockConverter.Setup(s => s.Convert(It.IsAny <IDocument>())).Returns(new byte[] { });

            IPdfConverter pdfConverterCore = new PdfConverter(mockConverter.Object);
            var           result           = await pdfConverterCore.CreatePdfDocument(buildModel, new TestPdfSpecification());

            Assert.NotNull(result);

            mockConverter.Verify(v => v.Convert(It.IsAny <IDocument>()), Times.Once);
        }