public async Task GenerateCertificatesAsync_ValidRequestNullIssuerReturnsOk()
        {
            // arrange
            var certificatesController = new CertificatesController(KvWrapper, CertificatesWrapper);
            var request = new CertificatesRequest()
            {
                IssuerBase64Pfx    = null,
                VaultBaseUrl       = "http://microsoft.com",
                RequestsProperties = new CertificateRequestProperties[] {
                    new CertificateRequestProperties()
                    {
                        KeyVaultCertificateName = "test",
                        KeyVaultSecretName      = "test",
                        CertificateProperties   = new CertificateProperties()
                        {
                            SubjectName = "name",
                            ValidDays   = 2
                        }
                    }
                }
            };

            // act
            var result = await certificatesController.GenerateCertificatesAsync(request);

            // assert
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
        }
        public async Task Certificate_ShouldReturnViewResultWithCorrectModel_GivenValidCertificate()
        {
            // Arrange
            var certificateService = CertificateServiceMock.GetMock;

            certificateService.DownloadAsync(this.GetCertificate());

            var controller = new CertificatesController(
                certificateService.Object,
                diplomaService: null,
                pdfService: null)
            {
                ControllerContext = ControllerContextMock.GetMock // HttpRequest Mock
            };

            controller.ControllerContext.HttpRequest(Scheme, Host, Path); // HttpRequest Mock

            // Act
            var result = await controller.Certificate(CertificateValidId);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <CertificateServiceModel>(viewResult.Model);

            this.AsserCertificate(model);

            certificateService.Verify();
        }
        public async Task Certificate_ShouldRedirectToHome_GivenInvalidCertificate()
        {
            // Arrange
            var certificateService = CertificateServiceMock.GetMock;

            certificateService.DownloadAsync(null);

            var controller = new CertificatesController(
                certificateService.Object,
                diplomaService: null,
                pdfService: null)
            {
                TempData = TempDataMock.GetMock
            };

            // Act
            var result = await controller.Certificate(CertificateInvalidId);

            // Assert
            controller.TempData.AssertErrorMsg(WebConstants.CertificateNotFoundMsg);

            this.AssertRedirectToHomeControllerIndex(result);

            certificateService.Verify();
        }
        public void CertificateDownload_ShouldReturnFileContentResultWithCorrectContent_GivenServiceSuccess()
        {
            // Arrange
            var pdfService = PdfServiceMock.GetMock;

            pdfService.ConvertToPdf(this.GetCertificateFileBytes());

            var controller = new CertificatesController(
                certificateService: null,
                diplomaService: null,
                pdfService.Object)
            {
                ControllerContext = ControllerContextMock.GetMock // HttpRequest Mock
            };

            controller.ControllerContext.HttpRequest(Scheme, Host, Path); // HttpRequest Mock

            // Act
            var result = controller.CertificateDownload(CertificateValidId);

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

            this.AssertCertificateFileContent(fileContentResult);

            pdfService.Verify();
        }
        public void CertificateDownload_ShouldRedirectToHome_GivenInvalidPath()
        {
            // Arrange
            var pdfService = PdfServiceMock.GetMock;

            pdfService.ConvertToPdf(null);

            var controller = new CertificatesController(
                certificateService: null,
                diplomaService: null,
                pdfService.Object)
            {
                TempData          = TempDataMock.GetMock,
                ControllerContext = ControllerContextMock.GetMock // HttpRequest Mock
            };

            controller.ControllerContext.HttpRequest(Scheme, Host, Path); // HttpRequest Mock

            // Act
            var result = controller.CertificateDownload(CertificateValidId);

            // Assert
            controller.TempData.AssertErrorMsg(WebConstants.CertificateNotFoundMsg);

            this.AssertRedirectToHomeControllerIndex(result);

            pdfService.Verify();
        }
예제 #6
0
        public void SetUp()
        {
            _certificatesRepository = new Mock <ICertificatesRepository>();
            _pdfGenerator           = new Mock <IPdfGenerator>();

            _certificatesController =
                new CertificatesController(_certificatesRepository.Object, _pdfGenerator.Object, ServiceProvider.GetService <IMapper>());

            SetUpCertificatesRepository();
        }
예제 #7
0
        public async Task DeleteConfirmedCertificatesController()
        {
            var controller = new CertificatesController(GetInMemoryDbMetData(), GetHostingEnvironment());

            var result = await controller.DeleteConfirmed(certificates[1].Id);

            var viewResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Index", viewResult.ActionName);
        }
예제 #8
0
        public async Task EditCertificatesController()
        {
            var controller = new CertificatesController(GetInMemoryDbMetData(), GetHostingEnvironment());

            var result = await controller.Edit(certificates[0].Id, certificates[0], GetFormFile());

            var viewResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Index", viewResult.ActionName);
        }
        public async Task GenerateCertificatesAsync_EmptyRequestBodyReturnsBadRequest()
        {
            // arrange
            var certificatesController = new CertificatesController(KvWrapper, CertificatesWrapper);

            // act
            var result = await certificatesController.GenerateCertificatesAsync(new CertificatesRequest());

            // assert
            Assert.IsInstanceOfType(result, typeof(BadRequestResult));
        }
예제 #10
0
        public async Task DetailsCertificatesController()
        {
            var controller = new CertificatesController(GetInMemoryDbMetData(), GetHostingEnvironment());

            var result = await controller.Details(certificates[1].Id);

            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <Certificate>(viewResult.ViewData.Model);

            Assert.Equal(2, model.Id);
            Assert.Equal("Certificate 2", model.Name);
            Assert.Equal("Second Cert", model.Alt_Text);
            Assert.NotNull(viewResult);
        }
예제 #11
0
        protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
        {
            IController controller = null;

            if (controllerType == typeof(CertificatesController))
            {
                controller = new CertificatesController(_paging, _sorting, _filtering);
            }
            else if (controllerType == typeof(AdministrationController))
            {
                controller = new AdministrationController();
            }
            else
            {
                controller = null;
            }
            return(controller);
        }
예제 #12
0
        public async Task IndexCertificatesController()
        {
            var controller = new CertificatesController(GetInMemoryDbMetData(), GetHostingEnvironment());

            var result = await controller.Index();

            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <List <Certificate> >(viewResult.ViewData.Model);

            Assert.Equal("Certificate 1", model[0].Name);
            Assert.Equal("Certificate 2", model[1].Name);
            Assert.Equal("Certificate 3", model[2].Name);

            Assert.Equal("First Cert", model[0].Alt_Text);
            Assert.Equal("Second Cert", model[1].Alt_Text);
            Assert.Equal("Third Cert", model[2].Alt_Text);

            Assert.Equal(3, model.Count);
            Assert.NotNull(viewResult);
        }
        public void CertificateDownload_ShouldRedirectToView_GivenAzureDeployment()
        {
            // Arrange
            var controller = new CertificatesController(
                certificateService: null,
                diplomaService: null,
                pdfService: null)
            {
                ControllerContext = ControllerContextMock.GetMock // HttpRequest Mock
            };

            controller.ControllerContext.HttpRequest(Scheme, WebConstants.AzureWeb, Path); // HttpRequest Mock

            // Act
            var result = controller.CertificateDownload(CertificateValidId);

            // Assert
            var redirectResult = Assert.IsType <RedirectResult>(result);

            Assert.Equal(DownloadUrlAzure, redirectResult.Url);
        }