Beispiel #1
0
        private void CreateStateCombination(StatefulAccessControlList acl, StatePropertyDefinition stateProperty, StateDefinition stateDefinition)
        {
            StateCombination stateCombination = acl.CreateStateCombination();

            stateProperty.AddState(stateDefinition);
            stateCombination.AttachState(stateDefinition);
        }
Beispiel #2
0
 public StatePropertyDefinition CreateNewStateProperty(string name)
 {
     using (_transaction.EnterNonDiscardingScope())
     {
         return(StatePropertyDefinition.NewObject(Guid.NewGuid(), name));
     }
 }
Beispiel #3
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 #4
0
        public void ValidateUniqueStateCombinations_DoubleStateCombinationAndObjectIsDeleted()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass        = testHelper.CreateOrderClassDefinition();
                List <StateCombination>  stateCombinations = testHelper.CreateOrderStateAndPaymentStateCombinations(orderClass);
                var states = stateCombinations[0].GetStates();
                StatePropertyDefinition orderStateProperty = states[0].StateProperty;
                StatePropertyDefinition paymentProperty    = states[1].StateProperty;

                using (ClientTransaction.Current.CreateSubTransaction().EnterDiscardingScope())
                {
                    testHelper.CreateStateCombination(
                        orderClass,
                        ClientTransaction.Current,
                        orderStateProperty[EnumWrapper.Get(OrderState.Received).Name],
                        paymentProperty[EnumWrapper.Get(PaymentState.Paid).Name]);
                    Assert.That(orderClass.StateCombinations, Is.Not.Empty);
                    orderClass.Delete();

                    SecurableClassValidationResult result = new SecurableClassValidationResult();
                    orderClass.ValidateUniqueStateCombinations(result);

                    Assert.That(result.IsValid, Is.True);
                    Assert.That(orderClass.State, Is.EqualTo(StateType.Deleted));
                }
            }
        }
Beispiel #5
0
        public void GetState_InvalidName()
        {
            StatePropertyDefinition stateProperty = _testHelper.CreateConfidentialityProperty(0);

            Assert.That(
                () => stateProperty.GetState("New"),
                Throws.ArgumentException.And.Message.StartsWith("The state 'New' is not defined for the property 'Confidentiality'."));
        }
Beispiel #6
0
        public void GetState_InvalidValue()
        {
            StatePropertyDefinition stateProperty = _testHelper.CreateConfidentialityProperty(0);

            Assert.That(
                () => stateProperty.GetState(42),
                Throws.ArgumentException.And.Message.StartsWith("A state with the value 42 is not defined for the property 'Confidentiality'."));
        }
Beispiel #7
0
        public void AttachState_WithoutClassDefinition()
        {
            StateCombination        combination = StateCombination.NewObject();
            StatePropertyDefinition property    = _testHelper.CreateTestProperty();

            combination.AttachState(property["Test1"]);

            Assert.That(combination.GetStates().Length, Is.EqualTo(1));
        }
Beispiel #8
0
        public void AddsStateProperty()
        {
            var stateProperty            = StatePropertyDefinition.NewObject();
            var securableClassDefinition = SecurableClassDefinition.NewObject();

            securableClassDefinition.AddStateProperty(stateProperty);

            Assert.That(securableClassDefinition.StateProperties, Is.EqualTo(new[] { stateProperty }));
        }
Beispiel #9
0
        public void GetState_ValidValue()
        {
            StatePropertyDefinition stateProperty = _testHelper.CreateConfidentialityProperty(0);

            StateDefinition actualState = stateProperty.GetState(MetadataTestHelper.Confidentiality_PrivateValue);

            StateDefinition expectedState = _testHelper.CreatePrivateState();

            MetadataObjectAssert.AreEqual(expectedState, actualState, "Private state");
        }
Beispiel #10
0
        public void RemoveState_StateNotFound()
        {
            StatePropertyDefinition stateProperty = _testHelper.CreateNewStateProperty("NewProperty");

            stateProperty.AddState(_testHelper.CreateState("State 1", 1));

            Assert.That(
                () => stateProperty.RemoveState(_testHelper.CreateState("State 2", 2)),
                Throws.ArgumentException.And.Message.StartsWith("The state 'State 2' does not exist on the property 'NewProperty'."));
        }
Beispiel #11
0
        public void AddState_DuplicateValue()
        {
            StatePropertyDefinition stateProperty = _testHelper.CreateNewStateProperty("NewProperty");

            stateProperty.AddState(_testHelper.CreateState("State 1", 1));

            Assert.That(
                () => stateProperty.AddState(_testHelper.CreateState("State 2", 1)),
                Throws.ArgumentException.And.Message.StartsWith("A state with the value 1 was already added to the property 'NewProperty'."));
        }
Beispiel #12
0
        public void Indexer_ValidName()
        {
            StatePropertyDefinition stateProperty = _testHelper.CreateConfidentialityProperty(0);

            StateDefinition actualState = stateProperty[MetadataTestHelper.Confidentiality_ConfidentialName];

            StateDefinition expectedState = _testHelper.CreateConfidentialState();

            MetadataObjectAssert.AreEqual(expectedState, actualState, "Confidential state");
        }
Beispiel #13
0
        public void GetHashCode_OneStatelessAndOneWithAState()
        {
            SecurableClassDefinition orderClass      = _testHelper.CreateOrderClassDefinition();
            StatePropertyDefinition  paymentProperty = _testHelper.CreatePaymentStateProperty(orderClass);
            StateCombination         combination1    = _testHelper.CreateStateCombination(orderClass);
            StateCombination         combination2    = _testHelper.CreateStateCombination(orderClass, paymentProperty[EnumWrapper.Get(PaymentState.Paid).Name]);

            StateCombinationComparer comparer = new StateCombinationComparer();

            Assert.That(comparer.GetHashCode(combination2), Is.Not.EqualTo(comparer.GetHashCode(combination1)));
        }
Beispiel #14
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 #15
0
        public void AddState()
        {
            var state1 = _testHelper.CreateState("State 1", 1);
            var state2 = _testHelper.CreateState("State 2", 2);
            StatePropertyDefinition stateProperty = _testHelper.CreateNewStateProperty("NewProperty");

            stateProperty.AddState(state1);
            stateProperty.AddState(state2);

            Assert.That(stateProperty.DefinedStates, Is.EqualTo(new[] { state1, state2 }));
        }
Beispiel #16
0
        public StatePropertyDefinition CreateTestProperty()
        {
            using (_transaction.EnterNonDiscardingScope())
            {
                StatePropertyDefinition property = CreateStateProperty("Test");
                property.AddState(CreateState("Test1", 0));
                property.AddState(CreateState("Test2", 1));

                return(property);
            }
        }
Beispiel #17
0
        public void Equals_TwoDifferent()
        {
            SecurableClassDefinition orderClass      = _testHelper.CreateOrderClassDefinition();
            StatePropertyDefinition  paymentProperty = _testHelper.CreatePaymentStateProperty(orderClass);
            StateCombination         combination1    = _testHelper.CreateStateCombination(orderClass, paymentProperty[EnumWrapper.Get(PaymentState.None).Name]);
            StateCombination         combination2    = _testHelper.CreateStateCombination(orderClass, paymentProperty[EnumWrapper.Get(PaymentState.Paid).Name]);

            StateCombinationComparer comparer = new StateCombinationComparer();

            Assert.That(comparer.Equals(combination1, combination2), Is.False);
        }
Beispiel #18
0
        public StatePropertyDefinition CreateOrderStateProperty(SecurableClassDefinition classDefinition)
        {
            using (_transaction.EnterNonDiscardingScope())
            {
                StatePropertyDefinition orderStateProperty = CreateStateProperty("State");
                orderStateProperty.AddState(CreateState(EnumWrapper.Get(OrderState.Received).Name, 0));
                orderStateProperty.AddState(CreateState(EnumWrapper.Get(OrderState.Delivered).Name, 1));
                classDefinition.AddStateProperty(orderStateProperty);

                return(orderStateProperty);
            }
        }
Beispiel #19
0
        public void GetStates_OneState()
        {
            SecurableClassDefinition classDefinition = _testHelper.CreateOrderClassDefinition();
            StatePropertyDefinition  property        = _testHelper.CreatePaymentStateProperty(classDefinition);
            StateDefinition          state           = property.DefinedStates[1];
            StateCombination         combination     = _testHelper.CreateStateCombination(classDefinition, state);

            StateDefinition[] states = combination.GetStates();

            Assert.That(states.Length, Is.EqualTo(1));
            Assert.That(states[0], Is.SameAs(state));
        }
Beispiel #20
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 #21
0
        public StatePropertyDefinition CreatePaymentStateProperty(SecurableClassDefinition classDefinition)
        {
            using (_transaction.EnterNonDiscardingScope())
            {
                StatePropertyDefinition paymentStateProperty = CreateStateProperty("Payment");
                paymentStateProperty.AddState(CreateState(EnumWrapper.Get(PaymentState.None).Name, 0));
                paymentStateProperty.AddState(CreateState(EnumWrapper.Get(PaymentState.Paid).Name, 1));
                classDefinition.AddStateProperty(paymentStateProperty);

                return(paymentStateProperty);
            }
        }
Beispiel #22
0
        public StatePropertyDefinition CreateDeliveryStateProperty(SecurableClassDefinition classDefinition)
        {
            using (_transaction.EnterNonDiscardingScope())
            {
                StatePropertyDefinition deliveryStateProperty = CreateStateProperty("Delivery");
                deliveryStateProperty.AddState(CreateState(EnumWrapper.Get(Delivery.Dhl).Name, 0));
                deliveryStateProperty.AddState(CreateState(EnumWrapper.Get(Delivery.Post).Name, 1));
                classDefinition.AddStateProperty(deliveryStateProperty);

                return(deliveryStateProperty);
            }
        }
Beispiel #23
0
        public void ClearStates()
        {
            SecurableClassDefinition classDefinition = _testHelper.CreateOrderClassDefinition();
            StateCombination         combination     = _testHelper.CreateStateCombination(classDefinition);
            StatePropertyDefinition  property        = _testHelper.CreateTestProperty();

            combination.AttachState(property["Test1"]);
            Assert.That(combination.GetStates(), Is.Not.Empty);

            combination.ClearStates();

            Assert.That(combination.GetStates(), Is.Empty);
        }
Beispiel #24
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 #25
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 #26
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 #27
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 #28
0
        public static void AreEqual(StatePropertyDefinition expected, StatePropertyDefinition actual, string message)
        {
            Assert.AreEqual(expected.MetadataItemID, actual.MetadataItemID, message);
            Assert.AreEqual(expected.Name, actual.Name, message);
            Assert.AreEqual(expected.Index, actual.Index, message);

            Assert.AreEqual(expected.DefinedStates.Count, actual.DefinedStates.Count, message);

            for (int i = 0; i < expected.DefinedStates.Count; i++)
            {
                AreEqual(expected.DefinedStates[i], actual.DefinedStates[i], message);
            }
        }
Beispiel #29
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 #30
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));
            }
        }