コード例 #1
0
        public ActionResult AllDataManagementPlansToCsv(CsvDumpViewModel model)
        {
            var projects = _projectRepository.GetAll().Where(p => p.DataManagementPlan != null).ToList();

            if (projects.Count != 0)
            {
                var dataManagementPlanTable = _csvHelper.DataManagementPlansToDataTable(projects);
                var reponse = this.ControllerContext.RequestContext.HttpContext.Response;
                reponse.AddHeader("Content-Disposition", "attachment;filename=DataManagementPlans_" + DateTime.Now.ToShortDateString() + ".csv");
                return(File(Encoding.UTF8.GetBytes(_csvHelper.ExportToCsv(dataManagementPlanTable, _appSettingsService.CsvSeparator)), "text/csv"));
            }
            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public void Render_CSV_file_for_post_to_DataManagementPlansToCsv()
        {
            var vm = new CsvDumpViewModel {
                Projects = Builder <DmpListViewModel> .CreateListOfSize(3).Build()
            };
            var projects = Builder <Project> .CreateListOfSize(5)
                           .All()
                           .With(p => p.DataManagementPlan = Builder <DataManagementPlan> .CreateNew().Build())
                           .Build();

            _projectRepository.GetAll().Returns(projects);
            _csvHelper.ExportToCsv(Arg.Any <DataTable>()).Returns("");
            _csvHelper.DataManagementPlansToDataTable(Arg.Any <IList <Project> >()).Returns(new DataTable());
            _controller.WithCallTo(c => c.AllDataManagementPlansToCsv(vm)).ShouldRenderFile("text/csv");

            _csvHelper.Received().ExportToCsv(Arg.Any <DataTable>(), Arg.Any <string>());
            _csvHelper.Received().DataManagementPlansToDataTable(Arg.Any <IList <Project> >());

            _context.HttpContext.Response.Received().AddHeader(Arg.Any <string>(), Arg.Any <string>());
        }
コード例 #3
0
        public void Generate_Datatable_from_DataManagementPlans()
        {
            const string userId         = "GA37493";
            var          projectParties = Builder <ProjectParty> .CreateListOfSize(5)
                                          .TheFirst(1)
                                          .With(q => q.Party       = Builder <Party> .CreateNew().With(r => r.UserId = userId).Build())
                                          .And(q => q.Relationship = ProjectRelationship.PrincipalInvestigator)
                                          .TheLast(4)
                                          .With(q => q.Party       = Builder <Party> .CreateNew().Build())
                                          .And(q => q.Relationship = PickHelper.RandomEnumExcept(ProjectRelationship.None, ProjectRelationship.PrincipalInvestigator))
                                          .Build();

            var dataManagementPlan = Builder <DataManagementPlan> .CreateNew()
                                     .With(o => o.ExistingDataDetail = Builder <ExistingDataDetail> .CreateNew()
                                                                       .With(q => q.UseExistingData        = PickHelper.RandomBoolean())
                                                                       .And(q => q.ExistingDataAccessTypes = PickHelper.RandomEnumsExcept(ExistingDataAccessTypes.None))
                                                                       .Build())
                                     .And(o => o.BackupPolicy  = Builder <BackupPolicy> .CreateNew().Build())
                                     .And(o => o.NewDataDetail = Builder <NewDataDetail> .CreateNew()
                                                                 .With(q => q.DataOwners = PickHelper.RandomEnumsExcept(DataOwners.None))
                                                                 .Build())
                                     .And(o => o.DataRelationshipDetail = Builder <DataRelationshipDetail> .CreateNew()
                                                                          .With(q => q.RelationshipBetweenExistingAndNewData = PickHelper.RandomEnumExcept(DataRelationship.None))
                                                                          .Build())
                                     .And(o => o.DataDocumentation = Builder <DataDocumentation> .CreateNew()
                                                                     .Build())
                                     .And(o => o.Ethic = Builder <Ethic> .CreateNew()
                                                         .With(q => q.EthicRequiresClearance = PickHelper.RandomBoolean())
                                                         .Build())
                                     .And(o => o.Confidentiality = Builder <Confidentiality> .CreateNew()
                                                                   .With(q => q.IsSensitive = PickHelper.RandomBoolean())
                                                                   .Build())
                                     .And(o => o.DataStorage = Builder <DataStorage> .CreateNew()
                                                               .With(q => q.InstitutionalStorageTypes = PickHelper.RandomEnumExcept(InstitutionalStorageTypes.ProjectStorageSpace))
                                                               .And(q => q.ExternalStorageTypes       = PickHelper.RandomEnumExcept(ExternalStorageTypes.None))
                                                               .And(q => q.PersonalStorageTypes       = PickHelper.RandomEnumExcept(PersonalStorageTypes.None))
                                                               .And(q => q.MaxDataSize    = PickHelper.RandomEnumExcept(MaxDataSize.None))
                                                               .And(q => q.VersionControl = PickHelper.RandomEnumsExcept(VersionControl.None))
                                                               .Build())
                                     .And(o => o.DataRetention = Builder <DataRetention> .CreateNew()
                                                                 .With(q => q.DataRetentionLocations       = PickHelper.RandomEnumExcept(DataRetentionLocations.None))
                                                                 .And(q => q.DataRetentionResponsibilities = PickHelper.RandomEnumExcept(DataResponsibilities.None))
                                                                 .And(q => q.DataRetentionPeriod           = PickHelper.RandomEnumExcept <DataRetentionPeriod>())
                                                                 .Build())
                                     .And(o => o.DataSharing = Builder <DataSharing> .CreateNew()
                                                               .With(q => q.DataSharingAvailability    = PickHelper.RandomEnumExcept <DataSharingAvailability>())
                                                               .And(q => q.DataSharingAvailabilityDate = DateTime.Today.AddYears(1))
                                                               .And(q => q.ShareAccess       = PickHelper.RandomEnumExcept(ShareAccess.NoAccess))
                                                               .And(q => q.DataLicensingType = PickHelper.RandomEnumExcept <DataLicensingType>())
                                                               .Build())
                                     .Build();

            var projects = Builder <Project> .CreateListOfSize(5)
                           .All()
                           .With(o => o.DataManagementPlan = dataManagementPlan)
                           .And(o => o.ProvisioningStatus  = PickHelper.RandomEnumExcept <ProvisioningStatus>())
                           .Do(o => o.Parties.AddRange(projectParties))
                           .Build();

            var dataManagementPlansTable = _csvHelper.DataManagementPlansToDataTable(projects);

            Assert.That(dataManagementPlansTable, Is.Not.Null);
            Assert.That(dataManagementPlansTable.Columns.Count, Is.EqualTo(DataManagementColumnCount), "Incorrect number of columns");
            Assert.That(dataManagementPlansTable.Rows.Count, Is.EqualTo(5));

            for (var index = 0; index < projects.Count; index++)
            {
                var dmp     = projects[index].DataManagementPlan;
                var dataRow = dataManagementPlansTable.Rows[index];

                Assert.That(dataRow["ExistingDataAccessTypes"], Is.EqualTo(dmp.ExistingDataDetail.ExistingDataAccessTypes.ToString()));
                Assert.That(dataRow["ExistingDataOwner"], Is.EqualTo(dmp.ExistingDataDetail.ExistingDataOwner));
                Assert.That(dataRow["InstitutionalOtherTypeDescription"], Is.EqualTo(dmp.DataStorage.InstitutionalOtherTypeDescription));
                Assert.That(dataRow["DataRetentionLocations"], Is.EqualTo(dmp.DataRetention.DataRetentionLocations.ToString()));
                Assert.That(dataRow["VersionControl"], Is.EqualTo(dmp.DataStorage.VersionControl.ToString()));
                Assert.That(dataRow["EthicRequiresClearance"], Is.EqualTo(dmp.Ethic.EthicRequiresClearance));
                Assert.That(dataRow["ConfidentialityComments"], Is.EqualTo(dmp.Confidentiality.ConfidentialityComments));
                Assert.That(dataRow["RelationshipBetweenExistingAndNewData"], Is.EqualTo(dmp.DataRelationshipDetail.RelationshipBetweenExistingAndNewData.ToString()));
                Assert.That(dataRow["DataSharingAvailabilityDate"], Is.EqualTo(dmp.DataSharing.DataSharingAvailabilityDate));

                var parties = dataRow["AccessRoles"].ToString().Split('%');
                Assert.That(parties.Length, Is.EqualTo(5));
            }
        }