Exemple #1
0
        public async Task Query_ReleaseId_SubjectNotFound()
        {
            var releaseSubject = new ReleaseSubject
            {
                Release = new Release(),
                Subject = new Subject(),
            };

            var query = new ObservationQueryContext
            {
                SubjectId = Guid.NewGuid(),
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var statisticsDbContext = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                await statisticsDbContext.AddAsync(releaseSubject);

                await statisticsDbContext.SaveChangesAsync();
            }

            await using (var statisticsDbContext = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                var service = BuildTableBuilderService(statisticsDbContext);

                var result = await service.Query(Guid.NewGuid(), query);

                Assert.True(result.IsLeft);
                Assert.IsType <NotFoundResult>(result.Left);
            }
        }
Exemple #2
0
        public async Task GetPublicationIdForSubject()
        {
            var releaseSubject = new ReleaseSubject
            {
                Release = new Release
                {
                    PublicationId = Guid.NewGuid(),
                },
                Subject = new Subject()
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var context = InMemoryStatisticsDbContext(contextId))
            {
                await context.AddAsync(releaseSubject);

                await context.SaveChangesAsync();
            }

            await using (var context = InMemoryStatisticsDbContext(contextId))
            {
                var service = BuildSubjectService(context);
                var result  = await service.GetPublicationIdForSubject(releaseSubject.SubjectId);

                Assert.Equal(releaseSubject.Release.PublicationId, result);
            }
        }
Exemple #3
0
        private async Task <DataGuidanceSubjectViewModel> BuildSubjectViewModel(ReleaseSubject releaseSubject)
        {
            var subject = releaseSubject.Subject;

            var releaseFile =
                await _releaseDataFileRepository.GetBySubject(
                    releaseSubject.ReleaseId,
                    releaseSubject.SubjectId);

            var geographicLevels = await GetGeographicLevels(subject.Id);

            var timePeriods = _timePeriodService.GetTimePeriodLabels(subject.Id);
            var variables   = GetVariables(subject.Id);
            var footnotes   = GetFootnotes(releaseSubject.ReleaseId, subject.Id);

            return(new DataGuidanceSubjectViewModel
            {
                Id = subject.Id,
                Content = releaseSubject.DataGuidance ?? "",
                Filename = releaseFile.File.Filename,
                Name = releaseFile.Name ?? "",
                GeographicLevels = geographicLevels,
                TimePeriods = timePeriods,
                Variables = variables,
                Footnotes = footnotes
            });
        }
        public async Task DeleteReleaseSubject_SoftDeleteOrphanedSubject()
        {
            var releaseSubject = new ReleaseSubject
            {
                Release = new Release(),
                Subject = new Subject(),
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var statisticsDbContext = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                await statisticsDbContext.AddAsync(releaseSubject);

                await statisticsDbContext.SaveChangesAsync();
            }

            await using (var statisticsDbContext = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                var service = BuildReleaseSubjectService(statisticsDbContext);
                await service.DeleteReleaseSubject(releaseSubject.ReleaseId, releaseSubject.SubjectId, true);
            }

            await using (var statisticsDbContext = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                Assert.Empty(statisticsDbContext.ReleaseSubject.ToList());

                var subjects = statisticsDbContext.Subject.IgnoreQueryFilters().ToList();
                Assert.Single(subjects);
                Assert.Equal(releaseSubject.Subject.Id, subjects[0].Id);
                Assert.True(subjects[0].SoftDeleted);
            }
        }
        public async Task FindPublicationForSubject()
        {
            var releaseSubject = new ReleaseSubject
            {
                Release = new Release
                {
                    Publication = new Publication
                    {
                        Title = "Test publication"
                    },
                },
                Subject = new Subject
                {
                    Name = "Test subject"
                }
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var context = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                await context.AddAsync(releaseSubject);

                await context.SaveChangesAsync();
            }

            await using (var context = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                var service = BuildSubjectService(context);
                var result  = await service.FindPublicationForSubject(releaseSubject.SubjectId);

                Assert.Equal(releaseSubject.Release.PublicationId, result.Id);
                Assert.Equal("Test publication", result.Title);
            }
        }
Exemple #6
0
        public async Task GetGeographicLevels_NoObservations()
        {
            var release = new Release();

            var subject = new Subject();

            var releaseSubject = new ReleaseSubject
            {
                Release      = release,
                Subject      = subject,
                DataGuidance = "Subject 1 Guidance"
            };

            var statisticsDbContextId = Guid.NewGuid().ToString();

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                await statisticsDbContext.AddAsync(release);

                await statisticsDbContext.AddAsync(subject);

                await statisticsDbContext.AddAsync(releaseSubject);

                await statisticsDbContext.SaveChangesAsync();
            }

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                var service = SetupService(statisticsDbContext: statisticsDbContext);

                var result = await service.GetGeographicLevels(subject.Id);

                Assert.Empty(result);
            }
        }
        public async Task Get_WithReleaseAndSubjectName_SubjectNameNotFound()
        {
            var releaseSubject = new ReleaseSubject
            {
                Release = new Release(),
                Subject = new Subject
                {
                    Name = "Test subject"
                }
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var context = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                await context.AddAsync(releaseSubject);

                await context.SaveChangesAsync();
            }

            await using (var context = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                var service = BuildSubjectService(context);
                var result  = await service.Get(releaseSubject.ReleaseId, "Not the subject");

                Assert.Null(result);
            }
        }
        public async Task IsSubjectForLatestPublishedRelease()
        {
            var releaseSubject = new ReleaseSubject
            {
                Release = new Release
                {
                    Publication = new Publication(),
                    Published   = DateTime.UtcNow
                },
                Subject = new Subject()
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var context = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                await context.AddAsync(releaseSubject);

                await context.SaveChangesAsync();
            }

            await using (var context = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                var releaseService = new Mock <IReleaseService>();

                releaseService
                .Setup(s => s.GetLatestPublishedRelease(releaseSubject.Release.PublicationId))
                .Returns(releaseSubject.Release);

                var service = BuildSubjectService(context, releaseService: releaseService.Object);
                var result  = await service.IsSubjectForLatestPublishedRelease(releaseSubject.SubjectId);

                Assert.True(result);
            }
        }
        public async Task DeleteAllReleaseSubjects()
        {
            var release = new Release();

            var releaseSubject1 = new ReleaseSubject
            {
                Release = release,
                Subject = new Subject(),
            };

            var releaseSubject2 = new ReleaseSubject
            {
                Release = release,
                Subject = new Subject(),
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var statisticsDbContext = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                await statisticsDbContext.AddRangeAsync(releaseSubject1, releaseSubject2);

                await statisticsDbContext.SaveChangesAsync();
            }

            await using (var statisticsDbContext = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                var subjectDeleter = new Mock <ReleaseSubjectRepository.SubjectDeleter>();

                subjectDeleter
                .Setup(
                    s =>
                    s.Delete(
                        It.Is <Subject>(subject => subject.Id == releaseSubject1.SubjectId),
                        It.IsAny <StatisticsDbContext>()
                        )
                    );
                subjectDeleter
                .Setup(
                    s => s.Delete(
                        It.Is <Subject>(subject => subject.Id == releaseSubject2.SubjectId),
                        It.IsAny <StatisticsDbContext>()
                        )
                    );

                var service = BuildReleaseSubjectService(statisticsDbContext, subjectDeleter: subjectDeleter.Object);
                await service.DeleteAllReleaseSubjects(release.Id);

                MockUtils.VerifyAllMocks(subjectDeleter);
            }

            await using (var statisticsDbContext = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                Assert.Empty(statisticsDbContext.ReleaseSubject.ToList());
            }
        }
Exemple #10
0
        public void GetSubjectMeta_EmptyModelReturnedForSubject()
        {
            var builder = new DbContextOptionsBuilder <StatisticsDbContext>();

            builder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            var options = builder.Options;

            using (var context = new StatisticsDbContext(options, null))
            {
                var release = new Release
                {
                    Id = Guid.NewGuid(),
                };

                var subject = new Subject
                {
                    Id = Guid.NewGuid()
                };

                var releaseSubjectLink = new ReleaseSubject
                {
                    ReleaseId = release.Id,
                    SubjectId = subject.Id
                };

                context.Add(release);
                context.Add(subject);
                context.Add(releaseSubjectLink);

                context.SaveChanges();

                var(boundaryLevelService, filterService, filterItemService, geoJsonService, indicatorGroupService, locationService, observationService, timePeriodService, userService) = Mocks();

                filterService.Setup(s => s.GetFiltersIncludingItems(subject.Id)).Returns(Enumerable.Empty <Filter>());
                indicatorGroupService.Setup(s => s.GetIndicatorGroups(subject.Id)).Returns(Enumerable.Empty <IndicatorGroup>());
                locationService.Setup(s => s.GetObservationalUnits(subject.Id)).Returns(new Dictionary <GeographicLevel, IEnumerable <IObservationalUnit> >());
                timePeriodService.Setup(s => s.GetTimePeriods(subject.Id)).Returns(Enumerable.Empty <(int Year, TimeIdentifier TimeIdentifier)>());

                var service = new SubjectMetaService(boundaryLevelService.Object,
                                                     filterService.Object,
                                                     filterItemService.Object,
                                                     geoJsonService.Object,
                                                     indicatorGroupService.Object,
                                                     locationService.Object,
                                                     new Mock <ILogger <SubjectMetaService> >().Object,
                                                     MapperUtils.MapperForProfile <DataServiceMappingProfiles>(),
                                                     observationService.Object,
                                                     new PersistenceHelper <StatisticsDbContext>(context),
                                                     timePeriodService.Object,
                                                     userService.Object);

                var result = service.GetSubjectMeta(subject.Id);
                Assert.True(result.Result.IsRight);
                Assert.IsAssignableFrom <SubjectMetaViewModel>(result.Result.Right);
            }
        }
Exemple #11
0
        public void GetSubjectMeta_SubjectNoAccess()
        {
            var builder = new DbContextOptionsBuilder <StatisticsDbContext>();

            builder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            var options = builder.Options;

            using (var context = new StatisticsDbContext(options, null))
            {
                var release = new Release
                {
                    Id = Guid.NewGuid(),
                };

                var subject = new Subject
                {
                    Id = Guid.NewGuid()
                };

                var releaseSubjectLink = new ReleaseSubject
                {
                    ReleaseId = release.Id,
                    SubjectId = subject.Id
                };

                context.Add(release);
                context.Add(subject);
                context.Add(releaseSubjectLink);

                context.SaveChanges();

                var(boundaryLevelService, filterService, filterItemService, geoJsonService, indicatorGroupService, locationService, observationService, timePeriodService, userService) = Mocks();

                userService.Setup(s => s.MatchesPolicy(release, CanViewSubjectData)).ReturnsAsync(false);

                var service = new SubjectMetaService(boundaryLevelService.Object,
                                                     filterService.Object,
                                                     filterItemService.Object,
                                                     geoJsonService.Object,
                                                     indicatorGroupService.Object,
                                                     locationService.Object,
                                                     new Mock <ILogger <SubjectMetaService> >().Object,
                                                     MapperUtils.MapperForProfile <DataServiceMappingProfiles>(),
                                                     observationService.Object,
                                                     new PersistenceHelper <StatisticsDbContext>(context),
                                                     timePeriodService.Object,
                                                     userService.Object);

                var result = service.GetSubjectMetaRestricted(subject.Id);
                Assert.True(result.Result.IsLeft);
                Assert.IsAssignableFrom <ForbidResult>(result.Result.Left);
            }
        }
        public async Task Validate_MetaGuidanceNotPopulated()
        {
            var release = new Release();

            var releaseSubject1 = new ReleaseSubject
            {
                MetaGuidance = "Subject 1 Meta Guidance",
                Release      = release,
                Subject      = new Subject
                {
                    Filename = "file1.csv",
                    Name     = "Subject 1"
                }
            };

            // Meta guidance is not populated for Subject 2
            var releaseSubject2 = new ReleaseSubject
            {
                MetaGuidance = null,
                Release      = release,
                Subject      = new Subject
                {
                    Filename = "file2.csv",
                    Name     = "Subject 2",
                }
            };

            var statisticsDbContextId = Guid.NewGuid().ToString();

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                await statisticsDbContext.AddAsync(release);

                await statisticsDbContext.AddRangeAsync(releaseSubject1, releaseSubject2);

                await statisticsDbContext.SaveChangesAsync();
            }

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                var service = SetupMetaGuidanceSubjectService(context: statisticsDbContext);

                var result = await service.Validate(release.Id);

                Assert.True(result.IsRight);
                Assert.False(result.Right);
            }
        }
        private async Task <MetaGuidanceSubjectViewModel> BuildSubjectViewModel(ReleaseSubject releaseSubject)
        {
            var subject          = releaseSubject.Subject;
            var geographicLevels = await GetGeographicLevels(subject.Id);

            var timePeriods = await GetTimePeriods(subject.Id);

            var variables = GetVariables(subject.Id);

            return(new MetaGuidanceSubjectViewModel
            {
                Id = subject.Id,
                Content = releaseSubject.MetaGuidance ?? "",
                Filename = subject.Filename ?? "Unknown",
                Name = subject.Name,
                GeographicLevels = geographicLevels,
                TimePeriods = timePeriods,
                Variables = variables
            });
        }
        public async Task DeleteReleaseSubject_NonOrphanedSubject()
        {
            var subject = new Subject();

            var releaseSubject1 = new ReleaseSubject
            {
                Release = new Release(),
                Subject = subject,
            };
            var releaseSubject2 = new ReleaseSubject
            {
                Release = new Release(),
                Subject = subject
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var statisticsDbContext = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                await statisticsDbContext.AddRangeAsync(releaseSubject1, releaseSubject2);

                await statisticsDbContext.SaveChangesAsync();
            }

            await using (var statisticsDbContext = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                var service = BuildReleaseSubjectService(statisticsDbContext);
                await service.DeleteReleaseSubject(releaseSubject2.ReleaseId, releaseSubject2.SubjectId);
            }

            await using (var statisticsDbContext = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                var releaseSubjects = statisticsDbContext.ReleaseSubject.ToList();
                Assert.Single(releaseSubjects);
                Assert.Equal(subject.Id, releaseSubjects[0].SubjectId);

                var subjects = statisticsDbContext.Subject.ToList();
                Assert.Single(subjects);
                Assert.Equal(subject.Id, subjects[0].Id);
            }
        }
Exemple #15
0
        public void Query_ReleaseId_CanViewSubjectData()
        {
            PermissionTestUtils.PolicyCheckBuilder <DataSecurityPolicies>()
            .ExpectResourceCheckToFail(_subject, DataSecurityPolicies.CanViewSubjectData)
            .AssertForbidden(
                async userService =>
            {
                var releaseSubject = new ReleaseSubject
                {
                    ReleaseId = _release.Id,
                    Release   = _release,
                    SubjectId = _subject.Id,
                    Subject   = _subject,
                };

                var statisticsPersistenceHelper = StatisticsPersistenceHelperMock(_subject);

                MockUtils.SetupCall(statisticsPersistenceHelper, releaseSubject);

                var subjectService = new Mock <ISubjectService>();

                subjectService
                .Setup(s => s.IsSubjectForLatestPublishedRelease(_subject.Id))
                .ReturnsAsync(false);

                var service = BuildTableBuilderService(
                    userService: userService.Object,
                    subjectService: subjectService.Object,
                    statisticsPersistenceHelper: statisticsPersistenceHelper.Object
                    );
                return(await service.Query(
                           releaseSubject.ReleaseId,
                           new ObservationQueryContext
                {
                    SubjectId = _subject.Id
                }
                           ));
            }
                );
        }
Exemple #16
0
        public async Task Validate_DataGuidancePopulated()
        {
            var release = new Release();

            var releaseSubject1 = new ReleaseSubject
            {
                DataGuidance = "Subject 1 Guidance",
                Release      = release,
                Subject      = new Subject()
            };

            var releaseSubject2 = new ReleaseSubject
            {
                DataGuidance = "Subject 2 Guidance",
                Release      = release,
                Subject      = new Subject()
            };

            var statisticsDbContextId = Guid.NewGuid().ToString();

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                await statisticsDbContext.AddAsync(release);

                await statisticsDbContext.AddRangeAsync(releaseSubject1, releaseSubject2);

                await statisticsDbContext.SaveChangesAsync();
            }

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                var service = SetupService(statisticsDbContext: statisticsDbContext);

                var result = await service.Validate(release.Id);

                Assert.True(result.IsRight);
                Assert.True(result.Right);
            }
        }
Exemple #17
0
        public async Task IsSubjectForLatestPublishedRelease_SubjectBelongsToNonLiveRelease()
        {
            var releaseSubject = new ReleaseSubject
            {
                Release = new Release
                {
                    PublicationId = Guid.NewGuid(),
                    Published     = null
                },
                Subject = new Subject()
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var context = InMemoryStatisticsDbContext(contextId))
            {
                await context.AddAsync(releaseSubject);

                await context.SaveChangesAsync();
            }

            await using (var context = InMemoryStatisticsDbContext(contextId))
            {
                var releaseRepository = new Mock <IReleaseRepository>();

                releaseRepository
                .Setup(s => s.GetLatestPublishedRelease(releaseSubject.Release.PublicationId))
                .Returns(new Release
                {
                    Id = Guid.NewGuid()
                });

                var service = BuildSubjectService(context, releaseRepository: releaseRepository.Object);
                var result  = await service.IsSubjectForLatestPublishedRelease(releaseSubject.SubjectId);

                Assert.False(result);
            }
        }
        public async Task DeleteReleaseSubject_NotFound()
        {
            var releaseSubject = new ReleaseSubject
            {
                Release = new Release(),
                Subject = new Subject(),
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var statisticsDbContext = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                await statisticsDbContext.AddAsync(releaseSubject);

                await statisticsDbContext.SaveChangesAsync();
            }

            await using (var statisticsDbContext = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                var service = BuildReleaseSubjectService(statisticsDbContext);
                // Try to delete non-existing ReleaseSubject
                await service.DeleteReleaseSubject(Guid.NewGuid(), Guid.NewGuid());
            }

            await using (var statisticsDbContext = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                // Check that other ReleaseSubject has not been deleted
                var releaseSubjects = statisticsDbContext.ReleaseSubject.ToList();
                Assert.Single(releaseSubjects);
                Assert.Equal(releaseSubject.SubjectId, releaseSubjects[0].SubjectId);

                var subjects = statisticsDbContext.Subject.ToList();
                Assert.Single(subjects);
                Assert.Equal(releaseSubject.SubjectId, subjects[0].Id);
            }
        }
Exemple #19
0
        public async Task GetTimePeriodLabels_NoObservations()
        {
            var release = new Release();

            var subject = new Subject();

            var releaseSubject1 = new ReleaseSubject
            {
                Release      = release,
                Subject      = subject,
                DataGuidance = "Subject 1 Guidance"
            };

            var statisticsDbContextId = Guid.NewGuid().ToString();

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                await statisticsDbContext.AddAsync(release);

                await statisticsDbContext.AddAsync(subject);

                await statisticsDbContext.AddAsync(releaseSubject1);

                await statisticsDbContext.SaveChangesAsync();
            }

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                var service = new TimePeriodService(statisticsDbContext);

                var result = service.GetTimePeriodLabels(subject.Id);

                Assert.Empty(result.From);
                Assert.Empty(result.To);
            }
        }
Exemple #20
0
        public async Task GetFootnotes_FiltersByRelease()
        {
            var release      = new Release();
            var otherRelease = new Release();

            var releaseSubject1 = new ReleaseSubject
            {
                Release = release,
                Subject = new Subject()
            };

            var releaseSubject2 = new ReleaseSubject
            {
                Release = release,
                Subject = new Subject()
            };

            var footnote1 = new Footnote
            {
                Content  = "Test footnote 1",
                Releases = new List <ReleaseFootnote>
                {
                    new ReleaseFootnote
                    {
                        Release = release
                    },
                    // Check that footnote is still fetched
                    // even if it also linked to another release
                    new ReleaseFootnote
                    {
                        Release = otherRelease
                    }
                },
                Subjects = new List <SubjectFootnote>
                {
                    new SubjectFootnote
                    {
                        Subject = releaseSubject1.Subject
                    }
                },
            };

            var footnote2 = new Footnote
            {
                Content  = "Test footnote 2",
                Releases = new List <ReleaseFootnote>
                {
                    new ReleaseFootnote
                    {
                        Release = release
                    },
                },
                Subjects = new List <SubjectFootnote>
                {
                    new SubjectFootnote
                    {
                        Subject = releaseSubject2.Subject
                    }
                },
            };

            var footnoteForOtherRelease = new Footnote
            {
                Content  = "Test footnote for other release",
                Releases = new List <ReleaseFootnote>
                {
                    new ReleaseFootnote
                    {
                        Release = new Release()
                    },
                },
                Subjects = new List <SubjectFootnote>
                {
                    new SubjectFootnote
                    {
                        Subject = new Subject()
                    }
                },
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var context = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                await context.AddAsync(release);

                await context.AddRangeAsync(releaseSubject1, releaseSubject2);

                await context.AddRangeAsync(footnote1, footnote2, footnoteForOtherRelease);

                await context.SaveChangesAsync();
            }

            await using (var context = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                var repository = BuildFootnoteRepository(context);
                var results    = repository.GetFootnotes(release.Id).ToList();

                Assert.Equal(2, results.Count);

                Assert.Equal("Test footnote 1", results[0].Content);

                var footnote1Releases = results[0].Releases.ToList();

                Assert.Single(footnote1Releases);
                Assert.Equal(release.Id, footnote1Releases[0].ReleaseId);

                var footnote1Subjects = results[0].Subjects.ToList();

                Assert.Single(footnote1Subjects);
                Assert.Equal(releaseSubject1.SubjectId, footnote1Subjects[0].SubjectId);

                Assert.Equal("Test footnote 2", results[1].Content);

                var footnote2Releases = results[1].Releases.ToList();

                Assert.Single(footnote2Releases);
                Assert.Equal(release.Id, footnote2Releases[0].ReleaseId);

                var footnote2Subjects = results[1].Subjects.ToList();
                Assert.Single(footnote2Subjects);
                Assert.Equal(releaseSubject2.SubjectId, footnote2Subjects[0].SubjectId);
            }
        }
Exemple #21
0
        public async Task Get_SpecificSubjects()
        {
            var release = new Release();

            var releaseSubject1 = new ReleaseSubject
            {
                Release      = release,
                Subject      = new Subject(),
                DataGuidance = "Subject 1 Guidance"
            };

            var releaseSubject2 = new ReleaseSubject
            {
                Release      = release,
                Subject      = new Subject(),
                DataGuidance = "Subject 2 Guidance"
            };

            var releaseSubject3 = new ReleaseSubject
            {
                Release      = release,
                Subject      = new Subject(),
                DataGuidance = "Subject 3 Guidance"
            };

            var statisticsDbContextId = Guid.NewGuid().ToString();

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                await statisticsDbContext.AddAsync(release);

                await statisticsDbContext.AddRangeAsync(releaseSubject1, releaseSubject2, releaseSubject3);

                await statisticsDbContext.SaveChangesAsync();
            }

            var contentRelease = new Content.Model.Release
            {
                Id = release.Id,
            };

            var releaseFile1 = new ReleaseFile
            {
                Release = contentRelease,
                Name    = "Subject 1",
                File    = new File
                {
                    SubjectId = releaseSubject1.SubjectId,
                    Filename  = "file1.csv",
                    Type      = FileType.Data,
                }
            };

            var releaseFile2 = new ReleaseFile
            {
                Release = contentRelease,
                Name    = "Subject 2",
                File    = new File
                {
                    SubjectId = releaseSubject2.SubjectId,
                    Filename  = "file2.csv",
                    Type      = FileType.Data,
                }
            };

            var releaseFile3 = new ReleaseFile
            {
                Release = contentRelease,
                Name    = "Subject 3",
                File    = new File
                {
                    SubjectId = releaseSubject3.SubjectId,
                    Filename  = "file3.csv",
                    Type      = FileType.Data,
                }
            };

            var contentDbContextId = Guid.NewGuid().ToString();

            await using (var contentDbContext = InMemoryContentDbContext(contentDbContextId))
            {
                await contentDbContext.AddRangeAsync(
                    releaseFile1, releaseFile2, releaseFile3);

                await contentDbContext.SaveChangesAsync();
            }

            await using (var contentDbContext = InMemoryContentDbContext(contentDbContextId))
                await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
                {
                    var service = SetupService(
                        statisticsDbContext: statisticsDbContext,
                        contentDbContext: contentDbContext);

                    var result = await service.GetSubjects(release.Id, new List <Guid>
                    {
                        releaseSubject1.SubjectId, releaseSubject3.SubjectId
                    });

                    // Assert only the specified Subjects are returned
                    Assert.True(result.IsRight);

                    Assert.Equal(2, result.Right.Count);

                    Assert.Equal(releaseSubject1.SubjectId, result.Right[0].Id);
                    Assert.Equal("Subject 1 Guidance", result.Right[0].Content);
                    Assert.Equal("file1.csv", result.Right[0].Filename);
                    Assert.Equal("Subject 1", result.Right[0].Name);
                    Assert.Empty(result.Right[0].TimePeriods.From);
                    Assert.Empty(result.Right[0].TimePeriods.To);
                    Assert.Empty(result.Right[0].GeographicLevels);
                    Assert.Empty(result.Right[0].Variables);

                    Assert.Equal(releaseSubject3.SubjectId, result.Right[1].Id);
                    Assert.Equal("Subject 3 Guidance", result.Right[1].Content);
                    Assert.Equal("file3.csv", result.Right[1].Filename);
                    Assert.Equal("Subject 3", result.Right[1].Name);
                    Assert.Empty(result.Right[1].TimePeriods.From);
                    Assert.Empty(result.Right[1].TimePeriods.To);
                    Assert.Empty(result.Right[1].GeographicLevels);
                    Assert.Empty(result.Right[1].Variables);
                }
        }
Exemple #22
0
        public async Task GetGeographicLevels()
        {
            var release = new Release();

            var subject = new Subject();

            var releaseSubject = new ReleaseSubject
            {
                Release      = release,
                Subject      = subject,
                DataGuidance = "Subject 1 Guidance"
            };

            var subjectObservation1 = new Observation
            {
                Location = new Location
                {
                    GeographicLevel = GeographicLevel.Country
                },
                Subject        = subject,
                Year           = 2020,
                TimeIdentifier = TimeIdentifier.AcademicYearQ3
            };

            var subjectObservation2 = new Observation
            {
                Location = new Location
                {
                    GeographicLevel = GeographicLevel.LocalAuthority
                },
                Subject        = subject,
                Year           = 2020,
                TimeIdentifier = TimeIdentifier.AcademicYearQ4
            };

            var subjectObservation3 = new Observation
            {
                Location = new Location
                {
                    GeographicLevel = GeographicLevel.LocalAuthorityDistrict
                },
                Subject        = subject,
                Year           = 2021,
                TimeIdentifier = TimeIdentifier.AcademicYearQ1
            };

            var statisticsDbContextId = Guid.NewGuid().ToString();

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                await statisticsDbContext.AddAsync(release);

                await statisticsDbContext.AddAsync(subject);

                await statisticsDbContext.AddAsync(releaseSubject);

                await statisticsDbContext.AddRangeAsync(
                    subjectObservation1,
                    subjectObservation2,
                    subjectObservation3);

                await statisticsDbContext.SaveChangesAsync();
            }

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                var service = SetupService(statisticsDbContext: statisticsDbContext);

                var result = await service.GetGeographicLevels(subject.Id);

                Assert.Equal(3, result.Count);
                Assert.Equal("National", result[0]);
                Assert.Equal("Local Authority", result[1]);
                Assert.Equal("Local Authority District", result[2]);
            }
        }
Exemple #23
0
        public async Task Query_ReleaseId()
        {
            var releaseSubject = new ReleaseSubject
            {
                Release = new Release(),
                Subject = new Subject
                {
                    Id = Guid.NewGuid()
                },
            };

            var indicator1Id = Guid.NewGuid();
            var indicator2Id = Guid.NewGuid();

            var query = new ObservationQueryContext
            {
                SubjectId  = releaseSubject.Subject.Id,
                Indicators = new[] { indicator1Id, indicator2Id, },
                Locations  = new LocationQuery
                {
                    Country = new[] { "england" }
                },
                TimePeriod = new TimePeriodQuery
                {
                    StartYear = 2019,
                    StartCode = TimeIdentifier.AcademicYear,
                    EndYear   = 2020,
                    EndCode   = TimeIdentifier.AcademicYear,
                }
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var statisticsDbContext = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                await statisticsDbContext.AddAsync(releaseSubject);

                await statisticsDbContext.SaveChangesAsync();
            }

            await using (var statisticsDbContext = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                var observations = new List <Observation>
                {
                    new Observation
                    {
                        Measures = new Dictionary <Guid, string>
                        {
                            { indicator1Id, "123" },
                            { indicator2Id, "456" },
                        },
                        FilterItems    = new List <ObservationFilterItem>(),
                        Year           = 2019,
                        TimeIdentifier = TimeIdentifier.AcademicYear,
                    },
                    new Observation
                    {
                        Measures = new Dictionary <Guid, string>
                        {
                            { indicator1Id, "789" },
                            { Guid.NewGuid(), "1123" },
                            { Guid.NewGuid(), "1456" },
                        },
                        FilterItems    = new List <ObservationFilterItem>(),
                        Year           = 2020,
                        TimeIdentifier = TimeIdentifier.AcademicYear,
                    },
                };

                var subjectMeta = new ResultSubjectMetaViewModel
                {
                    Indicators = new List <IndicatorMetaViewModel>
                    {
                        new IndicatorMetaViewModel
                        {
                            Label = "Test indicator"
                        }
                    },
                };

                var observationService = new Mock <IObservationService>();

                observationService
                .Setup(s => s.FindObservations(query))
                .Returns(observations);

                var resultSubjectMetaService = new Mock <IResultSubjectMetaService>();

                resultSubjectMetaService
                .Setup(
                    s => s.GetSubjectMeta(
                        releaseSubject.ReleaseId,
                        It.IsAny <SubjectMetaQueryContext>(),
                        It.IsAny <IQueryable <Observation> >()
                        )
                    )
                .ReturnsAsync(subjectMeta);

                var service = BuildTableBuilderService(
                    statisticsDbContext,
                    observationService: observationService.Object,
                    resultSubjectMetaService: resultSubjectMetaService.Object
                    );

                var result = await service.Query(releaseSubject.ReleaseId, query);

                Assert.True(result.IsRight);

                var observationResults = result.Right.Results.ToList();

                Assert.Equal(2, observationResults.Count);

                Assert.Equal("2019_AY", observationResults[0].TimePeriod);
                Assert.Equal(2, observationResults[0].Measures.Count);
                Assert.Equal("123", observationResults[0].Measures[indicator1Id.ToString()]);
                Assert.Equal("456", observationResults[0].Measures[indicator2Id.ToString()]);

                Assert.Equal("2020_AY", observationResults[1].TimePeriod);
                Assert.Single(observationResults[1].Measures);
                Assert.Equal("789", observationResults[1].Measures[indicator1Id.ToString()]);

                Assert.Equal(subjectMeta, result.Right.SubjectMeta);

                MockUtils.VerifyAllMocks(observationService, resultSubjectMetaService);
            }
        }
        public async Task Get_AmendedRelease()
        {
            var releaseVersion1 = new Release
            {
                Id = Guid.NewGuid(),
                PreviousVersionId = null
            };

            var releaseVersion2 = new Release
            {
                Id = Guid.NewGuid(),
                PreviousVersionId = releaseVersion1.Id
            };

            var subject1 = new Subject
            {
                Filename = "file1.csv",
                Name     = "Subject 1"
            };

            var subject2 = new Subject
            {
                Filename = "file2.csv",
                Name     = "Subject 2"
            };

            // Version 1 has one Subject, Version 2 adds another Subject

            var releaseVersion1Subject1 = new ReleaseSubject
            {
                Release      = releaseVersion1,
                Subject      = subject1,
                MetaGuidance = "Version 1 Subject 1 Meta Guidance"
            };

            var releaseVersion2Subject1 = new ReleaseSubject
            {
                Release      = releaseVersion2,
                Subject      = subject1,
                MetaGuidance = "Version 2 Subject 1 Meta Guidance"
            };

            var releaseVersion2Subject2 = new ReleaseSubject
            {
                Release      = releaseVersion2,
                Subject      = subject2,
                MetaGuidance = "Version 2 Subject 2 Meta Guidance"
            };

            var statisticsDbContextId = Guid.NewGuid().ToString();

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                await statisticsDbContext.AddRangeAsync(releaseVersion1, releaseVersion2);

                await statisticsDbContext.AddRangeAsync(subject1, subject2);

                await statisticsDbContext.AddRangeAsync(releaseVersion1Subject1, releaseVersion2Subject1,
                                                        releaseVersion2Subject2);

                await statisticsDbContext.SaveChangesAsync();
            }

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                var service = SetupMetaGuidanceSubjectService(context: statisticsDbContext);

                var version1Result = await service.GetSubjects(releaseVersion1.Id);

                // Assert version 1 has one Subject with the correct content
                Assert.True(version1Result.IsRight);

                Assert.Single(version1Result.Right);

                Assert.Equal(subject1.Id, version1Result.Right[0].Id);
                Assert.Equal("Version 1 Subject 1 Meta Guidance", version1Result.Right[0].Content);
                Assert.Equal("file1.csv", version1Result.Right[0].Filename);
                Assert.Equal("Subject 1", version1Result.Right[0].Name);
                Assert.Null(version1Result.Right[0].TimePeriods.From);
                Assert.Null(version1Result.Right[0].TimePeriods.To);
                Assert.Empty(version1Result.Right[0].GeographicLevels);
                Assert.Empty(version1Result.Right[0].Variables);

                var version2Result = await service.GetSubjects(releaseVersion2.Id);

                // Assert version 2 has two Subjects with the correct content
                Assert.True(version2Result.IsRight);

                Assert.Equal(2, version2Result.Right.Count);

                Assert.Equal(subject1.Id, version2Result.Right[0].Id);
                Assert.Equal("Version 2 Subject 1 Meta Guidance", version2Result.Right[0].Content);
                Assert.Equal("file1.csv", version2Result.Right[0].Filename);
                Assert.Equal("Subject 1", version2Result.Right[0].Name);
                Assert.Null(version2Result.Right[0].TimePeriods.From);
                Assert.Null(version2Result.Right[0].TimePeriods.To);
                Assert.Empty(version2Result.Right[0].GeographicLevels);

                Assert.Equal(subject2.Id, version2Result.Right[1].Id);
                Assert.Equal("Version 2 Subject 2 Meta Guidance", version2Result.Right[1].Content);
                Assert.Equal("file2.csv", version2Result.Right[1].Filename);
                Assert.Equal("Subject 2", version2Result.Right[1].Name);
                Assert.Null(version2Result.Right[1].TimePeriods.From);
                Assert.Null(version2Result.Right[1].TimePeriods.To);
                Assert.Empty(version2Result.Right[1].GeographicLevels);
                Assert.Empty(version2Result.Right[1].Variables);
            }
        }
        public async Task Get_SpecificSubjects()
        {
            var release = new Release();

            var subject1 = new Subject
            {
                Filename = "file1.csv",
                Name     = "Subject 1"
            };

            var subject2 = new Subject
            {
                Filename = "file2.csv",
                Name     = "Subject 2"
            };

            var subject3 = new Subject
            {
                Filename = "file3.csv",
                Name     = "Subject 3"
            };

            var releaseSubject1 = new ReleaseSubject
            {
                Release      = release,
                Subject      = subject1,
                MetaGuidance = "Subject 1 Meta Guidance"
            };

            var releaseSubject2 = new ReleaseSubject
            {
                Release      = release,
                Subject      = subject2,
                MetaGuidance = "Subject 2 Meta Guidance"
            };

            var releaseSubject3 = new ReleaseSubject
            {
                Release      = release,
                Subject      = subject3,
                MetaGuidance = "Subject 3 Meta Guidance"
            };

            var statisticsDbContextId = Guid.NewGuid().ToString();

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                await statisticsDbContext.AddAsync(release);

                await statisticsDbContext.AddRangeAsync(subject1, subject2, subject3);

                await statisticsDbContext.AddRangeAsync(releaseSubject1, releaseSubject2, releaseSubject3);

                await statisticsDbContext.SaveChangesAsync();
            }

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                var service = SetupMetaGuidanceSubjectService(context: statisticsDbContext);

                var result = await service.GetSubjects(release.Id, new List <Guid>
                {
                    subject1.Id, subject3.Id
                });

                // Assert only the specified Subjects are returned
                Assert.True(result.IsRight);

                Assert.Equal(2, result.Right.Count);

                Assert.Equal(subject1.Id, result.Right[0].Id);
                Assert.Equal("Subject 1 Meta Guidance", result.Right[0].Content);
                Assert.Equal("file1.csv", result.Right[0].Filename);
                Assert.Equal("Subject 1", result.Right[0].Name);
                Assert.Null(result.Right[0].TimePeriods.From);
                Assert.Null(result.Right[0].TimePeriods.To);
                Assert.Empty(result.Right[0].GeographicLevels);
                Assert.Empty(result.Right[0].Variables);

                Assert.Equal(subject3.Id, result.Right[1].Id);
                Assert.Equal("Subject 3 Meta Guidance", result.Right[1].Content);
                Assert.Equal("file3.csv", result.Right[1].Filename);
                Assert.Equal("Subject 3", result.Right[1].Name);
                Assert.Null(result.Right[1].TimePeriods.From);
                Assert.Null(result.Right[1].TimePeriods.To);
                Assert.Empty(result.Right[1].GeographicLevels);
                Assert.Empty(result.Right[1].Variables);
            }
        }
        public async Task Get_OrderedByName()
        {
            var release = new Release();

            var releaseSubject1 = new ReleaseSubject
            {
                Release = release,
                Subject = new Subject
                {
                    Filename = "file1.csv",
                    Name     = "Subject 1"
                },
                MetaGuidance = "Subject 1 Meta Guidance"
            };
            var releaseSubject2 = new ReleaseSubject
            {
                Release = release,
                Subject = new Subject
                {
                    Filename = "file2.csv",
                    Name     = "Subject 2"
                },
                MetaGuidance = "Subject 2 Meta Guidance"
            };
            var releaseSubject3 = new ReleaseSubject
            {
                Release = release,
                Subject = new Subject
                {
                    Filename = "file3.csv",
                    Name     = "Subject 3"
                },
                MetaGuidance = "Subject 3 Meta Guidance"
            };

            var statisticsDbContextId = Guid.NewGuid().ToString();

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                await statisticsDbContext.AddAsync(release);

                // Saved in random order
                await statisticsDbContext.AddRangeAsync(releaseSubject3, releaseSubject1, releaseSubject2);

                await statisticsDbContext.SaveChangesAsync();
            }

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                var service = SetupMetaGuidanceSubjectService(context: statisticsDbContext);

                var result = await service.GetSubjects(release.Id);

                Assert.True(result.IsRight);

                Assert.Equal(3, result.Right.Count);

                Assert.Equal("Subject 1", result.Right[0].Name);
                Assert.Equal("Subject 2", result.Right[1].Name);
                Assert.Equal("Subject 3", result.Right[2].Name);
            }
        }
        public async Task Get()
        {
            var release = new Release();

            var subject1 = new Subject
            {
                Filename = "file1.csv",
                Name     = "Subject 1"
            };

            var subject2 = new Subject
            {
                Filename = "file2.csv",
                Name     = "Subject 2"
            };

            var subject1Filter = new Filter
            {
                Subject = subject1,
                Name    = "subject1_filter",
                Label   = "Subject 1 Filter",
                Hint    = "Hint"
            };

            var subject2Filter = new Filter
            {
                Subject = subject2,
                Name    = "subject2_filter",
                Label   = "Subject 2 Filter",
                Hint    = null
            };

            var subject1IndicatorGroup = new IndicatorGroup
            {
                Subject    = subject1,
                Indicators = new List <Indicator>
                {
                    new Indicator
                    {
                        Name  = "subject1_indicator",
                        Label = "Subject 1 Indicator"
                    }
                }
            };

            var subject2IndicatorGroup = new IndicatorGroup
            {
                Subject    = subject2,
                Indicators = new List <Indicator>
                {
                    new Indicator
                    {
                        Name  = "subject2_indicator",
                        Label = "Subject 2 Indicator"
                    }
                }
            };

            var releaseSubject1 = new ReleaseSubject
            {
                Release      = release,
                Subject      = subject1,
                MetaGuidance = "Subject 1 Meta Guidance"
            };

            var releaseSubject2 = new ReleaseSubject
            {
                Release      = release,
                Subject      = subject2,
                MetaGuidance = "Subject 2 Meta Guidance"
            };

            var subject1Observation1 = new Observation
            {
                GeographicLevel = GeographicLevel.Country,
                Subject         = subject1,
                Year            = 2020,
                TimeIdentifier  = TimeIdentifier.AcademicYearQ3
            };

            var subject1Observation2 = new Observation
            {
                GeographicLevel = GeographicLevel.LocalAuthority,
                Subject         = subject1,
                Year            = 2020,
                TimeIdentifier  = TimeIdentifier.AcademicYearQ4
            };

            var subject1Observation3 = new Observation
            {
                GeographicLevel = GeographicLevel.LocalAuthorityDistrict,
                Subject         = subject1,
                Year            = 2021,
                TimeIdentifier  = TimeIdentifier.AcademicYearQ1
            };

            var subject2Observation1 = new Observation
            {
                GeographicLevel = GeographicLevel.Country,
                Subject         = subject2,
                Year            = 2020,
                TimeIdentifier  = TimeIdentifier.SummerTerm
            };

            var subject2Observation2 = new Observation
            {
                GeographicLevel = GeographicLevel.Region,
                Subject         = subject2,
                Year            = 2021,
                TimeIdentifier  = TimeIdentifier.AutumnTerm
            };

            var subject2Observation3 = new Observation
            {
                GeographicLevel = GeographicLevel.Region,
                Subject         = subject2,
                Year            = 2021,
                TimeIdentifier  = TimeIdentifier.SpringTerm
            };

            var statisticsDbContextId = Guid.NewGuid().ToString();

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                await statisticsDbContext.AddAsync(release);

                await statisticsDbContext.AddRangeAsync(subject1, subject2);

                await statisticsDbContext.AddRangeAsync(releaseSubject1, releaseSubject2);

                await statisticsDbContext.AddRangeAsync(subject1Filter, subject2Filter);

                await statisticsDbContext.AddRangeAsync(subject1IndicatorGroup, subject2IndicatorGroup);

                await statisticsDbContext.AddRangeAsync(subject1Observation1, subject1Observation2,
                                                        subject1Observation3, subject2Observation1, subject2Observation2, subject2Observation3);

                await statisticsDbContext.SaveChangesAsync();
            }

            await using (var statisticsDbContext = InMemoryStatisticsDbContext(statisticsDbContextId))
            {
                var service = SetupMetaGuidanceSubjectService(context: statisticsDbContext);

                var result = await service.GetSubjects(release.Id);

                // Assert there are two Subjects with the correct content
                Assert.True(result.IsRight);

                Assert.Equal(2, result.Right.Count);

                Assert.Equal(subject1.Id, result.Right[0].Id);
                Assert.Equal("Subject 1 Meta Guidance", result.Right[0].Content);
                Assert.Equal("file1.csv", result.Right[0].Filename);
                Assert.Equal("Subject 1", result.Right[0].Name);
                Assert.Equal("2020/21 Q3", result.Right[0].TimePeriods.From);
                Assert.Equal("2021/22 Q1", result.Right[0].TimePeriods.To);
                Assert.Equal(new List <string>
                {
                    "National", "Local Authority", "Local Authority District"
                }, result.Right[0].GeographicLevels);
                Assert.Equal(2, result.Right[0].Variables.Count);
                Assert.Equal("Subject 1 Filter - Hint", result.Right[0].Variables[0].Label);
                Assert.Equal("subject1_filter", result.Right[0].Variables[0].Value);
                Assert.Equal("Subject 1 Indicator", result.Right[0].Variables[1].Label);
                Assert.Equal("subject1_indicator", result.Right[0].Variables[1].Value);

                Assert.Equal(subject2.Id, result.Right[1].Id);
                Assert.Equal("Subject 2 Meta Guidance", result.Right[1].Content);
                Assert.Equal("file2.csv", result.Right[1].Filename);
                Assert.Equal("Subject 2", result.Right[1].Name);
                Assert.Equal("2020/21 Summer Term", result.Right[1].TimePeriods.From);
                Assert.Equal("2021/22 Spring Term", result.Right[1].TimePeriods.To);
                Assert.Equal(new List <string>
                {
                    "National", "Regional"
                }, result.Right[1].GeographicLevels);
                Assert.Equal(2, result.Right[1].Variables.Count);
                Assert.Equal("Subject 2 Filter", result.Right[1].Variables[0].Label);
                Assert.Equal("subject2_filter", result.Right[1].Variables[0].Value);
                Assert.Equal("Subject 2 Indicator", result.Right[1].Variables[1].Label);
                Assert.Equal("subject2_indicator", result.Right[1].Variables[1].Value);
            }
        }
Exemple #28
0
        public async Task GetSubjectsWithNoFootnotes_FootnoteForMultipleSubjects()
        {
            var release = new Release();

            var releaseSubject1 = new ReleaseSubject
            {
                Release = release,
                Subject = new Subject
                {
                    Name = "Test subject 1"
                }
            };
            var releaseSubject2 = new ReleaseSubject
            {
                Release = release,
                Subject = new Subject
                {
                    Name = "Test subject 2"
                }
            };
            var releaseSubject3 = new ReleaseSubject
            {
                Release = release,
                Subject = new Subject
                {
                    Name = "Test subject 3"
                }
            };
            var releaseSubject4 = new ReleaseSubject
            {
                Release = release,
                Subject = new Subject
                {
                    Name = "Test subject 4"
                }
            };
            var releaseSubject5 = new ReleaseSubject
            {
                Release = release,
                Subject = new Subject
                {
                    Name = "Test subject 5",
                }
            };
            var releaseSubjectWithNoFootnotes = new ReleaseSubject
            {
                Release = release,
                Subject = new Subject
                {
                    Name = "Test subject with no footnotes"
                }
            };

            var footnote = new Footnote
            {
                Content  = "Test footnote 1",
                Releases = new List <ReleaseFootnote>
                {
                    new ReleaseFootnote
                    {
                        Release = release
                    },
                },
                Subjects = new List <SubjectFootnote>
                {
                    new SubjectFootnote
                    {
                        Subject = releaseSubject1.Subject,
                    }
                },
                Filters = new List <FilterFootnote>
                {
                    new FilterFootnote
                    {
                        Filter = new Filter
                        {
                            Subject = releaseSubject2.Subject
                        },
                    }
                },
                FilterGroups = new List <FilterGroupFootnote>
                {
                    new FilterGroupFootnote
                    {
                        FilterGroup = new FilterGroup
                        {
                            Filter = new Filter
                            {
                                Subject = releaseSubject3.Subject
                            },
                        }
                    }
                },
                FilterItems = new List <FilterItemFootnote>
                {
                    new FilterItemFootnote
                    {
                        FilterItem = new FilterItem
                        {
                            FilterGroup = new FilterGroup
                            {
                                Filter = new Filter
                                {
                                    Subject = releaseSubject4.Subject
                                },
                            }
                        }
                    }
                },
                Indicators = new List <IndicatorFootnote>
                {
                    new IndicatorFootnote
                    {
                        Indicator = new Indicator
                        {
                            IndicatorGroup = new IndicatorGroup
                            {
                                Subject = releaseSubject5.Subject
                            }
                        }
                    }
                }
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var context = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                await context.AddRangeAsync(release);

                await context.AddRangeAsync(
                    releaseSubject1,
                    releaseSubject2,
                    releaseSubject3,
                    releaseSubject4,
                    releaseSubject5,
                    releaseSubjectWithNoFootnotes
                    );

                await context.AddRangeAsync(footnote);

                await context.SaveChangesAsync();
            }

            await using (var context = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                var repository = BuildFootnoteRepository(context);
                var results    = await repository.GetSubjectsWithNoFootnotes(release.Id);

                Assert.Single(results);

                Assert.Equal(releaseSubjectWithNoFootnotes.Subject.Id, results[0].Id);
                Assert.Equal(releaseSubjectWithNoFootnotes.Subject.Name, results[0].Name);
            }
        }
Exemple #29
0
        public async Task GetFootnotes_FiltersCriteriaBySubjectId()
        {
            var release      = new Release();
            var otherRelease = new Release();

            var releaseSubject = new ReleaseSubject
            {
                Release = release,
                Subject = new Subject
                {
                    Name = "Test subject for release"
                }
            };

            var otherReleaseSubject = new ReleaseSubject
            {
                Release = otherRelease,
                Subject = new Subject
                {
                    Name = "Test subject for other release"
                }
            };

            var footnote = new Footnote
            {
                Content  = "Test footnote",
                Releases = new List <ReleaseFootnote>
                {
                    new ReleaseFootnote
                    {
                        Release = release
                    },
                    new ReleaseFootnote
                    {
                        Release = otherRelease
                    }
                },
                Subjects = new List <SubjectFootnote>
                {
                    new SubjectFootnote
                    {
                        Subject = releaseSubject.Subject
                    },
                    new SubjectFootnote
                    {
                        Subject = otherReleaseSubject.Subject
                    },
                },
                Filters = new List <FilterFootnote>
                {
                    new FilterFootnote
                    {
                        Filter = new Filter
                        {
                            Subject = releaseSubject.Subject
                        }
                    },
                    new FilterFootnote
                    {
                        Filter = new Filter
                        {
                            Subject = otherReleaseSubject.Subject
                        }
                    }
                },
                FilterGroups = new List <FilterGroupFootnote>
                {
                    new FilterGroupFootnote
                    {
                        FilterGroup = new FilterGroup
                        {
                            Filter = new Filter
                            {
                                Subject = releaseSubject.Subject
                            }
                        }
                    },
                    new FilterGroupFootnote
                    {
                        FilterGroup = new FilterGroup
                        {
                            Filter = new Filter
                            {
                                Subject = otherReleaseSubject.Subject
                            }
                        }
                    }
                },
                FilterItems = new List <FilterItemFootnote>
                {
                    new FilterItemFootnote
                    {
                        FilterItem = new FilterItem
                        {
                            FilterGroup = new FilterGroup
                            {
                                Filter = new Filter
                                {
                                    Subject = releaseSubject.Subject
                                }
                            }
                        }
                    },
                    new FilterItemFootnote
                    {
                        FilterItem = new FilterItem
                        {
                            FilterGroup = new FilterGroup
                            {
                                Filter = new Filter
                                {
                                    Subject = otherReleaseSubject.Subject,
                                }
                            }
                        }
                    }
                },
                Indicators = new List <IndicatorFootnote>
                {
                    new IndicatorFootnote
                    {
                        Indicator = new Indicator
                        {
                            IndicatorGroup = new IndicatorGroup
                            {
                                Subject = releaseSubject.Subject
                            }
                        }
                    },
                    new IndicatorFootnote
                    {
                        Indicator = new Indicator
                        {
                            IndicatorGroup = new IndicatorGroup
                            {
                                Subject = otherReleaseSubject.Subject
                            }
                        }
                    }
                }
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var context = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                await context.AddRangeAsync(release, otherRelease);

                await context.AddRangeAsync(releaseSubject, otherReleaseSubject);

                await context.AddAsync(footnote);

                await context.SaveChangesAsync();
            }

            await using (var context = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                var repository = BuildFootnoteRepository(context);
                var results    = repository.GetFootnotes(release.Id, releaseSubject.SubjectId).ToList();

                Assert.Single(results);
                Assert.Equal("Test footnote", results[0].Content);

                var footnoteReleases = results[0].Releases.ToList();

                Assert.Single(footnoteReleases);
                Assert.Equal(releaseSubject.ReleaseId, footnoteReleases[0].ReleaseId);

                var footnoteSubjects = results[0].Subjects.ToList();

                Assert.Single(footnoteSubjects);
                Assert.Equal(releaseSubject.SubjectId, footnoteSubjects[0].SubjectId);

                var footnoteFilters = results[0].Filters.ToList();

                Assert.Single(footnoteSubjects);
                Assert.Equal(releaseSubject.SubjectId, footnoteFilters[0].Filter.SubjectId);

                var footnoteFilterGroups = results[0].FilterGroups.ToList();

                Assert.Single(footnoteFilterGroups);
                Assert.Equal(releaseSubject.SubjectId, footnoteFilterGroups[0].FilterGroup.Filter.SubjectId);

                var footnoteFilterItems = results[0].FilterItems.ToList();

                Assert.Single(footnoteFilterItems);
                Assert.Equal(releaseSubject.SubjectId, footnoteFilterItems[0].FilterItem.FilterGroup.Filter.SubjectId);

                var footnoteIndicators = results[0].Indicators.ToList();

                Assert.Single(footnoteIndicators);
                Assert.Equal(releaseSubject.SubjectId, footnoteIndicators[0].Indicator.IndicatorGroup.SubjectId);
            }
        }
Exemple #30
0
        public async Task GetFootnotes_FiltersBySubjectIds()
        {
            var release = new Release();

            var releaseSubject1 = new ReleaseSubject
            {
                Release = release,
                Subject = new Subject()
            };

            var releaseSubject2 = new ReleaseSubject
            {
                Release = release,
                Subject = new Subject()
            };

            var releaseSubject3 = new ReleaseSubject
            {
                Release = release,
                Subject = new Subject()
            };

            var footnote1 = new Footnote
            {
                Content  = "Test footnote 1",
                Releases = new List <ReleaseFootnote>
                {
                    new ReleaseFootnote
                    {
                        Release = release
                    },
                },
                Subjects = new List <SubjectFootnote>
                {
                    new SubjectFootnote
                    {
                        Subject = releaseSubject1.Subject
                    }
                },
            };

            var footnote2 = new Footnote
            {
                Content  = "Test footnote 2",
                Releases = new List <ReleaseFootnote>
                {
                    new ReleaseFootnote
                    {
                        Release = release
                    },
                },
                Subjects = new List <SubjectFootnote>
                {
                    new SubjectFootnote
                    {
                        Subject = releaseSubject2.Subject
                    }
                },
            };

            var footnote3 = new Footnote
            {
                Content  = "Test footnote 3",
                Releases = new List <ReleaseFootnote>
                {
                    new ReleaseFootnote
                    {
                        Release = release
                    },
                },
                Subjects = new List <SubjectFootnote>
                {
                    new SubjectFootnote
                    {
                        Subject = releaseSubject3.Subject
                    }
                },
            };

            var contextId = Guid.NewGuid().ToString();

            await using (var context = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                await context.AddAsync(release);

                await context.AddRangeAsync(releaseSubject1, releaseSubject2, releaseSubject3);

                await context.AddRangeAsync(footnote1, footnote2, footnote3);

                await context.SaveChangesAsync();
            }

            await using (var context = StatisticsDbUtils.InMemoryStatisticsDbContext(contextId))
            {
                var repository = BuildFootnoteRepository(context);
                var results    = repository.GetFootnotes(
                    release.Id,
                    new List <Guid> {
                    releaseSubject1.SubjectId, releaseSubject3.SubjectId
                }
                    )
                                 .ToList();

                Assert.Equal(2, results.Count);

                Assert.Equal("Test footnote 1", results[0].Content);
                Assert.Equal("Test footnote 3", results[1].Content);
            }
        }