コード例 #1
0
        public async Task UXO_GenerateDocumentWithInvalidId_ShouldReturnNotFound()
        {
            var uxoId = "1";

            var mockUxoService         = new Mock <IUXOService>();
            var mockUxoDocumentService = new Mock <IUXODocumentService>();

            mockUxoService.Setup(svc => svc.FetchUXO(uxoId))
            .ReturnsAsync((UXO)null);

            var controller = new UxoController(mockUxoService.Object, mockUxoDocumentService.Object, _logger);
            var result     = await controller.GenerateDocument(uxoId);

            var actionResult = Assert.IsType <NotFoundObjectResult>(result);

            Assert.IsType <ErrorResponse>(actionResult.Value);
        }
コード例 #2
0
        public async Task UXO_GenerateDocumentFailsToProduceDocument_ShouldReturnInternalServerError()
        {
            var uxoId = "1";

            var mockUxoService         = new Mock <IUXOService>();
            var mockUxoDocumentService = new Mock <IUXODocumentService>();

            mockUxoService.Setup(svc => svc.FetchUXO(uxoId))
            .ReturnsAsync(SampleData.MinimalUXO());
            mockUxoDocumentService.Setup(svc => svc.CreateDocument(It.IsAny <UXO>()))
            .ReturnsAsync((byte[])null);

            var controller = new UxoController(mockUxoService.Object, mockUxoDocumentService.Object, _logger);
            var result     = await controller.GenerateDocument(uxoId);

            var objectResult = Assert.IsType <ObjectResult>(result);

            Assert.Equal((int)HttpStatusCode.InternalServerError, objectResult.StatusCode);
        }
コード例 #3
0
        public async Task UXO_GenerateDocumentWithValidId_ShouldReturnFile()
        {
            var uxoId = "1";

            var mockUxoService         = new Mock <IUXOService>();
            var mockUxoDocumentService = new Mock <IUXODocumentService>();

            mockUxoService.Setup(svc => svc.FetchUXO(uxoId))
            .ReturnsAsync(SampleData.MinimalUXO());
            mockUxoDocumentService.Setup(svc => svc.CreateDocument(It.IsAny <UXO>()))
            .ReturnsAsync(SampleData.SampleFile());

            var controller = new UxoController(mockUxoService.Object, mockUxoDocumentService.Object, _logger);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();
            var result = await controller.GenerateDocument(uxoId);

            var actionResult = Assert.IsType <FileContentResult>(result);

            Assert.Equal("APPLICATION/octet-stream", actionResult.ContentType);
        }