Beispiel #1
0
 public StatePropertyDefinition CreateNewStateProperty(string name)
 {
     using (_transaction.EnterNonDiscardingScope())
     {
         return(StatePropertyDefinition.NewObject(Guid.NewGuid(), name));
     }
 }
Beispiel #2
0
        public SecurableClassDefinition CreateAndCommitSecurableClassDefinitionWithAccessControlLists(int accessControlLists, ClientTransaction transaction)
        {
            CreateEmptyDomain();

            using (transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition   classDefinition            = CreateOrderSecurableClassDefinition();
                StatelessAccessControlList statelessAccessControlList = StatelessAccessControlList.NewObject();
                classDefinition.StatelessAccessControlList = statelessAccessControlList;

                var stateProperty = StatePropertyDefinition.NewObject(Guid.NewGuid(), "Property");
                classDefinition.AddStateProperty(stateProperty);

                for (int i = 1; i < accessControlLists; i++)
                {
                    StatefulAccessControlList statefulAccessControlList = StatefulAccessControlList.NewObject();
                    classDefinition.StatefulAccessControlLists.Add(statefulAccessControlList);
                    statefulAccessControlList.CreateAccessControlEntry();
                    CreateStateCombination(statefulAccessControlList, stateProperty, StateDefinition.NewObject(string.Format("Value {0}", i), i));
                }

                ClientTransactionScope.CurrentTransaction.Commit();

                return(classDefinition);
            }
        }
Beispiel #3
0
        public void AddsStateProperty()
        {
            var stateProperty            = StatePropertyDefinition.NewObject();
            var securableClassDefinition = SecurableClassDefinition.NewObject();

            securableClassDefinition.AddStateProperty(stateProperty);

            Assert.That(securableClassDefinition.StateProperties, Is.EqualTo(new[] { stateProperty }));
        }
Beispiel #4
0
        private StatePropertyDefinition CreateConfidentialityProperty()
        {
            StatePropertyDefinition confidentialityProperty =
                StatePropertyDefinition.NewObject(new Guid("93969f13-65d7-49f4-a456-a1686a4de3de"), "Confidentiality");

            confidentialityProperty.AddState(CreateState("Public", 0));
            confidentialityProperty.AddState(CreateState("Secret", 1));
            confidentialityProperty.AddState(CreateState("TopSecret", 2));

            return(confidentialityProperty);
        }
Beispiel #5
0
        public void FailsForNonExistentStateProperty()
        {
            var securableClassDefinition = SecurableClassDefinition.NewObject();

            securableClassDefinition.Name = "Class";
            securableClassDefinition.AddStateProperty(StatePropertyDefinition.NewObject());
            securableClassDefinition.AddStateProperty(StatePropertyDefinition.NewObject());
            Assert.That(
                () => securableClassDefinition.RemoveStateProperty(StatePropertyDefinition.NewObject(Guid.NewGuid(), "Test")),
                Throws.ArgumentException
                .And.Message.StartsWith("The property 'Test' does not exist on the securable class definition."));
        }
Beispiel #6
0
        public void RemovesStateProperty()
        {
            var stateProperty0           = StatePropertyDefinition.NewObject();
            var stateProperty1           = StatePropertyDefinition.NewObject();
            var securableClassDefinition = SecurableClassDefinition.NewObject();

            securableClassDefinition.AddStateProperty(stateProperty0);
            securableClassDefinition.AddStateProperty(stateProperty1);

            securableClassDefinition.RemoveStateProperty(stateProperty0);

            Assert.That(securableClassDefinition.StateProperties, Is.EqualTo(new[] { stateProperty1 }));
        }
Beispiel #7
0
        public StatePropertyDefinition CreateFileStateProperty(int index)
        {
            using (_transaction.EnterNonDiscardingScope())
            {
                StatePropertyDefinition property = StatePropertyDefinition.NewObject(new Guid("00000000-0000-0000-0002-000000000001"), "State");
                property.Index = index;
                property.AddState(CreateState(State_NewName, State_NewValue));
                property.AddState(CreateState(State_NormalName, State_NormalValue));
                property.AddState(CreateState(State_ArchivedName, State_ArchivedValue));

                return(property);
            }
        }
Beispiel #8
0
        public StatePropertyDefinition CreateConfidentialityProperty(int index)
        {
            using (_transaction.EnterNonDiscardingScope())
            {
                StatePropertyDefinition property = StatePropertyDefinition.NewObject(new Guid("00000000-0000-0000-0001-000000000001"), "Confidentiality");
                property.Index = index;
                property.AddState(CreateState(Confidentiality_NormalName, Confidentiality_NormalValue));
                property.AddState(CreateState(Confidentiality_ConfidentialName, Confidentiality_ConfidentialValue));
                property.AddState(CreateState(Confidentiality_PrivateName, Confidentiality_PrivateValue));

                return(property);
            }
        }
Beispiel #9
0
        public void FailsForExistingStateProperty()
        {
            var stateProperty = StatePropertyDefinition.NewObject(Guid.NewGuid(), "Test");

            var securableClassDefinition = SecurableClassDefinition.NewObject();

            securableClassDefinition.Name = "Class";
            securableClassDefinition.AddStateProperty(stateProperty);
            Assert.That(
                () => securableClassDefinition.AddStateProperty(stateProperty),
                Throws.ArgumentException
                .And.Message.StartsWith("The property 'Test' has already been added to the securable class definition."));
        }
Beispiel #10
0
        public void TouchesSecurableClassDefinition()
        {
            var securableClassDefinition = SecurableClassDefinition.NewObject();

            using (ClientTransaction.Current.CreateSubTransaction().EnterDiscardingScope())
            {
                securableClassDefinition.EnsureDataAvailable();
                Assert.That(securableClassDefinition.State, Is.EqualTo(StateType.Unchanged));

                securableClassDefinition.AddStateProperty(StatePropertyDefinition.NewObject());

                Assert.That(securableClassDefinition.State, Is.EqualTo(StateType.Changed));
            }
        }
Beispiel #11
0
        private StatePropertyDefinition CreateFileStateProperty(ClientTransaction transaction)
        {
            using (transaction.EnterNonDiscardingScope())
            {
                StatePropertyDefinition fileStateProperty = StatePropertyDefinition.NewObject(new Guid("9e689c4c-3758-436e-ac86-23171289fa5e"), "FileState");
                fileStateProperty.AddState(CreateState("Open", 0));
                fileStateProperty.AddState(CreateState("Cancelled", 1));
                fileStateProperty.AddState(CreateState("Reaccounted", 2));
                fileStateProperty.AddState(CreateState("HandledBy", 3));
                fileStateProperty.AddState(CreateState("Approved", 4));

                return(fileStateProperty);
            }
        }
Beispiel #12
0
        public void RemoveStateProperty_DeletesAssociatedAccessControlListIfDeletedStateCombinationWasLastStateCombination()
        {
            var state1        = StateDefinition.NewObject("Test", 1);
            var state2        = StateDefinition.NewObject();
            var stateProperty = StatePropertyDefinition.NewObject();

            stateProperty.AddState(state1);

            var securableClassDefinition = SecurableClassDefinition.NewObject();

            securableClassDefinition.AddStateProperty(stateProperty);
            var acl1 = securableClassDefinition.CreateStatefulAccessControlList();

            acl1.StateCombinations[0].AttachState(state1);

            var acl2 = securableClassDefinition.CreateStatefulAccessControlList();

            Assert.That(acl2.StateCombinations, Is.Not.Empty);

            var acl3 = securableClassDefinition.CreateStatefulAccessControlList();

            acl3.StateCombinations[0].Delete();

            var acl4 = securableClassDefinition.CreateStatefulAccessControlList();

            acl4.StateCombinations[0].AttachState(state2);

            securableClassDefinition.RemoveStateProperty(stateProperty);

            Assert.That(acl1.State, Is.EqualTo(StateType.Invalid));

            Assert.That(acl2.State, Is.EqualTo(StateType.New));
            Assert.That(acl2.StateCombinations.Count, Is.EqualTo(1));
            Assert.That(acl2.StateCombinations[0].GetStates(), Is.Empty);

            Assert.That(acl3.State, Is.EqualTo(StateType.New));
            Assert.That(acl3.StateCombinations, Is.Empty);

            Assert.That(acl4.State, Is.EqualTo(StateType.New));
            Assert.That(acl4.StateCombinations.Count, Is.EqualTo(1));
            Assert.That(acl4.StateCombinations[0].GetStates(), Is.EqualTo(new[] { state2 }));
        }
Beispiel #13
0
        public void RemoveStateProperty_DeletesAssociatedStateCombinations()
        {
            var state1        = StateDefinition.NewObject("Test", 1);
            var state2        = StateDefinition.NewObject();
            var stateProperty = StatePropertyDefinition.NewObject();

            stateProperty.AddState(state1);

            var securableClassDefinition = SecurableClassDefinition.NewObject();

            securableClassDefinition.AddStateProperty(stateProperty);
            var acl = securableClassDefinition.CreateStatefulAccessControlList();

            acl.StateCombinations[0].AttachState(state1);
            acl.CreateStateCombination().AttachState(state2);

            securableClassDefinition.RemoveStateProperty(stateProperty);

            Assert.That(acl.StateCombinations.Count, Is.EqualTo(1));
            Assert.That(acl.StateCombinations[0].GetStates(), Is.EqualTo(new[] { state2 }));
        }
Beispiel #14
0
 public void DomainObjectsAreSerializable()
 {
     CheckDomainObjectSerializability(delegate { return(AccessControlEntry.NewObject()); });
     CheckDomainObjectSerializability(delegate { return(StatefulAccessControlList.NewObject()); });
     CheckDomainObjectSerializability(delegate { return(Permission.NewObject()); });
     CheckDomainObjectSerializability(delegate { return(StateCombination.NewObject()); });
     CheckDomainObjectSerializability(delegate { return(StateUsage.NewObject()); });
     CheckDomainObjectSerializability(delegate { return(AbstractRoleDefinition.NewObject()); });
     CheckDomainObjectSerializability(delegate { return(AccessTypeDefinition.NewObject()); });
     CheckDomainObjectSerializability(delegate { return(AccessTypeReference.NewObject()); });
     CheckDomainObjectSerializability(delegate { return(Culture.NewObject("DE-DE")); });
     CheckDomainObjectSerializability(delegate { return(LocalizedName.NewObject("foo", Culture.NewObject("DE-DE"), SecurableClassDefinition.NewObject())); });
     CheckDomainObjectSerializability(delegate { return(SecurableClassDefinition.NewObject()); });
     CheckDomainObjectSerializability(delegate { return(StateDefinition.NewObject()); });
     CheckDomainObjectSerializability(delegate { return(StatePropertyDefinition.NewObject()); });
     CheckDomainObjectSerializability(delegate { return(StatePropertyReference.NewObject()); });
     CheckDomainObjectSerializability(delegate { return((Group)LifetimeService.NewObject(ClientTransaction.Current, typeof(Group), ParamList.Empty)); });
     CheckDomainObjectSerializability(delegate { return((GroupType)LifetimeService.NewObject(ClientTransaction.Current, typeof(GroupType), ParamList.Empty)); });
     CheckDomainObjectSerializability(delegate { return(GroupTypePosition.NewObject()); });
     CheckDomainObjectSerializability(delegate { return((Position)LifetimeService.NewObject(ClientTransaction.Current, typeof(Position), ParamList.Empty)); });
     CheckDomainObjectSerializability(delegate { return(Role.NewObject()); });
     CheckDomainObjectSerializability(delegate { return((Tenant)LifetimeService.NewObject(ClientTransaction.Current, typeof(Tenant), ParamList.Empty)); });
     CheckDomainObjectSerializability(delegate { return((User)LifetimeService.NewObject(ClientTransaction.Current, typeof(User), ParamList.Empty)); });
 }