public async Task UpdatePublication_CanCreatePublicationForSpecificTopic()
        {
            await using var context = DbUtils.InMemoryApplicationDbContext();

            var mocks = Mocks();

            context.Add(_topic);
            context.Add(_publication);

            await context.SaveChangesAsync();

            PermissionTestUtil.AssertSecurityPoliciesChecked(
                async service =>
                await service.UpdatePublication(_publication.Id, new SavePublicationViewModel
            {
                TopicId = _topic.Id,
                Title   = "Updated publication",
                Contact = new SaveContactViewModel
                {
                    TeamName     = "Test team",
                    TeamEmail    = "*****@*****.**",
                    ContactName  = "John Smith",
                    ContactTelNo = "0123456789"
                }
            }),
                _topic,
                mocks.UserService,
                BuildPublicationService(mocks),
                SecurityPolicies.CanCreatePublicationForSpecificTopic);
        }
        public void GetViewModel()
        {
            var mocks = Mocks();

            PermissionTestUtil.AssertSecurityPoliciesChecked(
                async service => await service.GetViewModel(_publication.Id),
                _publication,
                mocks.UserService,
                BuildPublicationService(mocks),
                SecurityPolicies.CanViewSpecificPublication);
        }
        private void AssertSecurityPoliciesChecked <T, TEntity>(
            Func <PreReleaseSummaryService, Task <Either <ActionResult, T> > > protectedAction, TEntity protectedEntity,
            params SecurityPolicies[] policies)
            where TEntity : class
        {
            var(persistenceHelper, userService) = Mocks();

            var service = new PreReleaseSummaryService(persistenceHelper.Object, userService.Object);

            PermissionTestUtil.AssertSecurityPoliciesChecked(protectedAction, protectedEntity, userService, service,
                                                             policies);
        }
        public async Task CreatePublication()
        {
            await using var context = DbUtils.InMemoryApplicationDbContext();

            var mocks = Mocks();

            context.Add(_topic);

            await context.SaveChangesAsync();

            PermissionTestUtil.AssertSecurityPoliciesChecked(
                async service =>
                await service.CreatePublication(new SavePublicationViewModel
            {
                TopicId = _topic.Id,
            }),
                _topic,
                mocks.UserService,
                BuildPublicationService(mocks),
                SecurityPolicies.CanCreatePublicationForSpecificTopic);
        }
        private void AssertSecurityPoliciesChecked <T>(
            Func <DataBlockService, Task <Either <ActionResult, T> > > protectedAction, params SecurityPolicies[] policies)
        {
            var(userService, persistenceHelper, fileStorageService) = Mocks();

            using (var context = DbUtils.InMemoryApplicationDbContext())
            {
                context.Add(new ReleaseContentBlock
                {
                    Release        = _release,
                    ContentBlockId = _dataBlock.Id
                });
                context.SaveChanges();

                var service = new DataBlockService(context, AdminMapper(),
                                                   persistenceHelper.Object, userService.Object,
                                                   fileStorageService.Object);

                PermissionTestUtil.AssertSecurityPoliciesChecked(protectedAction, _release, userService, service, policies);
            }
        }
Exemple #6
0
        private void AssertSecurityPoliciesChecked <T>(
            Func <FootnoteService, Task <Either <ActionResult, T> > > protectedAction, params SecurityPolicies[] policies)
        {
            var(
                _,
                releaseHelper,
                userService,
                footnoteService,
                footnoteHelper,
                guidGenerator
                ) = Mocks();

            using var context = InMemoryStatisticsDbContext();
            var service = new FootnoteService(
                context,
                releaseHelper.Object,
                userService.Object,
                footnoteService.Object,
                footnoteHelper.Object,
                guidGenerator.Object
                );

            PermissionTestUtil.AssertSecurityPoliciesChecked(protectedAction, Release, userService, service, policies);
        }