private void CreateStateCombination(StatefulAccessControlList acl, StatePropertyDefinition stateProperty, StateDefinition stateDefinition) { StateCombination stateCombination = acl.CreateStateCombination(); stateProperty.AddState(stateDefinition); stateCombination.AttachState(stateDefinition); }
public StatePropertyDefinition CreateNewStateProperty(string name) { using (_transaction.EnterNonDiscardingScope()) { return(StatePropertyDefinition.NewObject(Guid.NewGuid(), name)); } }
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); } }
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)); } } }
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'.")); }
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'.")); }
public void AttachState_WithoutClassDefinition() { StateCombination combination = StateCombination.NewObject(); StatePropertyDefinition property = _testHelper.CreateTestProperty(); combination.AttachState(property["Test1"]); Assert.That(combination.GetStates().Length, Is.EqualTo(1)); }
public void AddsStateProperty() { var stateProperty = StatePropertyDefinition.NewObject(); var securableClassDefinition = SecurableClassDefinition.NewObject(); securableClassDefinition.AddStateProperty(stateProperty); Assert.That(securableClassDefinition.StateProperties, Is.EqualTo(new[] { stateProperty })); }
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"); }
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'.")); }
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'.")); }
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"); }
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))); }
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); }
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 })); }
public StatePropertyDefinition CreateTestProperty() { using (_transaction.EnterNonDiscardingScope()) { StatePropertyDefinition property = CreateStateProperty("Test"); property.AddState(CreateState("Test1", 0)); property.AddState(CreateState("Test2", 1)); return(property); } }
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); }
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); } }
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)); }
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.")); }
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); } }
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); } }
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); }
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); } }
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); } }
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.")); }
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 })); }
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); } }
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); } }
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)); } }