예제 #1
0
        public void GetSubjectMeta_SubjectIdNotFound()
        {
            var builder = new DbContextOptionsBuilder <StatisticsDbContext>();

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

            using (var context = new StatisticsDbContext(options, null))
            {
                var(boundaryLevelService, filterService, filterItemService, geoJsonService, indicatorGroupService, locationService, observationService, timePeriodService, userService) = Mocks();

                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(Guid.NewGuid());
                Assert.True(result.Result.IsLeft);
                Assert.IsAssignableFrom <NotFoundResult>(result.Result.Left);
            }
        }
예제 #2
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);
            }
        }
예제 #3
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);
            }
        }