Пример #1
0
        public async Task HappyPath()
        {
            PdfDocument pdf = new PdfDocument();
            var         ms  = new MemoryStream(File.ReadAllBytes(@".\gpg_brochure.pdf"));

            pdf.File = new FormFile(ms, 0, ms.Length, "gpg_brochure.pdf", "gpg_brochure.pdf");;

            var options = new DbContextOptionsBuilder <DocumentDbContext>()
                          .UseInMemoryDatabase(databaseName: "DocumentDbContext")
                          .Options;

            IDocumentService documentService = new DocumentService(
                new DocumentRepository(new DocumentDbContext(options)));
            var controller = new DocumentController(documentService, new ModelStateErrorHandler());

            var response = await controller.AddPdf(pdf);
        }
        public async Task AddPdf_CallsAddDocument_ReturnsTrue()
        {
            var documentServiceMock        = new Mock <IDocumentService>();
            var modelStateErrorHandlerMock = new Mock <IModelStateErrorHandler>();
            var controller = new DocumentController(documentServiceMock.Object, modelStateErrorHandlerMock.Object);
            var file       = new Mock <IFormFile>();

            file.Setup(f => f.FileName).Returns("something.pdf");
            var pdf = new PdfDocument {
                File = file.Object
            };

            MimicControllerModelValidation(controller, pdf);

            var response = await controller.AddPdf(pdf);

            documentServiceMock.Verify(x => x.AddDocument(pdf.File), Times.Once);
        }