예제 #1
0
        public void Throws_error_when_default_permissions_reference_permission_records_that_werent_provided()
        {
            // setup
            var testPermissionProvider = new Fakes.FakePermissionProvider(new List <PermissionRecord>(), GetTestDefaultPermissionRecords());

            // act/assert
            Assert.That(() => _permissionService.InstallPermissions(testPermissionProvider, true), Throws.Exception);
        }
예제 #2
0
        public void Can_install_new_permissions()
        {
            // setup
            var testPermissionRecords  = GetTestPermissionRecords();
            var testPermissionProvider = new Fakes.FakePermissionProvider(testPermissionRecords, GetTestDefaultPermissionRecords());

            // act
            _permissionService.InstallPermissions(testPermissionProvider);

            // assert
            var databasePermissions = _container.Resolve <MongoCollection <PermissionRecord> >().FindAll().ToList();

            databasePermissions.Count.ShouldEqual(2);
            databasePermissions.SequenceEqual(testPermissionRecords, GetPermissionRecordComparer()).ShouldBeTrue();
        }
예제 #3
0
        public void Can_add_user_roles_if_installing_a_provider_with_new_user_roles()
        {
            // setup
            var testPermissionProvider = new Fakes.FakePermissionProvider(GetTestPermissionRecords(), GetTestDefaultPermissionRecords());

            // act
            _permissionService.InstallPermissions(testPermissionProvider, true);

            // assert
            var roles = _container.Resolve<MongoCollection<UserRole>>().FindAll().ToList();
            var roleMaps = _container.Resolve<MongoCollection<RolePermissionMap>>().FindAll().ToList();
            roles.Count.ShouldEqual(2);
            roleMaps.Count.ShouldEqual(2);
            roleMaps.Any(x => x.UserRoleId == roles[0].Id).ShouldBeTrue();
            roleMaps.Any(x => x.UserRoleId == roles[1].Id).ShouldBeTrue();
        }
예제 #4
0
        public void Can_add_user_roles_if_installing_a_provider_with_new_user_roles()
        {
            // setup
            var testPermissionProvider = new Fakes.FakePermissionProvider(GetTestPermissionRecords(), GetTestDefaultPermissionRecords());

            // act
            _permissionService.InstallPermissions(testPermissionProvider, true);

            // assert
            var roles    = _container.Resolve <MongoCollection <UserRole> >().FindAll().ToList();
            var roleMaps = _container.Resolve <MongoCollection <RolePermissionMap> >().FindAll().ToList();

            roles.Count.ShouldEqual(2);
            roleMaps.Count.ShouldEqual(2);
            roleMaps.Any(x => x.UserRoleId == roles[0].Id).ShouldBeTrue();
            roleMaps.Any(x => x.UserRoleId == roles[1].Id).ShouldBeTrue();
        }
예제 #5
0
        public void Can_udpate_database_when_reinstalling_a_provider()
        {
            // setup
            Can_install_new_permissions();
            var testPermissionRecords = GetTestPermissionRecords();

            testPermissionRecords[0].Name = "Permission1Modified";
            var testPermissionProvider = new Fakes.FakePermissionProvider(testPermissionRecords, GetTestDefaultPermissionRecords());

            // act
            _permissionService.InstallPermissions(testPermissionProvider, true);

            // assert
            var databasePermissions = _container.Resolve <MongoCollection <PermissionRecord> >().FindAll().ToList();

            databasePermissions.Count.ShouldEqual(2);
            databasePermissions[0].Name.ShouldEqual("Permission2");
            databasePermissions[1].Name.ShouldEqual("Permission1Modified");
        }
예제 #6
0
        public void Can_ignore_an_installation_provider_if_it_has_already_been_installed()
        {
            // setup
            Can_install_new_permissions();
            var testPermissionRecords = GetTestPermissionRecords();

            testPermissionRecords[0].Name = "Permission1Modified";
            testPermissionRecords.Add(new PermissionRecord {
                Name = "NewPermission", Category = "NewPermissionCategory", SystemName = "NewPermissionSystem"
            });
            var testPermissionProvider = new Fakes.FakePermissionProvider(testPermissionRecords, GetTestDefaultPermissionRecords());

            // act
            _permissionService.InstallPermissions(testPermissionProvider);

            // assert
            var databasePermissions = _container.Resolve <MongoCollection <PermissionRecord> >().FindAll().ToList();

            databasePermissions.Count.ShouldEqual(2);
            databasePermissions[0].Name.ShouldEqual("Permission1");
        }
예제 #7
0
        public void Throws_error_when_default_permissions_reference_permission_records_that_werent_provided()
        {
            // setup
            var testPermissionProvider = new Fakes.FakePermissionProvider(new List<PermissionRecord>(), GetTestDefaultPermissionRecords());

            // act/assert
            Assert.That(() => _permissionService.InstallPermissions(testPermissionProvider, true), Throws.Exception);
        }
예제 #8
0
        public void Can_udpate_database_when_reinstalling_a_provider()
        {
            // setup
            Can_install_new_permissions();
            var testPermissionRecords = GetTestPermissionRecords();
            testPermissionRecords[0].Name = "Permission1Modified";
            var testPermissionProvider = new Fakes.FakePermissionProvider(testPermissionRecords, GetTestDefaultPermissionRecords());

            // act
            _permissionService.InstallPermissions(testPermissionProvider, true);

            // assert
            var databasePermissions = _container.Resolve<MongoCollection<PermissionRecord>>().FindAll().ToList();
            databasePermissions.Count.ShouldEqual(2);
            databasePermissions[0].Name.ShouldEqual("Permission2");
            databasePermissions[1].Name.ShouldEqual("Permission1Modified");
        }
예제 #9
0
        public void Can_install_new_permissions()
        {
            // setup
            var testPermissionRecords = GetTestPermissionRecords();
            var testPermissionProvider = new Fakes.FakePermissionProvider(testPermissionRecords, GetTestDefaultPermissionRecords());

            // act
            _permissionService.InstallPermissions(testPermissionProvider);

            // assert
            var databasePermissions = _container.Resolve<MongoCollection<PermissionRecord>>().FindAll().ToList();
            databasePermissions.Count.ShouldEqual(2);
            databasePermissions.SequenceEqual(testPermissionRecords, GetPermissionRecordComparer()).ShouldBeTrue();
        }
예제 #10
0
        public void Can_ignore_an_installation_provider_if_it_has_already_been_installed()
        {
            // setup
            Can_install_new_permissions();
            var testPermissionRecords = GetTestPermissionRecords();
            testPermissionRecords[0].Name = "Permission1Modified";
            testPermissionRecords.Add(new PermissionRecord { Name = "NewPermission", Category = "NewPermissionCategory", SystemName = "NewPermissionSystem" });
            var testPermissionProvider = new Fakes.FakePermissionProvider(testPermissionRecords, GetTestDefaultPermissionRecords());

            // act
            _permissionService.InstallPermissions(testPermissionProvider);

            // assert
            var databasePermissions = _container.Resolve<MongoCollection<PermissionRecord>>().FindAll().ToList();
            databasePermissions.Count.ShouldEqual(2);
            databasePermissions[0].Name.ShouldEqual("Permission1");
        }