public void ShouldNotImportIfImportFileEmpty()
        {
            var importModel       = new ClaimSetFileImportModel();
            var validator         = new ClaimSetFileImportModelValidator(TestContext);
            var validationResults = validator.Validate(importModel);

            validationResults.IsValid.ShouldBe(false);
            validationResults.Errors.Select(x => x.ErrorMessage).ShouldContain("'Import File' must not be empty.");
        }
        private static ClaimSetFileImportModel GetImportModel(string testJson)
        {
            var byteArray   = Encoding.UTF8.GetBytes(testJson);
            var stream      = new MemoryStream(byteArray);
            var importModel = new ClaimSetFileImportModel();
            var importFile  = new Mock <HttpPostedFileBase>();

            importFile.Setup(f => f.ContentLength).Returns(stream.Capacity);
            importFile.Setup(f => f.FileName).Returns("testfile.json");
            importFile.Setup(f => f.InputStream).Returns(stream);
            importModel.ImportFile = importFile.Object;

            return(importModel);
        }
Ejemplo n.º 3
0
        private static ClaimSetFileImportModel GetImportModel(string testJson)
        {
            var byteArray   = Encoding.UTF8.GetBytes(testJson);
            var stream      = new MemoryStream(byteArray);
            var importModel = new ClaimSetFileImportModel();

            var importFile = new Mock <IFormFile>();

            importFile.Setup(f => f.Length).Returns(stream.Capacity);
            importFile.Setup(f => f.OpenReadStream()).Returns(stream);

            importFile.Setup(f => f.FileName).Returns("testfile.json");
            importModel.ImportFile = importFile.Object;

            return(importModel);
        }
Ejemplo n.º 4
0
        public void ShouldNotImportIfImportFileHasAnInvalidExtension()
        {
            var importModel = new ClaimSetFileImportModel();

            var importFile = new Mock <IFormFile>();

            importFile.Setup(f => f.FileName).Returns("testfile.xml");
            importModel.ImportFile = importFile.Object;

            Scoped <ISecurityContext>(securityContext =>
            {
                var validator         = new ClaimSetFileImportModelValidator(securityContext);
                var validationResults = validator.Validate(importModel);
                validationResults.IsValid.ShouldBe(false);
                validationResults.Errors.Select(x => x.ErrorMessage).ShouldContain("Invalid file extension. Only '*.json' files are allowed.");
            });
        }
 public ActionResult FileImport(ClaimSetFileImportModel claimSetFileImportModel)
 {
     _claimSetFileImportCommand.Execute(claimSetFileImportModel);
     return(RedirectToAction("ClaimSets", "GlobalSettings"));
 }