public void RemovesPermissionsForRemovedAccessType() { var accessType0 = AccessTypeDefinition.NewObject(); var accessType1 = AccessTypeDefinition.NewObject(); var accessType2 = AccessTypeDefinition.NewObject(); var securableClassDefinition = SecurableClassDefinition.NewObject(); securableClassDefinition.AddAccessType(accessType0); securableClassDefinition.AddAccessType(accessType1); securableClassDefinition.AddAccessType(accessType2); var testHelper = new AccessControlTestHelper(ClientTransaction.Current); var acls = new List <AccessControlList>(); acls.Add(testHelper.CreateStatefulAcl(securableClassDefinition)); acls.Add(testHelper.CreateStatelessAcl(securableClassDefinition)); foreach (var acl in acls) { acl.CreateAccessControlEntry(); } securableClassDefinition.RemoveAccessType(accessType1); foreach (var acl in acls) { var permissions = acl.AccessControlEntries[0].GetPermissions(); Assert.That(permissions.Count, Is.EqualTo(2)); Assert.That(permissions[0].AccessType, Is.SameAs(accessType0)); Assert.That(permissions[1].AccessType, Is.SameAs(accessType2)); } }
public void LeavesPermissionsUntouched() { var accessType0 = AccessTypeDefinition.NewObject(); var accessType1 = AccessTypeDefinition.NewObject(); var securableClassDefinition = SecurableClassDefinition.NewObject(); securableClassDefinition.AddAccessType(accessType0); securableClassDefinition.AddAccessType(accessType1); var testHelper = new AccessControlTestHelper(ClientTransaction.Current); var acls = new List <AccessControlList>(); acls.Add(testHelper.CreateStatefulAcl(securableClassDefinition)); acls.Add(testHelper.CreateStatelessAcl(securableClassDefinition)); foreach (var acl in acls) { var ace = acl.CreateAccessControlEntry(); ace.DenyAccess(accessType0); ace.AllowAccess(accessType1); } securableClassDefinition.MoveAccessType(0, accessType1); foreach (var acl in acls) { var permissions = acl.AccessControlEntries[0].GetPermissions(); Assert.That(permissions.Count, Is.EqualTo(2)); Assert.That(permissions[0].AccessType, Is.SameAs(accessType1)); Assert.That(permissions[0].Allowed, Is.True); Assert.That(permissions[1].AccessType, Is.SameAs(accessType0)); Assert.That(permissions[1].Allowed, Is.False); } }
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 override void SetUp() { base.SetUp(); AccessControlTestHelper testHelper = new AccessControlTestHelper(); _testHelper = testHelper; _testHelper.Transaction.EnterNonDiscardingScope(); }
public void GetStatePropertyTest_InvalidName() { AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition(); Assert.That(orderClass.GetStateProperty("Invalid"), Is.Null); } }
public void StateProperties_IsReadOnly() { AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinitionWithProperties(); Assert.That(((ICollection <StatePropertyDefinition>)orderClass.StateProperties).IsReadOnly, Is.True); } }
public void AccessTypes_Empty() { AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition(); Assert.That(orderClass.AccessTypes, Is.Empty); } }
public void StateProperties_OrderStateAndPaymentState() { AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinitionWithProperties(); Assert.That(orderClass.StateProperties.Count, Is.EqualTo(AccessControlTestHelper.OrderClassPropertyCount)); } }
public override void SetUp() { base.SetUp(); _aceClass = BindableObjectProviderTestHelper.GetBindableObjectClass(typeof(AccessControlEntry)); _testHelper = new AccessControlTestHelper(); _testHelper.Transaction.EnterNonDiscardingScope(); _ace = AccessControlEntry.NewObject(); }
public void AccessTypes_IsReadOnly() { AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition(); testHelper.AttachJournalizeAccessType(orderClass); Assert.That(((ICollection <AccessTypeDefinition>)orderClass.AccessTypes).IsReadOnly, Is.True); } }
public void AccessTypes_OneAccessType() { AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition(); testHelper.AttachJournalizeAccessType(orderClass); Assert.That(orderClass.AccessTypes.Count, Is.EqualTo(1)); } }
public void GetStateCombinations_TwoCombinations() { AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition(); StateCombination stateCombination = testHelper.CreateStateCombination(orderClass); List <StateCombination> stateCombinations = testHelper.CreateOrderStateAndPaymentStateCombinations(orderClass); Assert.That(orderClass.StateCombinations, Is.EqualTo(ArrayUtility.Combine(stateCombination, stateCombinations.ToArray()))); } }
public void Commit_EmptyStateCombinationInClassWithStateProperties() { AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition(); testHelper.CreateOrderStateAndPaymentStateCombinations(orderClass); testHelper.CreateStateCombination(orderClass); testHelper.Transaction.Commit(); } }
public void SetUp() { try { // Use default localization for tests AclToolsExpansion.Culture = new CultureInfo(""); AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterDiscardingScope()) { _dbFixtures = new DatabaseFixtures(); _dbFixtures.CreateAndCommitOrganizationalStructureWithTwoTenants(ClientTransaction.Current); _cultureDe = Culture.NewObject("de-DE"); _cultureEn = Culture.NewObject("en-US"); SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition(); OrderClassHandle = orderClass.GetHandle(); testHelper.AttachAccessType(orderClass, Guid.NewGuid(), "FirstAccessType", 0); testHelper.AttachAccessType(orderClass, Guid.NewGuid(), "FirstAccessType2", 2); testHelper.AttachAccessType(orderClass, Guid.NewGuid(), "FirstAccessType3", 3); aclList = testHelper.CreateAclsForOrderAndPaymentAndDeliveryStates(orderClass); var ace = aclList[0].CreateAccessControlEntry(); ace.GetPermissions()[0].Allowed = true; // FirstAccessType testHelper.CreateInvoiceClassDefinition(); LocalizeClassEnDe(orderClass, "Order", "Bestellung"); LocalizeStatePropertyEnDe(orderClass, "Payment", "Payment", "Bezahlstatus"); LocalizeStateEnDe(orderClass, "Payment", (int)PaymentState.None, "None", "Offen"); LocalizeStateEnDe(orderClass, "Payment", (int)PaymentState.Paid, "Paid", "Bezahlt"); LocalizeStatePropertyEnDe(orderClass, "State", "Order State", "Bestellstatus"); LocalizeStateEnDe(orderClass, "State", (int)OrderState.Delivered, "Delivered", "Ausgelifert"); LocalizeStateEnDe(orderClass, "State", (int)OrderState.Received, "Received", "Erhalten"); LocalizeStatePropertyEnDe(orderClass, "Delivery", "Delivery Provider", "Auslieferer"); LocalizeStateEnDe(orderClass, "Delivery", (int)Delivery.Dhl, "DHL", "DHL"); LocalizeStateEnDe(orderClass, "Delivery", (int)Delivery.Post, "Mail", "Post"); ClientTransaction.Current.Commit(); } } catch (Exception e) { Console.WriteLine(e); throw; } }
public void StateProperties_IsNotCached() { AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinitionWithProperties(); var firstCollection = orderClass.StateProperties; var secondCollection = orderClass.StateProperties; Assert.That(secondCollection, Is.Not.SameAs(firstCollection)); } }
public void ValidateUniqueStateCombinations_NoStateCombinations() { AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition(); SecurableClassValidationResult result = new SecurableClassValidationResult(); orderClass.ValidateUniqueStateCombinations(result); Assert.That(result.IsValid, Is.True); } }
public void Validate_Valid() { AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition(); testHelper.CreateOrderStateAndPaymentStateCombinations(orderClass); SecurableClassValidationResult result = orderClass.Validate(); Assert.That(result.IsValid, Is.True); } }
public void AccessTypes_IsNotCached() { AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition(); testHelper.AttachJournalizeAccessType(orderClass); var firstCollection = orderClass.AccessTypes; var secondCollection = orderClass.AccessTypes; Assert.That(secondCollection, Is.Not.SameAs(firstCollection)); } }
public void Commit_TwoStateCombinations() { AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition(); StatePropertyDefinition paymentProperty = testHelper.CreatePaymentStateProperty(orderClass); testHelper.CreateStateCombination(orderClass, paymentProperty[EnumWrapper.Get(PaymentState.Paid).Name]); testHelper.CreateStateCombination(orderClass, paymentProperty[EnumWrapper.Get(PaymentState.Paid).Name]); testHelper.CreateStateCombination(orderClass, paymentProperty[EnumWrapper.Get(PaymentState.None).Name]); testHelper.Transaction.Commit(); } }
public void GetStatePropertyTest_ValidName() { 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; Assert.That(orderClass.GetStateProperty(orderStateProperty.Name), Is.EqualTo(orderStateProperty)); Assert.That(orderClass.GetStateProperty(paymentProperty.Name), Is.EqualTo(paymentProperty)); } }
public void IsValid_DuplicateStateCombination() { AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition(); StateCombination stateCombination = testHelper.CreateStateCombination(orderClass); SecurableClassValidationResult result = new SecurableClassValidationResult(); result.AddDuplicateStateCombination(stateCombination); Assert.That(result.IsValid, Is.False); } }
public void DuplicateStateCombinations_OneInvalidStateCombination() { AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition(); StateCombination stateCombination = testHelper.CreateStateCombination(orderClass); SecurableClassValidationResult result = new SecurableClassValidationResult(); result.AddDuplicateStateCombination(stateCombination); Assert.That(result.DuplicateStateCombinations.Count, Is.EqualTo(1)); Assert.That(result.DuplicateStateCombinations, Has.Member(stateCombination)); } }
public void ValidateStateCombinationsAgainstStateProperties_EmptyStateCombinationInClassWithStateProperties() { AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition(); testHelper.CreateOrderStateAndPaymentStateCombinations(orderClass); StateCombination statelessCombination = testHelper.CreateStateCombination(orderClass); SecurableClassValidationResult result = new SecurableClassValidationResult(); orderClass.ValidateStateCombinationsAgainstStateProperties(result); Assert.That(result.IsValid, Is.False); Assert.That(result.InvalidStateCombinations, Is.EquivalentTo(new[] { statelessCombination })); } }
public void ValidateUniqueStateCombinations_TwoEmptyStateCombinations() { AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition(); StateCombination statelessCombination1 = testHelper.CreateStateCombination(orderClass); StateCombination statelessCombination2 = testHelper.CreateStateCombination(orderClass); SecurableClassValidationResult result = new SecurableClassValidationResult(); orderClass.ValidateUniqueStateCombinations(result); Assert.That(result.IsValid, Is.False); Assert.That(result.DuplicateStateCombinations, Has.Member(statelessCombination1)); Assert.That(result.DuplicateStateCombinations, Has.Member(statelessCombination2)); } }
public void DeleteGroupType_WithAccessControlEntry() { DatabaseFixtures dbFixtures = new DatabaseFixtures(); AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { dbFixtures.CreateEmptyDomain(); GroupType groupType = testHelper.CreateGroupType("GroupType"); AccessControlEntry ace = testHelper.CreateAceWithBranchOfOwningGroup(groupType); ClientTransaction.Current.Commit(); groupType.Delete(); ClientTransaction.Current.Commit(); Assert.That(ace.State, Is.EqualTo(StateType.Invalid)); } }
public void Validate_DoubleStateCombination() { 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; testHelper.CreateStateCombination( orderClass, orderStateProperty[EnumWrapper.Get(OrderState.Received).Name], paymentProperty[EnumWrapper.Get(PaymentState.Paid).Name]); SecurableClassValidationResult result = orderClass.Validate(); Assert.That(result.IsValid, Is.False); } }
public void DeleteGroup_WithAccessControlEntry() { DatabaseFixtures dbFixtures = new DatabaseFixtures(); AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { dbFixtures.CreateEmptyDomain(); var group = testHelper.CreateGroup("group", null, testHelper.CreateTenant("tenant")); var ace = testHelper.CreateAceWithSpecificGroup(group); ClientTransaction.Current.Commit(); group.Delete(); ClientTransaction.Current.Commit(); Assert.That(ace.State, Is.EqualTo(StateType.Invalid)); } }
public void CascadeToAccessControlEntry() { DatabaseFixtures dbFixtures = new DatabaseFixtures(); AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { dbFixtures.CreateEmptyDomain(); var tenant = testHelper.CreateTenant("TestTenant"); var owningGroup = testHelper.CreateGroup("group", null, tenant); var user = testHelper.CreateUser("user", null, "user", null, owningGroup, tenant); var ace = testHelper.CreateAceWithSpecificUser(user); ClientTransaction.Current.Commit(); user.Delete(); ClientTransaction.Current.Commit(); Assert.That(ace.State, Is.EqualTo(StateType.Invalid)); } }
public void ValidateUniqueStateCombinations_TwoStateCombinations() { AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { SecurableClassDefinition orderClass = testHelper.CreateOrderClassDefinition(); StatePropertyDefinition paymentProperty = testHelper.CreatePaymentStateProperty(orderClass); StateCombination paidCombination1 = testHelper.CreateStateCombination(orderClass, paymentProperty[EnumWrapper.Get(PaymentState.Paid).Name]); StateCombination paidCombination2 = testHelper.CreateStateCombination(orderClass, paymentProperty[EnumWrapper.Get(PaymentState.Paid).Name]); testHelper.CreateStateCombination(orderClass, paymentProperty[EnumWrapper.Get(PaymentState.None).Name]); SecurableClassValidationResult result = new SecurableClassValidationResult(); orderClass.ValidateUniqueStateCombinations(result); Assert.That(result.IsValid, Is.False); Assert.That(result.DuplicateStateCombinations.Count, Is.EqualTo(2)); Assert.That(result.DuplicateStateCombinations, Has.Member(paidCombination1)); Assert.That(result.DuplicateStateCombinations, Has.Member(paidCombination2)); } }
public void DeletePosition_WithAccessControlEntry() { DatabaseFixtures dbFixtures = new DatabaseFixtures(); AccessControlTestHelper testHelper = new AccessControlTestHelper(); using (testHelper.Transaction.EnterNonDiscardingScope()) { Tenant tenant = dbFixtures.CreateAndCommitOrganizationalStructureWithTwoTenants(ClientTransaction.Current); User user = User.FindByTenant(tenant.GetHandle()).First(); Role role = user.Roles[0]; Position position = role.Position; AccessControlEntry ace = testHelper.CreateAceWithPosition(position); ClientTransaction.Current.Commit(); position.Delete(); ClientTransaction.Current.Commit(); Assert.That(ace.State, Is.EqualTo(StateType.Invalid)); } }