Esempio n. 1
0
        public IconProxy GetIcon(string businessObjectClass, string businessObject, string arguments)
        {
            if (businessObjectClass == null)
            {
                return(null);
            }

            Type type = TypeUtility.GetType(businessObjectClass, true);
            var  businessObjectProvider = BindableObjectProvider.GetProviderForBindableObjectType(type);
            var  bindableObjectClass    = businessObjectProvider.GetBindableObjectClass(type);
            IBusinessObjectWithIdentity businessObjectWithIdentity = null;

            if (!string.IsNullOrEmpty(businessObject))
            {
                var businessObjectClassWithIdentity = (IBusinessObjectClassWithIdentity)bindableObjectClass;
                businessObjectWithIdentity = businessObjectClassWithIdentity.GetObject(businessObject);
            }

            var iconInfo = BusinessObjectBoundWebControl.GetIcon(businessObjectWithIdentity, bindableObjectClass.BusinessObjectProvider);

            if (iconInfo != null)
            {
                return(IconProxy.Create(new HttpContextWrapper(Context), iconInfo));
            }

            return(null);
        }
Esempio n. 2
0
        private IBusinessObjectReferenceProperty GetBusinessObjectProperty(Type bindableObjectType, string propertyName)
        {
            var provider            = BindableObjectProvider.GetProviderForBindableObjectType(bindableObjectType);
            var bindableObjectClass = provider.GetBindableObjectClass(bindableObjectType);

            return((IBusinessObjectReferenceProperty)bindableObjectClass.GetPropertyDefinition(propertyName));
        }
        public void NullabilityResolvedFromAboveInheritanceRoot()
        {
            var provider            = BindableObjectProvider.GetProviderForBindableObjectType(typeof(BindableDomainObjectAboveInheritanceRoot));
            var businessObjectClass = provider.GetBindableObjectClass(typeof(BindableDomainObjectAboveInheritanceRoot));

            var notNullableBooleanProperty = businessObjectClass.GetPropertyDefinition("NotNullableBooleanProperty");

            Assert.That(notNullableBooleanProperty.IsRequired, Is.True);

            var notNullableStringProperty = businessObjectClass.GetPropertyDefinition("NotNullableStringPropertyWithLengthConstraint");

            Assert.That(notNullableStringProperty.IsRequired, Is.True);

            var notNullableRelationProperty = businessObjectClass.GetPropertyDefinition("MandatoryUnidirectionalRelation");

            Assert.That(notNullableRelationProperty.IsRequired, Is.True);

            var nullableBooleanProperty = businessObjectClass.GetPropertyDefinition("NullableBooleanProperty");

            Assert.That(nullableBooleanProperty.IsRequired, Is.False);

            var nullableStringProperty = businessObjectClass.GetPropertyDefinition("NullableStringPropertyWithoutLengthConstraint");

            Assert.That(nullableStringProperty.IsRequired, Is.False);

            var nullableRelationProperty = businessObjectClass.GetPropertyDefinition("NotMandatoryUnidirectionalRelation");

            Assert.That(nullableRelationProperty.IsRequired, Is.False);
        }
        public void GetProviderForBindableObjectType()
        {
            BindableObjectProvider provider = BindableObjectProvider.GetProviderForBindableObjectType(typeof(SimpleBusinessObjectClass));

            Assert.That(provider, Is.Not.Null);
            Assert.That(provider, Is.SameAs(BusinessObjectProvider.GetProvider(typeof(BindableObjectProviderAttribute))));
        }
        public void UseBindableObjectProvider_WithBaseClass()
        {
            IBusinessObjectReferenceProperty property = new ReferenceProperty(
                new PropertyBase.Parameters(
                    _bindableObjectProvider,
                    GetPropertyInfo(typeof(ClassWithReferenceToClassDerivedFromBindableObjectBase), "ScalarReference"),
                    typeof(ClassDerivedFromBindableObjectBase),
                    new Lazy <Type> (() => typeof(ClassDerivedFromBindableObjectBase)),
                    null,
                    false,
                    false,
                    new BindableObjectDefaultValueStrategy(),
                    MockRepository.GenerateStub <IBindablePropertyReadAccessStrategy>(),
                    MockRepository.GenerateStub <IBindablePropertyWriteAccessStrategy>(),
                    SafeServiceLocator.Current.GetInstance <BindableObjectGlobalizationService>()));

            Assert.That(property.ReferenceClass, Is.SameAs(BindableObjectProviderTestHelper.GetBindableObjectClass(typeof(ClassDerivedFromBindableObjectBase))));
            Assert.That(
                property.BusinessObjectProvider,
                Is.SameAs(BindableObjectProvider.GetProviderForBindableObjectType(typeof(ClassWithReferenceToClassDerivedFromBindableObjectBase))));
            Assert.That(
                property.ReferenceClass.BusinessObjectProvider,
                Is.SameAs(BindableObjectProvider.GetProviderForBindableObjectType(typeof(ClassDerivedFromBindableObjectBase))));
            Assert.That(property.ReferenceClass.BusinessObjectProvider, Is.SameAs(property.BusinessObjectProvider));
        }
        public void GetProviderForBindableObjectType_WithIdentityType()
        {
            BindableObjectProvider provider = BindableObjectProvider.GetProviderForBindableObjectType(typeof(ClassWithIdentity));

            Assert.That(provider, Is.Not.Null);
            Assert.That(provider, Is.SameAs(BusinessObjectProvider.GetProvider(typeof(BindableObjectWithIdentityProviderAttribute))));
            Assert.That(provider, Is.Not.SameAs(BusinessObjectProvider.GetProvider(typeof(BindableObjectProviderAttribute))));
        }
Esempio n. 7
0
        public void GetIdentifier_ReturnsIdentifier()
        {
            var provider     = BindableObjectProvider.GetProviderForBindableObjectType(typeof(TypeOne));
            var typeOneClass = provider.GetBindableObjectClass(typeof(TypeOne));
            IBusinessObjectPropertyPath path = StaticBusinessObjectPropertyPath.Parse("TypeTwoValue.TypeThreeValue.TypeFourValue.IntValue", typeOneClass);

            Assert.That(path.Identifier, Is.EqualTo("TypeTwoValue.TypeThreeValue.TypeFourValue.IntValue"));
        }
Esempio n. 8
0
        public void GetIsDynamic_ReturnsFalse()
        {
            var provider     = BindableObjectProvider.GetProviderForBindableObjectType(typeof(TypeOne));
            var typeOneClass = provider.GetBindableObjectClass(typeof(TypeOne));
            IBusinessObjectPropertyPath path = StaticBusinessObjectPropertyPath.Parse("TypeTwoValue", typeOneClass);

            Assert.That(path.IsDynamic, Is.False);
        }
        public override void SetUp()
        {
            base.SetUp();

            var provider = BindableObjectProvider.GetProviderForBindableObjectType(typeof(BindableDomainObjectWithProperties));

            _businessObjectClassWithProperties = provider.GetBindableObjectClass(typeof(BindableDomainObjectWithProperties));
            _businessObjectSampleClass         = provider.GetBindableObjectClass(typeof(SampleBindableMixinDomainObject));
        }
Esempio n. 10
0
 public void GetProvider()
 {
     Assert.That(
         BindableObjectProvider.GetProviderForBindableObjectType(typeof(ClassDerivedFromBindableObjectBase)),
         Is.SameAs(BusinessObjectProvider.GetProvider <BindableObjectProviderAttribute>()));
     Assert.That(
         BindableObjectProvider.GetProviderForBindableObjectType(typeof(ClassDerivedFromBindableObjectBase)),
         Is.Not.SameAs(BusinessObjectProvider.GetProvider <BindableObjectWithIdentityProviderAttribute>()));
 }
        public void GetProviderForBindableObjectType_WithAttributeFromTypeOverridingAttributeFromMixin()
        {
            BindableObjectProvider provider =
                BindableObjectProvider.GetProviderForBindableObjectType(typeof(DerivedBusinessObjectClassWithSpecificBusinessObjectProviderAttribute));

            Assert.That(provider, Is.Not.Null);
            Assert.That(provider, Is.SameAs(BusinessObjectProvider.GetProvider(typeof(BindableObjectWithIdentityProviderAttribute))));
            Assert.That(provider, Is.Not.SameAs(BusinessObjectProvider.GetProvider(typeof(BindableObjectProviderAttribute))));
        }
Esempio n. 12
0
        public void GetFromUniqueIdentifier()
        {
            BusinessObjectProvider.GetProvider <BindableDomainObjectProviderAttribute>().AddService(typeof(IGetObjectService), new BindableDomainObjectGetObjectService());
            SampleBindableMixinDomainObject original = SampleBindableMixinDomainObject.NewObject();

            var provider = BindableObjectProvider.GetProviderForBindableObjectType(typeof(SampleBindableMixinDomainObject));
            var boClass  = (BindableObjectClassWithIdentity)provider.GetBindableObjectClass(typeof(SampleBindableMixinDomainObject));

            Assert.That(boClass.GetObject(original.ID.ToString()), Is.SameAs(original));
        }
Esempio n. 13
0
        public void Create_FromSingleProperty()
        {
            var provider = BindableObjectProvider.GetProviderForBindableObjectType(typeof(TypeOne));

            var properties = new[] { provider.GetBindableObjectClass(typeof(TypeOne)).GetPropertyDefinition("TypeTwoValue") };

            var path = StaticBusinessObjectPropertyPath.Create(properties);

            Assert.That(path.Properties, Is.EqualTo(properties));
            Assert.That(path.Identifier, Is.EqualTo("TypeTwoValue"));
        }
        public void GetPropertyDefinitions()
        {
            var provider            = BindableObjectProvider.GetProviderForBindableObjectType(typeof(SampleBindableMixinDomainObject));
            var bindableObjectClass = provider.GetBindableObjectClass(typeof(SampleBindableMixinDomainObject));

            var properties = bindableObjectClass.GetPropertyDefinitions();

            var propertiesByName = Array.ConvertAll(properties, property => property.Identifier);

            Assert.That(propertiesByName, Is.EquivalentTo(new[] { "List", "Relation", "Name", "Int32" }));
        }
Esempio n. 15
0
        private IBusinessObjectClassWithIdentity GetBusinessObjectClassWithIdentity(string businessObjectClass)
        {
            var type                = TypeUtility.GetType(businessObjectClass, true);
            var provider            = BindableObjectProvider.GetProviderForBindableObjectType(type);
            var bindableObjectClass = provider.GetBindableObjectClass(type);

            Assertion.IsNotNull(bindableObjectClass);
            Assertion.IsTrue(bindableObjectClass is IBusinessObjectClassWithIdentity);

            return((IBusinessObjectClassWithIdentity)bindableObjectClass);
        }
Esempio n. 16
0
        private Lazy <IBusinessObjectClass> GetReferenceClass()
        {
            return(new Lazy <IBusinessObjectClass> (
                       () =>
            {
                if (BindableObjectProvider.IsBindableObjectImplementation(UnderlyingType))
                {
                    var provider = BindableObjectProvider.GetProviderForBindableObjectType(UnderlyingType);
                    return provider.GetBindableObjectClass(UnderlyingType);
                }

                return GetReferenceClassFromService();
            },
                       LazyThreadSafetyMode.ExecutionAndPublication));
        }
Esempio n. 17
0
        public void LazyInitialization_KeepsProviderOfConstructionTime()
        {
            var objectCreatedBefore = ObjectFactory.Create <SimpleBusinessObjectClass> (ParamList.Empty);
            var providerBefore      = BindableObjectProvider.GetProviderForBindableObjectType(typeof(SimpleBusinessObjectClass));

            BindableObjectProvider.SetProvider(typeof(BindableObjectProviderAttribute), null);

            var providerAfter = BindableObjectProvider.GetProviderForBindableObjectType(typeof(SimpleBusinessObjectClass));

            Assert.That(providerAfter, Is.Not.SameAs(providerBefore));
            var objectCreatedAfter = ObjectFactory.Create <SimpleBusinessObjectClass> (ParamList.Empty);

            Assert.That(((IBusinessObject)objectCreatedAfter).BusinessObjectClass.BusinessObjectProvider, Is.SameAs(providerAfter));
            Assert.That(((IBusinessObject)objectCreatedBefore).BusinessObjectClass.BusinessObjectProvider, Is.SameAs(providerBefore));
        }
        public void LengthConstraintResolvedFromAboveInheritanceRoot()
        {
            var provider            = BindableObjectProvider.GetProviderForBindableObjectType(typeof(BindableDomainObjectAboveInheritanceRoot));
            var businessObjectClass = provider.GetBindableObjectClass(typeof(BindableDomainObjectAboveInheritanceRoot));

            var stringPropertyWithLengthConstraint =
                (IBusinessObjectStringProperty)businessObjectClass.GetPropertyDefinition("NotNullableStringPropertyWithLengthConstraint");

            Assert.That(stringPropertyWithLengthConstraint.MaxLength, Is.EqualTo(100));

            var stringPropertyWithoutLengthConstraint =
                (IBusinessObjectStringProperty)businessObjectClass.GetPropertyDefinition("NullableStringPropertyWithoutLengthConstraint");

            Assert.That(stringPropertyWithoutLengthConstraint.MaxLength, Is.Null);
        }
Esempio n. 19
0
        public void GetProperties_ThrowsNotSupportedException()
        {
            var provider     = BindableObjectProvider.GetProviderForBindableObjectType(typeof(TypeOne));
            var typeOneClass = provider.GetBindableObjectClass(typeof(TypeOne));

            var expectedProperties = new[]
            {
                typeOneClass.GetPropertyDefinition("TypeTwoValue"),
                provider.GetBindableObjectClass(typeof(TypeTwo)).GetPropertyDefinition("TypeThreeValue"),
                provider.GetBindableObjectClass(typeof(TypeThree)).GetPropertyDefinition("TypeFourValue"),
                provider.GetBindableObjectClass(typeof(TypeFour)).GetPropertyDefinition("IntValue"),
            };
            IBusinessObjectPropertyPath path = StaticBusinessObjectPropertyPath.Parse("TypeTwoValue.TypeThreeValue.TypeFourValue.IntValue", typeOneClass);

            Assert.That(() => path.Properties, Is.EqualTo(expectedProperties));
        }
Esempio n. 20
0
        public void Create_ContainsNonReferenceProperty_ThrowsArgumentException()
        {
            var provider = BindableObjectProvider.GetProviderForBindableObjectType(typeof(TypeOne));

            var properties = new[]
            {
                provider.GetBindableObjectClass(typeof(TypeOne)).GetPropertyDefinition("TypeTwoValue"),
                provider.GetBindableObjectClass(typeof(TypeTwo)).GetPropertyDefinition("IntValue"),
                provider.GetBindableObjectClass(typeof(TypeThree)).GetPropertyDefinition("TypeFourValue"),
                provider.GetBindableObjectClass(typeof(TypeFour)).GetPropertyDefinition("IntValue"),
            };

            Assert.That(
                () => StaticBusinessObjectPropertyPath.Create(properties),
                Throws.ArgumentException.With.Message.StartsWith(
                    "Property #1 ('IntValue') is not of type IBusinessObjectReferenceProperty. Every property except the last property must be a reference property."));
        }
Esempio n. 21
0
        public void GetBusinessObjectClass_WithTypeDerivedFromBaseClass()
        {
            Expect.Call(
                _typeResolutionServiceMock.GetType(
                    "Remotion.ObjectBinding.UnitTests.TestDomain.ClassDerivedFromBindableObjectBase, Remotion.ObjectBinding.UnitTests", true))
            .Return(typeof(ClassDerivedFromBindableObjectBase))
            .Repeat.AtLeastOnce();
            _mockRepository.ReplayAll();

            _dataSource.Type = typeof(ClassDerivedFromBindableObjectBase);
            IBusinessObjectClass actual = _dataSource.BusinessObjectClass;

            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.BusinessObjectProvider, Is.SameAs(BindableObjectProvider.GetProviderForBindableObjectType(typeof(ClassDerivedFromBindableObjectBase))));

            _mockRepository.VerifyAll();
        }
Esempio n. 22
0
        public void Create_NextPropertyNotPartOfClass_ThrowsArgumentException()
        {
            var provider = BindableObjectProvider.GetProviderForBindableObjectType(typeof(TypeOne));

            var properties = new[]
            {
                provider.GetBindableObjectClass(typeof(TypeOne)).GetPropertyDefinition("TypeTwoValue"),
                provider.GetBindableObjectClass(typeof(TypeThree)).GetPropertyDefinition("TypeFourValue"),
                provider.GetBindableObjectClass(typeof(TypeFour)).GetPropertyDefinition("IntValue"),
            };

            Assert.That(
                () => StaticBusinessObjectPropertyPath.Create(properties),
                Throws.ArgumentException.With.Message.StartsWith(
                    "Property #1 ('TypeFourValue') is not part of the previous business object class "
                    + "'Remotion.ObjectBinding.UnitTests.BusinessObjectPropertyPaths.TestDomain.TypeTwo, Remotion.ObjectBinding.UnitTests'."
                    + " The property path must form a continuous chain."));
        }
Esempio n. 23
0
        public override void LoadValues(bool interim)
        {
            base.LoadValues(interim);

            var type     = typeof(AccessControlEntry);
            var provider = BindableObjectProvider.GetProviderForBindableObjectType(type);
            var aceClass = provider.GetBindableObjectClass(type);

            var cssHorizontal = "titleCellHorizontal";
            var cssVertical   = "titleCellVertical";

            HeaderCells.Controls.Add(CreateTableCell(string.Empty, cssHorizontal)); //ExpandButton
            HeaderCells.Controls.Add(CreateTableCell(string.Empty, cssHorizontal)); //DeleteButton
            HeaderCells.Controls.Add(CreateTableCell(aceClass.GetPropertyDefinition("TenantCondition").DisplayName, cssHorizontal));
            HeaderCells.Controls.Add(CreateTableCell(aceClass.GetPropertyDefinition("GroupCondition").DisplayName, cssHorizontal));
            HeaderCells.Controls.Add(CreateTableCell(aceClass.GetPropertyDefinition("UserCondition").DisplayName, cssHorizontal));
            HeaderCells.Controls.Add(CreateTableCell(aceClass.GetPropertyDefinition("SpecificAbstractRole").DisplayName, cssHorizontal));
            HeaderCells.Controls.Add(CreateTableCell(string.Empty, cssHorizontal)); //Toggle Permissions
            foreach (var accessType in CurrentClassDefinition.AccessTypes)
            {
                HeaderCells.Controls.Add(CreateTableCell(accessType.DisplayName, cssVertical));
            }
        }
Esempio n. 24
0
        /// <summary>
        /// Use this method as a shortcut to retrieve the <see cref="BindableObjectClass"/> for a <see cref="Type"/>
        /// that has the <see cref="BindableObjectMixinBase{T}"/> applied or is derived from a bindable object base class without first retrieving the
        /// matching provider.
        /// </summary>
        /// <param name="type">The type to get a <see cref="BindableObjectClass"/> for. This type must have a mixin derived from
        /// <see cref="BindableObjectMixinBase{TBindableObject}"/> configured or it must be derived from a bindable object class class, and it is
        /// recommended to specify the simple target type rather then the generated mixed type.</param>
        /// <returns>Returns the <see cref="BindableObjectClass"/> for the <paramref name="type"/>.</returns>
        public static BindableObjectClass GetBindableObjectClass(Type type)
        {
            var provider = BindableObjectProvider.GetProviderForBindableObjectType(type);

            return(provider.GetBindableObjectClass(type));
        }
Esempio n. 25
0
        private ClassInfo[] GetClassInfos()
        {
            ArrayList classInfoList = new ArrayList();

            foreach (ClassDefinition classDefinition in MappingConfiguration.Current.ClassDefinitions)
            {
                if (!(IgnoreClass(classDefinition) || classDefinition.IsAbstract))
                {
                    ClassInfo classInfo = new ClassInfo();

                    classInfo.type = classDefinition.ClassType;
                    // classInfo.objectClass = BindableObjectProvider.GetBindableObjectClass (classDefinition.ClassType);
                    classInfo.objectClass =
                        BindableObjectProvider.GetProviderForBindableObjectType(classDefinition.ClassType).GetBindableObjectClass(
                            classDefinition.ClassType);
                    classInfo.properties = GetProperties(classInfo.objectClass.GetPropertyDefinitions());

                    classInfoList.Add(classInfo);
                }
            }

            #region Thanks to MK

            /*
             * if (!File.Exists(_configuration.AssemblyName))
             *      throw new CodeGeneratorException(ErrorCode.AssemblyNotFound, _configuration.AssemblyName);
             *
             * Assembly assembly = Assembly.LoadFile(_configuration.AssemblyName);
             * TypeFilter typeFilter = new TypeFilter(InterfaceFilter);
             * Type[] types = assembly.GetTypes();
             * ArrayList classInfoList = new ArrayList();
             *
             * foreach (Type type in types)
             * {
             *      if (! type.IsClass)
             *              continue;
             *
             *      if (! HasInterface(type, "Remotion.ObjectBinding.IBusinessObject"))
             *              continue;
             *
             *      Type domainType = type;
             *      ClassProvider provider = null;
             *
             *      while (domainType != typeof(Object))
             *      {
             *              provider = ClassProvider.GetProvider(domainType);
             *
             *              if (provider != null)
             *                      break;
             *
             *              domainType = domainType.BaseType;
             *      }
             *
             *      if (provider == null)
             *              throw new CodeGeneratorException(ErrorCode.TypeNotMapped, domainType.FullName);
             *
             *      IBusinessObjectClass businessObjectClass = provider.GetClass(type);
             *
             *      if (! IgnoreClass(businessObjectClass))
             *      {
             *              ClassInfo classInfo = new ClassInfo();
             *
             *              classInfo.type = type;
             *              classInfo.objectClass = businessObjectClass;
             *              classInfo.properties = GetProperties(businessObjectClass.GetPropertyDefinitions());
             *
             *              classInfoList.Add(classInfo);
             *      }
             * }
             */
            #endregion

            return((ClassInfo[])classInfoList.ToArray(typeof(ClassInfo)));
        }
 public void GetProviderForBindableObjectType_WithMissingProviderAttribute()
 {
     BindableObjectProvider.GetProviderForBindableObjectType(typeof(ManualBusinessObject));
 }
 public void GetProviderForBindableObjectType_WithInvalidProviderType()
 {
     BindableObjectProvider.GetProviderForBindableObjectType(typeof(BindableObjectWithStubBusinessObjectProvider));
 }
 public void UsesBindableDomainObjectMetadataFactory()
 {
     Assert.That(
         BindableObjectProvider.GetProviderForBindableObjectType(typeof(SampleBindableMixinDomainObject)).MetadataFactory,
         Is.InstanceOf(typeof(BindableDomainObjectMetadataFactory)));
 }
Esempio n. 29
0
 private static void LoadObjectBinding()
 {
     using (StopwatchScope.CreateScope("Loading object binding took {elapsed:ms} ms."))
         BindableObjectProvider.GetProviderForBindableObjectType(typeof(Tenant)).GetBindableObjectClass(typeof(Tenant));
 }
Esempio n. 30
0
 public void FromInterface()
 {
     Assert.That(_businessObject.BusinessObjectClass, Is.Not.Null);
     Assert.That(_businessObject.BusinessObjectClass, Is.SameAs(_bindableObjectMixin.BusinessObjectClass));
     Assert.That(_businessObject.BusinessObjectClass.BusinessObjectProvider, Is.SameAs(BindableObjectProvider.GetProviderForBindableObjectType(typeof(SimpleBusinessObjectClass))));
 }