public ActionResult FileExport(ClaimSetFileExportModel claimSetFileExportModel)
        {
            var exports             = _claimSetFileExportCommand.Execute(claimSetFileExportModel);
            var currentDate         = DateTime.Now.ToString("MM/dd/yyyy hh:mm tt");
            var exportClaimSetModel = new ExportClaimSetPreviewModel
            {
                DownLoadFileTitle   = $"{exports.Title}({currentDate})",
                ExportPreviewString = exports.Serialize()
            };

            return(PartialView("_ExportClaimSetPreview", exportClaimSetModel));
        }
        public void ShouldNotExportIfTitleEmpty()
        {
            var testApplication = new Application
            {
                ApplicationName = $"Test Application {DateTime.Now:O}"
            };

            Save(testApplication);

            var testClaimSet1 = new ClaimSet {
                ClaimSetName = "TestClaimSet1", Application = testApplication
            };

            Save(testClaimSet1);

            var testClaimSet2 = new ClaimSet {
                ClaimSetName = "TestClaimSet2", Application = testApplication
            };

            Save(testClaimSet2);

            var getClaimSetById = new GetClaimSetByIdQuery(TestContext);

            var exportModel = new ClaimSetFileExportModel
            {
                ClaimSets = new List <Management.ClaimSetEditor.ClaimSet>
                {
                    getClaimSetById.Execute(testClaimSet1.ClaimSetId),
                    getClaimSetById.Execute(testClaimSet2.ClaimSetId)
                },
                SelectedForExport = new List <int>
                {
                    testClaimSet1.ClaimSetId, testClaimSet2.ClaimSetId
                }
            };

            var validator         = new ClaimSetFileExportModelValidator();
            var validationResults = validator.Validate(exportModel);

            validationResults.IsValid.ShouldBe(false);
            validationResults.Errors.Select(x => x.ErrorMessage).ShouldContain("'Title' must not be empty.");
        }
        public void ShouldNotExportIfNoSelectedClaimSet()
        {
            var testApplication = new Application
            {
                ApplicationName = $"Test Application {DateTime.Now:O}"
            };

            Save(testApplication);

            var testClaimSet1 = new ClaimSet {
                ClaimSetName = "TestClaimSet1", Application = testApplication
            };

            Save(testClaimSet1);

            var testClaimSet2 = new ClaimSet {
                ClaimSetName = "TestClaimSet2", Application = testApplication
            };

            Save(testClaimSet2);

            var getClaimSetById = new GetClaimSetByIdQuery(TestContext);

            var exportModel = new ClaimSetFileExportModel
            {
                Title     = "TestDownload",
                ClaimSets = new List <Management.ClaimSetEditor.ClaimSet>
                {
                    getClaimSetById.Execute(testClaimSet1.ClaimSetId),
                    getClaimSetById.Execute(testClaimSet2.ClaimSetId)
                },
                SelectedForExport = new List <int>()
            };

            var validator         = new ClaimSetFileExportModelValidator();
            var validationResults = validator.Validate(exportModel);

            validationResults.IsValid.ShouldBe(false);
            validationResults.Errors.Select(x => x.ErrorMessage).ShouldContain("You must select at least one claimset to proceed.");
        }
        public void ShouldExportClaimSet()
        {
            var testApplication = new Application
            {
                ApplicationName = $"Test Application {DateTime.Now:O}"
            };

            Save(testApplication);

            var testClaimSet1 = new ClaimSet {
                ClaimSetName = "TestClaimSet1", Application = testApplication
            };

            Save(testClaimSet1);

            var testClaimSet2 = new ClaimSet {
                ClaimSetName = "TestClaimSet2", Application = testApplication
            };

            Save(testClaimSet2);

            SetupParentResourceClaimsWithChildren(testClaimSet1, testApplication);

            SetupParentResourceClaimsWithChildren(testClaimSet2, testApplication);

            var getClaimSetById = new GetClaimSetByIdQuery(TestContext);

            var exportModel = new ClaimSetFileExportModel
            {
                Title     = "TestDownload",
                ClaimSets = new List <Management.ClaimSetEditor.ClaimSet>
                {
                    getClaimSetById.Execute(testClaimSet1.ClaimSetId),
                    getClaimSetById.Execute(testClaimSet2.ClaimSetId)
                },
                SelectedForExport = new List <int>
                {
                    testClaimSet1.ClaimSetId, testClaimSet2.ClaimSetId
                }
            };

            var getResourceByClaimSetIdQuery = new GetResourcesByClaimSetIdQuery(TestContext, GetMapper());

            var command      = new ClaimSetFileExportCommand(TestContext, getResourceByClaimSetIdQuery);
            var sharingModel = command.Execute(exportModel);

            var resourcesForClaimSet1 = getResourceByClaimSetIdQuery.AllResources(testClaimSet1.ClaimSetId).ToList();
            var resourcesForClaimSet2 = getResourceByClaimSetIdQuery.AllResources(testClaimSet2.ClaimSetId).ToList();

            sharingModel.Title.ShouldContain("TestDownload");
            var sharedClaimSets = sharingModel.Template.ClaimSets;

            sharedClaimSets.Length.ShouldBe(2);

            var sharedClaimSet1 = sharedClaimSets[0];

            var sharedClaimSet2 = sharedClaimSets[1];

            sharedClaimSet1.Name.ShouldBe(testClaimSet1.ClaimSetName);
            MatchResources(sharedClaimSet1.ResourceClaims, resourcesForClaimSet1);

            sharedClaimSet2.Name.ShouldBe(testClaimSet2.ClaimSetName);
            MatchResources(sharedClaimSet2.ResourceClaims, resourcesForClaimSet2);
        }