public void Serialization()
        {
            EnumWrapper wrapper             = EnumWrapper.Get("bla", "ble");
            EnumWrapper deserializedWrapper = Serializer.SerializeAndDeserialize(wrapper);

            Assert.That(deserializedWrapper, Is.EqualTo(wrapper));
        }
Example #2
0
        public void Serialization()
        {
            AccessType accessType             = AccessType.Get(EnumWrapper.Get(TestAccessTypes.First));
            AccessType deserializedAccessType = Serializer.SerializeAndDeserialize(accessType);

            Assert.That(deserializedAccessType, Is.EqualTo(accessType));
        }
Example #3
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));
                }
            }
        }
Example #4
0
        public void Test_ToString()
        {
            EnumWrapper wrapper    = EnumWrapper.Get(TestAccessTypes.First);
            AccessType  accessType = AccessType.Get(wrapper);

            Assert.That(accessType.ToString(), Is.EqualTo(wrapper.ToString()));
        }
        public void GetHashCode_EqualObjects()
        {
            EnumWrapper one = EnumWrapper.Get("123");
            EnumWrapper two = EnumWrapper.Get("123");

            Assert.That(one.GetHashCode(), Is.EqualTo(two.GetHashCode()));
        }
Example #6
0
        public void Find_ValidOneAbstractRole()
        {
            var abstractRoles = new[] { EnumWrapper.Get(ProjectRoles.QualityManager) };
            var result        = AbstractRoleDefinition.Find(abstractRoles);

            Assert.That(result.Count, Is.EqualTo(1));
            Assert.That(result[0].Name, Is.EqualTo(abstractRoles[0].Name));
        }
        public void CreateSecurityContextWithAbstractRole()
        {
            Enum[]          abstractRoles = new Enum[] { TestAbstractRoles.QualityEngineer, TestAbstractRoles.Developer };
            SecurityContext context       = CreateTestSecurityContextWithAbstractRoles(abstractRoles);

            Assert.That(
                context.AbstractRoles,
                Is.EquivalentTo(new[] { EnumWrapper.Get(TestAbstractRoles.QualityEngineer), EnumWrapper.Get(TestAbstractRoles.Developer) }));
        }
Example #8
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);
            }
        }
Example #9
0
        private Dictionary <EnumWrapper, IDomainObjectHandle <AbstractRoleDefinition> > LoadAbstractRoles()
        {
            var result = GetOrCreateQuery(
                MethodInfo.GetCurrentMethod(),
                () => from r in QueryFactory.CreateLinqQuery <AbstractRoleDefinition>()
                select new { Key = r.Name, Value = r.ID.GetHandle <AbstractRoleDefinition>() });

            using (CreateStopwatchScopeForQueryExecution("abstract roles"))
            {
                return(result.ToDictionary(r => EnumWrapper.Get(r.Key), r => r.Value));
            }
        }
        public void CreateSecurityContextWithState()
        {
            Dictionary <string, Enum> testStates = new Dictionary <string, Enum>();

            testStates.Add("Confidentiality", TestSecurityState.Public);
            testStates.Add("State", TestSecurityState.Secret);

            SecurityContext context = CreateTestSecurityContextWithStates(testStates);

            Assert.That(context.GetState("Confidentiality"), Is.EqualTo(EnumWrapper.Get(TestSecurityState.Public)));
            Assert.That(context.GetState("State"), Is.EqualTo(EnumWrapper.Get(TestSecurityState.Secret)));
        }
Example #11
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);
            }
        }
Example #12
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);
            }
        }
Example #13
0
        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();
            }
        }
        private XmlElement CreateStatePropertyValueNode(XmlDocument document, EnumValueInfo enumValueInfo)
        {
            XmlElement propertyValueElement = document.CreateElement("state", _metadataSchema.SchemaUri);

            XmlAttribute propertyValueNameAttribute = document.CreateAttribute("name");

            propertyValueNameAttribute.Value = EnumWrapper.Get(enumValueInfo.Name, enumValueInfo.TypeName).Name;

            XmlAttribute propertyValueValueAttribute = document.CreateAttribute("value");

            propertyValueValueAttribute.Value = enumValueInfo.Value.ToString();

            propertyValueElement.Attributes.Append(propertyValueNameAttribute);
            propertyValueElement.Attributes.Append(propertyValueValueAttribute);

            return(propertyValueElement);
        }
Example #15
0
        public List <AccessControlList> CreateAclsForOrderAndPaymentStates(SecurableClassDefinition classDefinition)
        {
            using (_transaction.EnterNonDiscardingScope())
            {
                StatePropertyDefinition orderState   = CreateOrderStateProperty(classDefinition);
                StatePropertyDefinition paymentState = CreatePaymentStateProperty(classDefinition);

                List <AccessControlList> acls = new List <AccessControlList>();
                acls.Add(CreateStatefulAcl(classDefinition, orderState[EnumWrapper.Get(OrderState.Received).Name], paymentState[EnumWrapper.Get(PaymentState.None).Name]));
                acls.Add(CreateStatefulAcl(classDefinition, orderState[EnumWrapper.Get(OrderState.Received).Name], paymentState[EnumWrapper.Get(PaymentState.Paid).Name]));
                acls.Add(CreateStatefulAcl(classDefinition, orderState[EnumWrapper.Get(OrderState.Delivered).Name], paymentState[EnumWrapper.Get(PaymentState.None).Name]));
                acls.Add(CreateStatefulAcl(classDefinition, orderState[EnumWrapper.Get(OrderState.Delivered).Name], paymentState[EnumWrapper.Get(PaymentState.Paid).Name]));
                acls.Add(CreateStatelessAcl(classDefinition));

                return(acls);
            }
        }
Example #16
0
        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);
            }
        }
        private void AppendEnumValueInfoAttributes(XmlDocument document, EnumValueInfo enumValueInfo, XmlElement enumValueElement)
        {
            XmlAttribute enumValueIDAttribute = document.CreateAttribute("id");

            enumValueIDAttribute.Value = enumValueInfo.ID;

            EnumWrapper  enumWrapper            = EnumWrapper.Get(enumValueInfo.Name, enumValueInfo.TypeName);
            XmlAttribute enumValueNameAttribute = document.CreateAttribute("name");

            enumValueNameAttribute.Value = enumWrapper.Name;

            XmlAttribute enumValueValueAttribute = document.CreateAttribute("value");

            enumValueValueAttribute.Value = enumValueInfo.Value.ToString();

            enumValueElement.Attributes.Append(enumValueIDAttribute);
            enumValueElement.Attributes.Append(enumValueNameAttribute);
            enumValueElement.Attributes.Append(enumValueValueAttribute);
        }
Example #18
0
        public void CreateSecurityContext()
        {
            OrganizationalStructureTestHelper testHelper = new OrganizationalStructureTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                Position position = testHelper.CreatePosition("PositionName");
                position.Delegation = Delegation.Enabled;

                ISecurityContext securityContext = ((ISecurityContextFactory)position).CreateSecurityContext();
                Assert.That(Type.GetType(securityContext.Class), Is.EqualTo(position.GetPublicDomainObjectType()));
                Assert.That(securityContext.Owner, Is.Null);
                Assert.That(securityContext.OwnerGroup, Is.Null);
                Assert.That(securityContext.OwnerTenant, Is.Null);
                Assert.That(securityContext.AbstractRoles, Is.Empty);
                Assert.That(securityContext.GetNumberOfStates(), Is.EqualTo(1));
                Assert.That(securityContext.GetState("Delegation"), Is.EqualTo(EnumWrapper.Get(Delegation.Enabled)));
            }
        }
Example #19
0
        public void ValidateDuringCommit()
        {
            SecurableClassDefinition orderClass      = _testHelper.CreateOrderClassDefinition();
            StatePropertyDefinition  paymentProperty = _testHelper.CreatePaymentStateProperty(orderClass);
            StateDefinition          paidState       = paymentProperty[EnumWrapper.Get(PaymentState.Paid).Name];
            StateDefinition          notPaidState    = paymentProperty[EnumWrapper.Get(PaymentState.None).Name];

            _testHelper.CreateStateCombination(orderClass, paidState);
            _testHelper.CreateStateCombination(orderClass, notPaidState);
            _testHelper.CreateStateCombination(orderClass);
            var dupicateStateCombination = orderClass.CreateStatefulAccessControlList().StateCombinations[0];

            using (ClientTransaction.Current.CreateSubTransaction().EnterDiscardingScope())
            {
                dupicateStateCombination.AttachState(paidState);

                ClientTransaction.Current.Commit();
            }
        }
Example #20
0
        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));
            }
        }
Example #21
0
        public List <StateDefinition> GetDeliveredAndUnpaidStateList(SecurableClassDefinition classDefinition)
        {
            using (_transaction.EnterNonDiscardingScope())
            {
                List <StateDefinition> states = new List <StateDefinition>();

                foreach (StatePropertyDefinition property in classDefinition.StateProperties)
                {
                    if (property.Name == "State")
                    {
                        states.Add(property[EnumWrapper.Get(OrderState.Delivered).Name]);
                    }

                    if (property.Name == "Payment")
                    {
                        states.Add(property[EnumWrapper.Get(PaymentState.None).Name]);
                    }
                }

                return(states);
            }
        }
Example #22
0
        public void ValidateDuringCommit_ByTouchOnClassForChangedStateUsagesCollection()
        {
            SecurableClassDefinition orderClass      = _testHelper.CreateOrderClassDefinition();
            StatePropertyDefinition  paymentProperty = _testHelper.CreatePaymentStateProperty(orderClass);
            StateDefinition          paidState       = paymentProperty[EnumWrapper.Get(PaymentState.Paid).Name];
            StateDefinition          notPaidState    = paymentProperty[EnumWrapper.Get(PaymentState.None).Name];
            StateCombination         combination1    = _testHelper.CreateStateCombination(orderClass, paidState);
            StateCombination         combination2    = _testHelper.CreateStateCombination(orderClass, notPaidState);
            StateCombination         combination3    = _testHelper.CreateStateCombination(orderClass);

            combination1.AccessControlList.AccessControlEntries.Add(AccessControlEntry.NewObject());
            combination2.AccessControlList.AccessControlEntries.Add(AccessControlEntry.NewObject());
            combination3.AccessControlList.AccessControlEntries.Add(AccessControlEntry.NewObject());
            var dupicateStateCombination = orderClass.CreateStatefulAccessControlList().StateCombinations[0];

            using (_testHelper.Transaction.CreateSubTransaction().EnterDiscardingScope())
            {
                dupicateStateCombination.AttachState(paidState);

                ClientTransaction.Current.Commit();
            }
        }
Example #23
0
        public void OnCommitting_WithChangedStateUsage_RegistersClassForCommit()
        {
            var classDefinition = _testHelper.CreateOrderClassDefinition();
            var property        = _testHelper.CreatePaymentStateProperty(classDefinition);
            var state           = property[EnumWrapper.Get(PaymentState.Paid).Name];
            var combination     = _testHelper.CreateStateCombination(classDefinition);

            using (ClientTransaction.Current.CreateSubTransaction().EnterDiscardingScope())
            {
                bool commitOnClassWasCalled = false;
                classDefinition.Committing += (sender, e) =>
                {
                    commitOnClassWasCalled = true;
                    Assert.That(GetDataContainer((DomainObject)sender).HasBeenMarkedChanged, Is.True);
                };
                combination.AttachState(state);

                ClientTransaction.Current.Commit();

                Assert.That(commitOnClassWasCalled, Is.True);
            }
        }
Example #24
0
        public void DuplicateStateCombinations_TwoInvalidStateCombinations()
        {
            AccessControlTestHelper testHelper = new AccessControlTestHelper();

            using (testHelper.Transaction.EnterNonDiscardingScope())
            {
                SecurableClassDefinition orderClass           = testHelper.CreateOrderClassDefinition();
                StatePropertyDefinition  paymentProperty      = testHelper.CreatePaymentStateProperty(orderClass);
                StateCombination         statelessCombination = testHelper.CreateStateCombination(orderClass);
                StateCombination         paidStateCombination = testHelper.CreateStateCombination(
                    orderClass, paymentProperty[EnumWrapper.Get(PaymentState.Paid).Name]);

                SecurableClassValidationResult result = new SecurableClassValidationResult();

                result.AddDuplicateStateCombination(statelessCombination);
                result.AddDuplicateStateCombination(paidStateCombination);

                Assert.That(result.DuplicateStateCombinations.Count, Is.EqualTo(2));
                Assert.That(result.DuplicateStateCombinations, Has.Member(statelessCombination));
                Assert.That(result.DuplicateStateCombinations, Has.Member(paidStateCombination));
            }
        }
        public void CreateSecurityContextFromEnumWrappers()
        {
            var abstractRoles = new[] { EnumWrapper.Get(TestAbstractRoles.QualityEngineer), EnumWrapper.Get(SimpleEnum.Second), EnumWrapper.Get("Role") };
            var states        = new Dictionary <string, EnumWrapper>();

            states.Add("property1", EnumWrapper.Get(TestSecurityState.Confidential));
            states.Add("property2", EnumWrapper.Get(SimpleEnum.First));
            states.Add("property3", EnumWrapper.Get("State"));

            SecurityContext context = SecurityContext.Create(typeof(ISecurableObject), "owner", "group", "tenant", states, abstractRoles);

            Assert.That(context.Owner, Is.EqualTo("owner"));
            Assert.That(context.OwnerGroup, Is.EqualTo("group"));
            Assert.That(context.OwnerTenant, Is.EqualTo("tenant"));

            Assert.That(context.AbstractRoles, Is.Not.SameAs(abstractRoles));
            Assert.That(context.AbstractRoles, Is.EquivalentTo(abstractRoles));

            Assert.That(context.GetNumberOfStates(), Is.EqualTo(3));
            Assert.That(context.GetState("property1"), Is.EqualTo(states["property1"]));
            Assert.That(context.GetState("property2"), Is.EqualTo(states["property2"]));
            Assert.That(context.GetState("property3"), Is.EqualTo(states["property3"]));
        }
        private LocalizedName CreateLocalizedNameFromEnumValueInfo(EnumValueInfo enumValueInfo, string text)
        {
            EnumWrapper enumWrapper = EnumWrapper.Get(enumValueInfo.Name, enumValueInfo.TypeName);

            return(new LocalizedName(enumValueInfo.ID, enumWrapper.ToString(), enumValueInfo.Name));
        }
 public void Equatable_Equals_False()
 {
     Assert.That(EnumWrapper.Get("123").Equals(EnumWrapper.Get("321")), Is.False);
 }
 public void Equatable_Equals_True()
 {
     Assert.That(EnumWrapper.Get("123").Equals(EnumWrapper.Get("123")), Is.True);
 }
 public void Equals_False_WithDifferentType()
 {
     Assert.That(EnumWrapper.Get("123").Equals("123"), Is.False);
 }
 public void Equals_False_WithNull()
 {
     Assert.That(EnumWrapper.Get("123").Equals(null), Is.False);
 }