public async Task Validate_NoDataFiles() { var release = new Release(); var contentDbContextId = Guid.NewGuid().ToString(); await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { await contentDbContext.AddAsync(release); await contentDbContext.SaveChangesAsync(); } var metaGuidanceSubjectService = new Mock <IMetaGuidanceSubjectService>(MockBehavior.Strict); await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { var service = SetupMetaGuidanceService(contentDbContext: contentDbContext, metaGuidanceSubjectService: metaGuidanceSubjectService.Object); var result = await service.Validate(release.Id); Assert.True(result.IsRight); } }
public async Task Get() { var release = new Release { MetaGuidance = "Release Meta Guidance" }; var releaseFile = new ReleaseFile { Release = release, File = new File { Filename = "file1.csv", Release = release, Type = FileType.Data, SubjectId = Guid.NewGuid() } }; var contentDbContextId = Guid.NewGuid().ToString(); await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { await contentDbContext.AddAsync(release); await contentDbContext.AddAsync(releaseFile); await contentDbContext.SaveChangesAsync(); } var metaGuidanceSubjectService = new Mock <IMetaGuidanceSubjectService>(MockBehavior.Strict); metaGuidanceSubjectService.Setup(mock => mock.GetSubjects(release.Id, new List <Guid> { releaseFile.File.SubjectId.Value })).ReturnsAsync(SubjectMetaGuidance); await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { var service = SetupMetaGuidanceService(contentDbContext: contentDbContext, metaGuidanceSubjectService: metaGuidanceSubjectService.Object); var result = await service.Get(release.Id); Assert.True(result.IsRight); metaGuidanceSubjectService.Verify(mock => mock.GetSubjects(release.Id, new List <Guid> { releaseFile.File.SubjectId.Value }), Times.Once); Assert.Equal(release.Id, result.Right.Id); Assert.Equal("Release Meta Guidance", result.Right.Content); Assert.Equal(SubjectMetaGuidance, result.Right.Subjects); } }
private static void AssertAmendedReleaseRoleCorrect(UserReleaseRole previous, UserReleaseRole amended, Release amendment) { Assert.NotEqual(previous.Id, amended.Id); Assert.Equal(amendment, amended.Release); Assert.Equal(amendment.Id, amended.ReleaseId); Assert.Equal(previous.UserId, amended.UserId); Assert.Equal(previous.Role, amended.Role); }
private void CreateGenericContentFromTemplate(Guid releaseId, Release newRelease) { var templateRelease = _context.Releases.AsNoTracking() .Include(r => r.Content) .ThenInclude(c => c.ContentSection) .First(r => r.Id == releaseId); templateRelease.CreateGenericContentFromTemplate(newRelease); }
public async Task <List <ReleaseChecklistIssue> > GetWarnings(Release release) { var warnings = new List <ReleaseChecklistIssue>(); var methodologies = await _methodologyVersionRepository.GetLatestVersionByPublication(release.PublicationId); if (!methodologies.Any()) { warnings.Add(new ReleaseChecklistIssue(ValidationErrorMessages.NoMethodology)); } var methodologiesNotApproved = methodologies .Where(m => m.Status != MethodologyStatus.Approved) .ToList(); if (methodologiesNotApproved.Any()) { warnings.AddRange(methodologiesNotApproved.Select(m => new MethodologyNotApprovedWarning(m.Id))); } if (release.NextReleaseDate == null) { warnings.Add(new ReleaseChecklistIssue(ValidationErrorMessages.NoNextReleaseDate)); } var dataFiles = await _fileRepository.ListDataFiles(release.Id); if (!dataFiles.Any()) { warnings.Add(new ReleaseChecklistIssue(ValidationErrorMessages.NoDataFiles)); } else { var subjectsWithNoFootnotes = await GetSubjectsWithNoFootnotes(release, dataFiles); if (subjectsWithNoFootnotes.Any()) { warnings.Add(new NoFootnotesOnSubjectsWarning(subjectsWithNoFootnotes.Count)); } var tableHighlights = await GetDataBlocksWithHighlights(release); if (!tableHighlights.Any()) { warnings.Add(new ReleaseChecklistIssue(ValidationErrorMessages.NoTableHighlights)); } } if (release.PreReleaseAccessList.IsNullOrEmpty()) { warnings.Add(new ReleaseChecklistIssue(ValidationErrorMessages.NoPublicPreReleaseAccessList)); } return(warnings); }
private async Task <List <DataBlockViewModel> > GetDataBlocksWithHighlights(Release release) { return((await _dataBlockService.List(release.Id)) .FoldRight( dataBlocks => dataBlocks .Where(dataBlock => !dataBlock.HighlightName.IsNullOrEmpty()) .ToList(), new List <DataBlockViewModel>() )); }
public async Task Update_NoSubjects() { var release = new Release { Id = Guid.NewGuid(), PreviousVersionId = null, MetaGuidance = "Release Meta Guidance" }; var contentDbContextId = Guid.NewGuid().ToString(); var statisticsDbContextId = Guid.NewGuid().ToString(); await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { await contentDbContext.AddAsync(release); await contentDbContext.SaveChangesAsync(); } var metaGuidanceSubjectService = new Mock <IMetaGuidanceSubjectService>(MockBehavior.Strict); metaGuidanceSubjectService.Setup(mock => mock.GetSubjects(release.Id, new List <Guid>())).ReturnsAsync(new List <MetaGuidanceSubjectViewModel>()); await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId)) { var service = SetupMetaGuidanceService(contentDbContext: contentDbContext, metaGuidanceSubjectService: metaGuidanceSubjectService.Object, statisticsDbContext: statisticsDbContext); var result = await service.Update( release.Id, new MetaGuidanceUpdateViewModel { Content = "Updated Release Meta Guidance", Subjects = new List <MetaGuidanceUpdateSubjectViewModel>() }); Assert.True(result.IsRight); metaGuidanceSubjectService.Verify(mock => mock.GetSubjects(release.Id, new List <Guid>()), Times.Once); Assert.Equal(release.Id, result.Right.Id); Assert.Equal("Updated Release Meta Guidance", result.Right.Content); Assert.Empty(result.Right.Subjects); } await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { Assert.Equal("Updated Release Meta Guidance", (await contentDbContext.Releases.FindAsync(release.Id)).MetaGuidance); } }
private async Task <List <Subject> > GetSubjectsWithNoFootnotes( Release release, IEnumerable <File> dataFiles) { var allowedSubjectIds = dataFiles .Where(dataFile => dataFile.SubjectId.HasValue) .Select(dataFile => dataFile.SubjectId.Value); return((await _footnoteRepository.GetSubjectsWithNoFootnotes(release.Id)) .Where(subject => allowedSubjectIds.Contains(subject.Id)) .ToList()); }
private static void AssertAmendedReleaseFileCorrect(ReleaseFile originalFile, ReleaseFile amendmentDataFile, Release amendment) { // assert it's a new link table entry between the Release amendment and the data file reference Assert.NotEqual(originalFile.Id, amendmentDataFile.Id); Assert.Equal(amendment, amendmentDataFile.Release); Assert.Equal(amendment.Id, amendmentDataFile.ReleaseId); // and assert that the file referenced is the SAME file reference as linked from the original Release's // link table entry Assert.Equal(originalFile.File.Id, amendmentDataFile.File.Id); }
public async Task GetChecklist_AllWarningsWithNoDataFiles() { var publication = new Publication(); var release = new Release { Publication = publication, }; var contextId = Guid.NewGuid().ToString(); await using (var context = ContentDbUtils.InMemoryContentDbContext(contextId)) { await context.AddRangeAsync(release); await context.SaveChangesAsync(); } await using (var context = ContentDbUtils.InMemoryContentDbContext(contextId)) { var fileRepository = new Mock <IFileRepository>(); fileRepository .Setup(r => r.ListDataFiles(release.Id)) .ReturnsAsync(new List <File>()); fileRepository .Setup(r => r.ListReplacementDataFiles(release.Id)) .ReturnsAsync(new List <File>()); var metaGuidanceService = new Mock <IMetaGuidanceService>(); metaGuidanceService .Setup(s => s.Validate(release.Id)) .ReturnsAsync(ValidationActionResult(PublicMetaGuidanceRequired)); var service = BuildReleaseChecklistService( context, fileRepository: fileRepository.Object, metaGuidanceService: metaGuidanceService.Object ); var checklist = await service.GetChecklist(release.Id); Assert.True(checklist.IsRight); Assert.False(checklist.Right.Valid); Assert.Equal(4, checklist.Right.Warnings.Count); Assert.Equal(NoMethodology, checklist.Right.Warnings[0].Code); Assert.Equal(NoNextReleaseDate, checklist.Right.Warnings[1].Code); Assert.Equal(NoDataFiles, checklist.Right.Warnings[2].Code); Assert.Equal(NoPublicPreReleaseAccessList, checklist.Right.Warnings[3].Code); } }
private async Task <Either <ActionResult, Release> > CopyFileLinks(Release originalRelease, Release newRelease) { var releaseFileCopies = _context .ReleaseFiles .Include(f => f.File) .Where(f => f.ReleaseId == originalRelease.Id) .Select(f => f.CreateReleaseAmendment(newRelease)).ToList(); await _context.ReleaseFiles.AddRangeAsync(releaseFileCopies); await _context.SaveChangesAsync(); return(newRelease); }
public async Task Validate_SubjectMetaGuidanceNotPopulated() { var release = new Release { MetaGuidance = "Release Meta Guidance" }; var releaseFile = new ReleaseFile { Release = release, File = new File { Filename = "file1.csv", Release = release, Type = FileType.Data, SubjectId = Guid.NewGuid() } }; var contentDbContextId = Guid.NewGuid().ToString(); await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { await contentDbContext.AddAsync(release); await contentDbContext.AddAsync(releaseFile); await contentDbContext.SaveChangesAsync(); } var metaGuidanceSubjectService = new Mock <IMetaGuidanceSubjectService>(MockBehavior.Strict); metaGuidanceSubjectService.Setup(mock => mock.Validate(release.Id)) .ReturnsAsync(false); await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId)) { var service = SetupMetaGuidanceService(contentDbContext: contentDbContext, metaGuidanceSubjectService: metaGuidanceSubjectService.Object); var result = await service.Validate(release.Id); Assert.True(result.IsLeft); metaGuidanceSubjectService.Verify(mock => mock.Validate(release.Id), Times.Once); ValidationTestUtil.AssertValidationProblem(result.Left, PublicMetaGuidanceRequired); } }
public async Task ListSubjects_FiltersSubjectsWithNoFileSubjectId() { var releaseId = Guid.NewGuid(); var release = new Release { Id = releaseId }; var releaseFile = new ReleaseFile { Release = release, File = new File { Filename = "data1.csv", Type = FileType.Data, } }; var import = new DataImport { File = releaseFile.File, Status = DataImportStatus.COMPLETE }; var contentDbContextId = Guid.NewGuid().ToString(); await using (var contentDbContext = InMemoryContentDbContext(contentDbContextId)) { await contentDbContext.AddAsync(release); await contentDbContext.AddRangeAsync(releaseFile); await contentDbContext.AddRangeAsync(import); await contentDbContext.SaveChangesAsync(); } await using (var contentDbContext = InMemoryContentDbContext(contentDbContextId)) { var service = BuildReleaseService(contentDbContext: contentDbContext); var result = await service.ListSubjects(release.Id); var subjects = result.AssertRight(); Assert.Empty(subjects); } }
private async Task <bool> HasDataFilesUploading(Release release) { var filters = TableQuery.CombineFilters( TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, release.Id.ToString()), TableOperators.And, TableQuery.GenerateFilterCondition("Status", QueryComparisons.NotEqual, IStatus.COMPLETE.ToString()) ); var query = new TableQuery <DatafileImport>().Where(filters); var cloudTable = await _tableStorageService.GetTableAsync(TableStorageTableNames.DatafileImportsTableName); var results = await cloudTable.ExecuteQuerySegmentedAsync(query, null); return(results.Results.Any()); }
private async Task <Release> HydrateReleaseForAmendment(Release release) { // Require publication / release / contact / graph to be able to work out: // If the release is the latest // The contact // TODO: EES-3164 Refactor using AsSplitQuery() await _context.Entry(release) .Reference(r => r.Publication) .LoadAsync(); await _context.Entry(release) .Collection(r => r.Content) .LoadAsync(); await release.Content .ToAsyncEnumerable() .ForEachAwaitAsync(async cs => { await _context.Entry(cs) .Reference(rcs => rcs.ContentSection) .LoadAsync(); await _context.Entry(cs.ContentSection) .Collection(s => s.Content) .LoadAsync(); }); await _context.Entry(release) .Collection(r => r.Updates) .LoadAsync(); await _context.Entry(release) .Collection(r => r.ContentBlocks) .LoadAsync(); await release.ContentBlocks .ToAsyncEnumerable() .ForEachAwaitAsync(async rcb => await _context.Entry(rcb) .Reference(cb => cb.ContentBlock) .LoadAsync() ); return(release); }
public async Task <List <ReleaseChecklistIssue> > GetWarnings(Release release) { var warnings = new List <ReleaseChecklistIssue>(); if (!release.Publication.MethodologyId.HasValue) { warnings.Add(new ReleaseChecklistIssue(ValidationErrorMessages.NoMethodology)); } if (release.NextReleaseDate == null) { warnings.Add(new ReleaseChecklistIssue(ValidationErrorMessages.NoNextReleaseDate)); } var dataFiles = await _fileRepository.ListDataFiles(release.Id); if (!dataFiles.Any()) { warnings.Add(new ReleaseChecklistIssue(ValidationErrorMessages.NoDataFiles)); } else { var subjectsWithNoFootnotes = await GetSubjectsWithNoFootnotes(release, dataFiles); if (subjectsWithNoFootnotes.Any()) { warnings.Add(new NoFootnotesOnSubjectsWarning(subjectsWithNoFootnotes.Count)); } var tableHighlights = await GetDataBlocksWithHighlights(release); if (!tableHighlights.Any()) { warnings.Add(new ReleaseChecklistIssue(ValidationErrorMessages.NoTableHighlights)); } } if (release.PreReleaseAccessList.IsNullOrEmpty()) { warnings.Add(new ReleaseChecklistIssue(ValidationErrorMessages.NoPublicPreReleaseAccessList)); } return(warnings); }
public async Task <List <ReleaseChecklistIssue> > GetErrors(Release release) { var errors = new List <ReleaseChecklistIssue>(); if (await _dataImportService.HasIncompleteImports(release.Id)) { errors.Add(new ReleaseChecklistIssue(ValidationErrorMessages.DataFileImportsMustBeCompleted)); } var replacementDataFiles = await _fileRepository.ListReplacementDataFiles(release.Id); if (replacementDataFiles.Any()) { errors.Add(new ReleaseChecklistIssue(ValidationErrorMessages.DataFileReplacementsMustBeCompleted)); } var isDataGuidanceValid = await _dataGuidanceService.Validate(release.Id); if (isDataGuidanceValid.IsLeft) { errors.Add(new ReleaseChecklistIssue(ValidationErrorMessages.PublicDataGuidanceRequired)); } if (release.Amendment && !release.Updates.Any(update => update.Created > release.Created)) { errors.Add(new ReleaseChecklistIssue(ValidationErrorMessages.ReleaseNoteRequired)); } if (await ReleaseHasEmptyGenericContentSection(release.Id)) { errors.Add(new ReleaseChecklistIssue(ValidationErrorMessages.EmptyContentSectionExists)); } if (await ReleaseGenericContentSectionsContainEmptyContentBlock(release.Id)) { errors.Add(new ReleaseChecklistIssue(ValidationErrorMessages.GenericSectionsContainEmptyHtmlBlock)); } return(errors); }
public async Task GetChecklist_NotFound() { var release = new Release(); var contextId = Guid.NewGuid().ToString(); await using (var context = InMemoryContentDbContext(contextId)) { await context.AddAsync(release); await context.SaveChangesAsync(); } await using (var context = InMemoryContentDbContext(contextId)) { var service = BuildReleaseChecklistService(context); var result = await service.GetChecklist(Guid.NewGuid()); result.AssertNotFound(); } }
public async Task GetChecklist_NotFound() { var release = new Release(); var contextId = Guid.NewGuid().ToString(); await using (var context = ContentDbUtils.InMemoryContentDbContext(contextId)) { await context.AddAsync(release); await context.SaveChangesAsync(); } await using (var context = ContentDbUtils.InMemoryContentDbContext(contextId)) { var service = BuildReleaseChecklistService(context); var checklist = await service.GetChecklist(Guid.NewGuid()); Assert.True(checklist.IsLeft); Assert.IsType <NotFoundResult>(checklist.Left); } }
public async Task CreateCacheKeyForFastTrackResults() { var fastTrackId = Guid.NewGuid(); var owningPublication = new Publication { Id = Guid.NewGuid(), Slug = "the-publication-slug" }; var owningRelease = new Release { Id = Guid.NewGuid(), Publication = owningPublication, Slug = "the-release-slug" }; await using var contentDbContext = InMemoryContentDbContext(); await contentDbContext.Releases.AddAsync(owningRelease); await contentDbContext.SaveChangesAsync(); var(service, fastTrackService) = BuildServiceAndMocks(contentDbContext, null); fastTrackService .Setup(s => s.GetReleaseFastTrack(fastTrackId)) .ReturnsAsync(new ReleaseFastTrack(owningRelease.Id, fastTrackId, "")); var result = await service.CreateCacheKeyForFastTrackResults(fastTrackId); VerifyAllMocks(fastTrackService); var cacheKey = result.AssertRight(); Assert.Equal(BlobContainers.PublicContent, cacheKey.Container); var expectedCacheKeyPath = $"publications/{owningPublication.Slug}/releases/{owningRelease.Slug}/fast-track-results/{fastTrackId}.json"; Assert.Equal(expectedCacheKeyPath, cacheKey.Key); }
private static void AssertAmendedContentSectionCorrect(Release amendment, ReleaseContentSection amended, ReleaseContentSection previous) { Assert.Equal(amendment, amended.Release); Assert.Equal(amendment.Id, amended.ReleaseId); Assert.True(amended.ContentSectionId != Guid.Empty); Assert.NotEqual(previous.ContentSectionId, amended.ContentSectionId); var previousSection = previous.ContentSection; var amendedSection = amended.ContentSection; Assert.NotEqual(previousSection.Id, amendedSection.Id); Assert.Equal(previousSection.Caption, amendedSection.Caption); Assert.Equal(previousSection.Heading, amendedSection.Heading); Assert.Equal(previousSection.Order, amendedSection.Order); Assert.Equal(previousSection.Type, amendedSection.Type); Assert.Equal(previousSection.Content.Count, amendedSection.Content.Count); amendedSection.Content.ForEach(amendedBlock => { var previousBlock = previousSection.Content.Find(b => b.Order == amendedBlock.Order); AssertAmendedContentBlockCorrect(previousBlock, amendedBlock, amendedSection); }); }
public async Task <List <ReleaseChecklistIssue> > GetErrors(Release release) { var errors = new List <ReleaseChecklistIssue>(); if (await HasDataFilesUploading(release)) { errors.Add(new ReleaseChecklistIssue(ValidationErrorMessages.DataFileImportsMustBeCompleted)); } var replacementDataFiles = await _fileRepository.ListReplacementDataFiles(release.Id); if (replacementDataFiles.Any()) { errors.Add(new ReleaseChecklistIssue(ValidationErrorMessages.DataFileReplacementsMustBeCompleted)); } if (release.Publication.Methodology != null && release.Publication.Methodology.Status != MethodologyStatus.Approved) { errors.Add(new MethodologyMustBeApprovedError(release.Publication.Methodology.Id)); } var isMetaGuidanceValid = await _metaGuidanceService.Validate(release.Id); if (isMetaGuidanceValid.IsLeft) { errors.Add(new ReleaseChecklistIssue(ValidationErrorMessages.PublicMetaGuidanceRequired)); } if (release.Amendment && release.Updates.All(update => update.ReleaseId != release.Id)) { errors.Add(new ReleaseChecklistIssue(ValidationErrorMessages.ReleaseNoteRequired)); } return(errors); }
public async Task GetChecklist_AllErrors() { var publication = new Publication { Methodology = new Methodology() }; var originalRelease = new Release { Publication = publication, Version = 0 }; var release = new Release { Publication = publication, PreviousVersion = originalRelease, Version = 1, }; var contextId = Guid.NewGuid().ToString(); await using (var context = ContentDbUtils.InMemoryContentDbContext(contextId)) { await context.AddRangeAsync(release, originalRelease); await context.SaveChangesAsync(); } await using (var context = ContentDbUtils.InMemoryContentDbContext(contextId)) { var fileRepository = new Mock <IFileRepository>(); fileRepository .Setup(r => r.ListDataFiles(release.Id)) .ReturnsAsync(new List <File>()); fileRepository .Setup(r => r.ListReplacementDataFiles(release.Id)) .ReturnsAsync( new List <File> { new File() } ); var metaGuidanceService = new Mock <IMetaGuidanceService>(); metaGuidanceService .Setup(s => s.Validate(release.Id)) .ReturnsAsync(ValidationActionResult(PublicMetaGuidanceRequired)); var tableStorageService = MockTableStorageService( new List <DatafileImport> { new DatafileImport() } ); var service = BuildReleaseChecklistService( context, fileRepository: fileRepository.Object, metaGuidanceService: metaGuidanceService.Object, tableStorageService: tableStorageService.Object ); var checklist = await service.GetChecklist(release.Id); Assert.True(checklist.IsRight); Assert.False(checklist.Right.Valid); Assert.Equal(5, checklist.Right.Errors.Count); Assert.Equal(DataFileImportsMustBeCompleted, checklist.Right.Errors[0].Code); Assert.Equal(DataFileReplacementsMustBeCompleted, checklist.Right.Errors[1].Code); var methodologyMustBeApprovedError = Assert.IsType <MethodologyMustBeApprovedError>(checklist.Right.Errors[2]); Assert.Equal(MethodologyMustBeApproved, methodologyMustBeApprovedError.Code); Assert.Equal(publication.MethodologyId, methodologyMustBeApprovedError.MethodologyId); Assert.Equal(PublicMetaGuidanceRequired, checklist.Right.Errors[3].Code); Assert.Equal(ReleaseNoteRequired, checklist.Right.Errors[4].Code); } }
private async Task <Either <ActionResult, Unit> > ValidateReleaseWithChecklist(Release release) { if (release.Status != ReleaseStatus.Approved) { return(Unit.Instance); } var errors = (await _releaseChecklistService.GetErrors(release)) .Select(error => error.Code) .ToList(); if (!errors.Any()) { return(Unit.Instance); } return(ValidationActionResult(errors)); }
public async Task GetChecklist_AllWarningsWithDataFiles() { var publication = new Publication(); var release = new Release { Publication = publication, }; var contextId = Guid.NewGuid().ToString(); await using (var context = ContentDbUtils.InMemoryContentDbContext(contextId)) { await context.AddRangeAsync(release); await context.SaveChangesAsync(); } await using (var context = ContentDbUtils.InMemoryContentDbContext(contextId)) { var subject = new Subject { Id = Guid.NewGuid() }; var otherSubject = new Subject { Id = Guid.NewGuid(), }; var fileRepository = new Mock <IFileRepository>(); fileRepository .Setup(r => r.ListDataFiles(release.Id)) .ReturnsAsync( new List <File> { new File { Id = Guid.NewGuid(), Filename = "test-file-1.csv", Type = FileType.Data, Release = release, ReleaseId = release.Id, SubjectId = subject.Id }, new File { Id = Guid.NewGuid(), Filename = "test-file-2.csv", Type = FileType.Data, Release = release, ReleaseId = release.Id, SubjectId = otherSubject.Id } } ); var metaGuidanceService = new Mock <IMetaGuidanceService>(); metaGuidanceService .Setup(s => s.Validate(release.Id)) .ReturnsAsync(ValidationActionResult(PublicMetaGuidanceRequired)); var footnoteRepository = new Mock <IFootnoteRepository>(); footnoteRepository .Setup(r => r.GetSubjectsWithNoFootnotes(release.Id)) .ReturnsAsync( new List <Subject> { subject, } ); fileRepository .Setup(r => r.ListReplacementDataFiles(release.Id)) .ReturnsAsync(new List <File>()); var dataBlockService = new Mock <IDataBlockService>(); dataBlockService .Setup(s => s.List(release.Id)) .ReturnsAsync( new List <DataBlockViewModel> { new DataBlockViewModel(), new DataBlockViewModel(), } ); var service = BuildReleaseChecklistService( context, fileRepository: fileRepository.Object, metaGuidanceService: metaGuidanceService.Object, footnoteRepository: footnoteRepository.Object, dataBlockService: dataBlockService.Object ); var checklist = await service.GetChecklist(release.Id); Assert.True(checklist.IsRight); Assert.False(checklist.Right.Valid); Assert.Equal(5, checklist.Right.Warnings.Count); Assert.Equal(NoMethodology, checklist.Right.Warnings[0].Code); Assert.Equal(NoNextReleaseDate, checklist.Right.Warnings[1].Code); var noFootnotesWarning = Assert.IsType <NoFootnotesOnSubjectsWarning>(checklist.Right.Warnings[2]); Assert.Equal(NoFootnotesOnSubjects, noFootnotesWarning.Code); Assert.Equal(1, noFootnotesWarning.TotalSubjects); Assert.Equal(NoTableHighlights, checklist.Right.Warnings[3].Code); Assert.Equal(NoPublicPreReleaseAccessList, checklist.Right.Warnings[4].Code); } }
private async Task <Either <ActionResult, Release> > CreateBasicReleaseAmendment(Release release) { var amendment = release.CreateReleaseAmendment(DateTime.UtcNow, _userService.GetUserId()); await _context.Releases.AddAsync(amendment); await _context.SaveChangesAsync(); return(amendment); }
private async Task <Either <ActionResult, Release> > CopyReleaseTeam(Guid originalReleaseId, Release amendment) { var newRoles = _context .UserReleaseRoles .Where(r => r.ReleaseId == originalReleaseId) .Select(r => r.CreateReleaseAmendment(amendment)); await _context.AddRangeAsync(newRoles); await _context.SaveChangesAsync(); return(amendment); }
private async Task <Either <ActionResult, Release> > CreateStatisticsReleaseAmendment(Release amendment) { var statsRelease = _statisticsDbContext .Release .FirstOrDefault(r => r.Id == amendment.PreviousVersionId); // Release does not have to have stats uploaded but if it has then // create a link row to link back to the original subject if (statsRelease != null) { var statsAmendment = statsRelease.CreateReleaseAmendment(amendment.Id, amendment.PreviousVersionId); var statsAmendmentSubjectLinks = _statisticsDbContext .ReleaseSubject .Where(rs => rs.ReleaseId == amendment.PreviousVersionId) .Select(rs => rs.CopyForRelease(statsAmendment)); await _statisticsDbContext.Release.AddAsync(statsAmendment); await _statisticsDbContext.ReleaseSubject.AddRangeAsync(statsAmendmentSubjectLinks); await _statisticsDbContext.SaveChangesAsync(); } return(amendment); }
public async Task GetChecklist_FullyValid() { var publication = new Publication { Methodology = new Methodology { Status = MethodologyStatus.Approved } }; var originalRelease = new Release { Publication = publication, Version = 0 }; var release = new Release { Publication = publication, PreviousVersion = originalRelease, Version = 1, MetaGuidance = "Test meta guidance", PreReleaseAccessList = "Test access list", NextReleaseDate = new PartialDate { Month = "12", Year = "2021" }, Updates = new List <Update> { new Update { Reason = "Test reason 1", Release = originalRelease }, new Update { Reason = "Test reason 2" } }, }; var contextId = Guid.NewGuid().ToString(); await using (var context = ContentDbUtils.InMemoryContentDbContext(contextId)) { await context.AddRangeAsync(release, originalRelease); await context.SaveChangesAsync(); } await using (var context = ContentDbUtils.InMemoryContentDbContext(contextId)) { var subject = new Subject { Id = Guid.NewGuid() }; var fileRepository = new Mock <IFileRepository>(); fileRepository .Setup(r => r.ListDataFiles(release.Id)) .ReturnsAsync( new List <File> { new File { Id = Guid.NewGuid(), Filename = "test-file-1.csv", Type = FileType.Data, Release = release, ReleaseId = release.Id, SubjectId = subject.Id, }, } ); fileRepository .Setup(r => r.ListReplacementDataFiles(release.Id)) .ReturnsAsync(new List <File>()); var metaGuidanceService = new Mock <IMetaGuidanceService>(); metaGuidanceService .Setup(s => s.Validate(release.Id)) .ReturnsAsync(Unit.Instance); var footnoteRepository = new Mock <IFootnoteRepository>(); footnoteRepository .Setup(r => r.GetSubjectsWithNoFootnotes(release.Id)) .ReturnsAsync(new List <Subject>()); var dataBlockService = new Mock <IDataBlockService>(); dataBlockService .Setup(s => s.List(release.Id)) .ReturnsAsync( new List <DataBlockViewModel> { new DataBlockViewModel { HighlightName = "Test highlight name" }, } ); var service = BuildReleaseChecklistService( context, metaGuidanceService: metaGuidanceService.Object, fileRepository: fileRepository.Object, footnoteRepository: footnoteRepository.Object, dataBlockService: dataBlockService.Object ); var checklist = await service.GetChecklist(release.Id); Assert.True(checklist.IsRight); Assert.Empty(checklist.Right.Errors); Assert.Empty(checklist.Right.Warnings); Assert.True(checklist.Right.Valid); } }
private async Task <Either <ActionResult, Release> > CopyReleaseRolePermissions(Guid originalReleaseId, Release amendment) { var newRoles = _context .UserReleaseRoles .AsQueryable() .IgnoreQueryFilters() // For auditing purposes, we also want to migrate release roles that have Deleted set .Where(releaseRole => !releaseRole.SoftDeleted && releaseRole.ReleaseId == originalReleaseId) .Select(releaseRole => releaseRole.CopyForAmendment(amendment)); await _context.AddRangeAsync(newRoles); await _context.SaveChangesAsync(); return(amendment); }