Example #1
0
        public override void TestFixtureSetUp()
        {
            base.TestFixtureSetUp();

            _searchServiceStub     = MockRepository.GenerateStub <ISearchAvailableObjectsService>();
            _searchServiceArgsStub = MockRepository.GenerateStub <ISearchAvailableObjectsArguments>();
            BusinessObjectProvider.SetProvider(typeof(BindableDomainObjectProviderAttribute), null);
            BusinessObjectProvider.GetProvider <BindableDomainObjectProviderAttribute>().AddService(
                typeof(ISearchAvailableObjectsService), MockRepository.GenerateStub <ISearchAvailableObjectsService>());
        }
Example #2
0
        public IBusinessObject[] Search(
            IBusinessObject referencingObject,
            IBusinessObjectReferenceProperty property,
            ISearchAvailableObjectsArguments searchArguments)
        {
            var referencingSecurityManagerObject = ArgumentUtility.CheckType <TReferencingObject> ("referencingObject", referencingObject);

            ArgumentUtility.CheckNotNull("property", property);

            var queryFactory = GetQueryFactory(property);

            var securityManagerSearchArguments = CreateSearchArguments(searchArguments);

            return(CreateQuery(queryFactory, referencingSecurityManagerObject, property, securityManagerSearchArguments).ToArray());
        }
Example #3
0
        public IBusinessObject[] Search(
            IBusinessObject referencingObject,
            IBusinessObjectReferenceProperty property,
            ISearchAvailableObjectsArguments searchArguments)
        {
            ArgumentUtility.CheckNotNull("property", property);
            var rolePropertiesSearchArguments = ArgumentUtility.CheckType <RolePropertiesSearchArguments> ("searchArguments", searchArguments);

            if (!SupportsProperty(property))
            {
                throw new ArgumentException(
                          string.Format("The property '{0}' is not supported by the '{1}' type.", property.Identifier, GetType().FullName));
            }

            var positions         = GetPositions(rolePropertiesSearchArguments);
            var filteredPositions = FilterByAccess(positions, SecurityManagerAccessTypes.AssignRole);

            return(filteredPositions.ToArray());
        }
Example #4
0
        public void Search_WithSearchNotSupported()
        {
            IBusinessObject                  businessObject       = (IBusinessObject)ObjectFactory.Create <ClassWithBusinessObjectProperties> (ParamList.Empty);
            ISearchServiceOnProperty         mockService          = _mockRepository.StrictMock <ISearchServiceOnProperty>();
            IBusinessObjectReferenceProperty property             = CreateProperty("SearchServiceFromPropertyDeclaration");
            ISearchAvailableObjectsArguments searchArgumentsStubb = _mockRepository.Stub <ISearchAvailableObjectsArguments>();

            Expect.Call(mockService.SupportsProperty(property)).Return(false);
            _mockRepository.ReplayAll();

            _bindableObjectProviderForDeclaringType.AddService(mockService);
            try
            {
                property.SearchAvailableObjects(businessObject, searchArgumentsStubb);
            }
            finally
            {
                _mockRepository.VerifyAll();
            }
        }
Example #5
0
        public void Search_WithSearchSupportedAndReferencingObjectNull()
        {
            ISearchServiceOnType             mockService = _mockRepository.StrictMock <ISearchServiceOnType>();
            IBusinessObjectReferenceProperty property    = CreateProperty("SearchServiceFromPropertyType");

            IBusinessObject[] expected = new IBusinessObject[0];
            ISearchAvailableObjectsArguments searchArgumentsStub = _mockRepository.Stub <ISearchAvailableObjectsArguments>();

            using (_mockRepository.Ordered())
            {
                Expect.Call(mockService.SupportsProperty(property)).Return(true);
                Expect.Call(mockService.Search(null, property, searchArgumentsStub)).Return(expected);
            }
            _mockRepository.ReplayAll();

            _bindableObjectProviderForPropertyType.AddService(mockService);
            IBusinessObject[] actual = property.SearchAvailableObjects(null, searchArgumentsStub);

            _mockRepository.VerifyAll();
            Assert.That(actual, Is.SameAs(expected));
        }
Example #6
0
        private SecurityManagerSearchArguments CreateSearchArguments(ISearchAvailableObjectsArguments searchArguments)
        {
            if (searchArguments == null)
            {
                return(new SecurityManagerSearchArguments(null, null, null));
            }

            var defaultSearchArguments = searchArguments as DefaultSearchArguments;

            if (defaultSearchArguments != null)
            {
                if (string.IsNullOrEmpty(defaultSearchArguments.SearchStatement))
                {
                    return(new SecurityManagerSearchArguments(null, null, null));
                }

                var tenantHandle = ObjectID.Parse(defaultSearchArguments.SearchStatement).GetHandle <Tenant>();
                return(new SecurityManagerSearchArguments(new TenantConstraint(tenantHandle), null, null));
            }

            return(ArgumentUtility.CheckType <SecurityManagerSearchArguments> ("searchArguments", searchArguments));
        }
Example #7
0
        public void SearchOwningGroups()
        {
            ISearchAvailableObjectsService   searchServiceStub = MockRepository.GenerateStub <ISearchAvailableObjectsService>();
            ISearchAvailableObjectsArguments args = MockRepository.GenerateStub <ISearchAvailableObjectsArguments>();

            BusinessObjectProvider.SetProvider(typeof(BindableDomainObjectProviderAttribute), null);
            BusinessObjectProvider.GetProvider <BindableDomainObjectProviderAttribute>()
            .AddService(typeof(GroupPropertyTypeSearchService), searchServiceStub);
            IBusinessObjectClass             userClass           = BindableObjectProviderTestHelper.GetBindableObjectClass(typeof(User));
            IBusinessObjectReferenceProperty owningGroupProperty = (IBusinessObjectReferenceProperty)userClass.GetPropertyDefinition("OwningGroup");

            Assert.That(owningGroupProperty, Is.Not.Null);

            User user     = CreateUser();
            var  expected = new[] { MockRepository.GenerateStub <IBusinessObject> () };

            searchServiceStub.Stub(stub => stub.SupportsProperty(owningGroupProperty)).Return(true);
            searchServiceStub.Stub(stub => stub.Search(user, owningGroupProperty, args)).Return(expected);

            Assert.That(owningGroupProperty.SupportsSearchAvailableObjects, Is.True);

            IBusinessObject[] actual = owningGroupProperty.SearchAvailableObjects(user, args);
            Assert.That(actual, Is.SameAs(expected));
        }
Example #8
0
        public void SearchParents()
        {
            ISearchAvailableObjectsService   searchServiceStub = MockRepository.GenerateStub <ISearchAvailableObjectsService>();
            ISearchAvailableObjectsArguments args = MockRepository.GenerateStub <ISearchAvailableObjectsArguments>();

            BusinessObjectProvider.SetProvider(typeof(BindableDomainObjectProviderAttribute), null);
            BusinessObjectProvider.GetProvider <BindableDomainObjectProviderAttribute>()
            .AddService(typeof(TenantPropertyTypeSearchService), searchServiceStub);
            IBusinessObjectClass             tenantClass    = BindableObjectProviderTestHelper.GetBindableObjectClass(typeof(Tenant));
            IBusinessObjectReferenceProperty parentProperty = (IBusinessObjectReferenceProperty)tenantClass.GetPropertyDefinition("Parent");

            Assert.That(parentProperty, Is.Not.Null);

            Tenant tenant   = TestHelper.CreateTenant("TestTenant", string.Empty);
            var    expected = new[] { MockRepository.GenerateStub <IBusinessObject> () };

            searchServiceStub.Stub(stub => stub.SupportsProperty(parentProperty)).Return(true);
            searchServiceStub.Stub(stub => stub.Search(tenant, parentProperty, args)).Return(expected);

            Assert.That(parentProperty.SupportsSearchAvailableObjects, Is.True);

            IBusinessObject[] actual = parentProperty.SearchAvailableObjects(tenant, args);
            Assert.That(actual, Is.SameAs(expected));
        }
Example #9
0
        public void SearchPositions()
        {
            ISearchAvailableObjectsService   searchServiceStub = MockRepository.GenerateStub <ISearchAvailableObjectsService> ();
            ISearchAvailableObjectsArguments args = MockRepository.GenerateStub <ISearchAvailableObjectsArguments> ();

            BusinessObjectProvider.SetProvider(typeof(BindableDomainObjectProviderAttribute), null);
            BusinessObjectProvider.GetProvider <BindableDomainObjectProviderAttribute>()
            .AddService(typeof(RolePropertiesSearchService), searchServiceStub);
            IBusinessObjectClass             roleClass        = BindableObjectProviderTestHelper.GetBindableObjectClass(typeof(Role));
            IBusinessObjectReferenceProperty positionProperty = (IBusinessObjectReferenceProperty)roleClass.GetPropertyDefinition("Position");

            Assert.That(positionProperty, Is.Not.Null);

            Role role     = Role.NewObject();
            var  expected = new[] { MockRepository.GenerateStub <IBusinessObject> () };

            searchServiceStub.Stub(stub => stub.SupportsProperty(positionProperty)).Return(true);
            searchServiceStub.Stub(stub => stub.Search(role, positionProperty, args)).Return(expected);

            Assert.That(positionProperty.SupportsSearchAvailableObjects, Is.True);

            IBusinessObject[] actual = positionProperty.SearchAvailableObjects(role, args);
            Assert.That(actual, Is.SameAs(expected));
        }
Example #10
0
        public IBusinessObject[] Search(IBusinessObject referencingObject, IBusinessObjectReferenceProperty property, ISearchAvailableObjectsArguments searchArguments)
        {
            var defaultSearchArguments = searchArguments as DefaultSearchArguments;

            if (defaultSearchArguments == null || string.IsNullOrEmpty(defaultSearchArguments.SearchStatement))
            {
                return(_searchAllService.Search(referencingObject, property, searchArguments));
            }
            else
            {
                return(_querySearchService.Search(referencingObject, property, searchArguments));
            }
        }
Example #11
0
        /// <summary>
        ///   Searches the object model for the <see cref="IBusinessObject"/> instances that can be assigned to this property.
        /// </summary>
        /// <param name="referencingObject">
        ///   The <see cref="IBusinessObject"/> for which to search for the possible objects to be referenced. Can be <see langword="null"/>.
        /// </param>
        /// <param name="searchArguments">
        ///   A parameter object containing additional information for executing the search. Can be <see langword="null"/>.
        /// </param>
        /// <returns>
        ///   A list of the <see cref="IBusinessObject"/> instances available. Must not return <see langword="null"/>.
        /// </returns>
        /// <exception cref="NotSupportedException">
        ///   Thrown if <see cref="SupportsSearchAvailableObjects"/> evaluated <see langword="false"/> but this method has been called anyways.
        /// </exception>
        /// <remarks>
        ///   <para>
        ///     The implementation delegates to the <see cref="ISearchAvailableObjectsService.Search"/> method of the <see cref="ISearchAvailableObjectsService"/> interface.
        ///   </para><para>
        ///   The service lookup uses the following logic to retrieve the service from the <see cref="IBusinessObjectProvider"/>:
        ///   <list type="table">
        ///     <item>
        ///       <term>
        ///         The <see cref="SearchAvailableObjectsServiceTypeAttribute"/> is declared on the property itself.
        ///       </term>
        ///       <description>
        ///         The service <see cref="Type"/> declared by the <see cref="SearchAvailableObjectsServiceTypeAttribute"/>'s <see cref="SearchAvailableObjectsServiceTypeAttribute.Type"/>
        ///         property is used to retrieve the specifc implementation of the <see cref="ISearchAvailableObjectsService"/>
        ///         from the <see cref="PropertyBase.BusinessObjectProvider"/> of the <see cref="ReferenceProperty"/>.
        ///       </description>
        ///     </item>
        ///     <item>
        ///       <term>
        ///         The <see cref="SearchAvailableObjectsServiceTypeAttribute"/> is declared on the property's <see cref="Type"/>.
        ///       </term>
        ///       <description>
        ///         The service <see cref="Type"/> declared by the <see cref="SearchAvailableObjectsServiceTypeAttribute"/>'s <see cref="SearchAvailableObjectsServiceTypeAttribute.Type"/>
        ///         property is used to retrieve the specifc implementation of the <see cref="ISearchAvailableObjectsService"/>
        ///         from the <see cref="IBusinessObjectClass.BusinessObjectProvider"/> of the <see cref="ReferenceProperty"/>'s <see cref="ReferenceClass"/>.
        ///       </description>
        ///     </item>
        ///     <item>
        ///       <term>
        ///         No <see cref="SearchAvailableObjectsServiceTypeAttribute"/> has been declared.
        ///       </term>
        ///       <description>
        ///         An instance of the <see cref="ISearchAvailableObjectsService"/> is retrieved from the <see cref="PropertyBase.BusinessObjectProvider"/> of the
        ///         <see cref="ReferenceProperty"/>.
        ///       </description>
        ///     </item>
        ///   </list>
        ///   If no service was registered on the <see cref="IBusinessObjectProvider"/> for the specified <see cref="Type"/>, the feature is disabled and
        ///   <see cref="SupportsSearchAvailableObjects"/> will evaluate <see langword="false"/>.
        /// </para>
        /// </remarks>
        /// <seealso cref="SearchAvailableObjectsServiceTypeAttribute"/>
        /// <seealso cref="ISearchAvailableObjectsService"/>
        /// <seealso cref="SupportsSearchAvailableObjects"/>
        public IBusinessObject[] SearchAvailableObjects(IBusinessObject referencingObject, ISearchAvailableObjectsArguments searchArguments)
        {
            if (!SupportsSearchAvailableObjects)
            {
                throw new NotSupportedException(
                          string.Format(
                              "Searching is not supported for reference property '{0}' of business object class '{1}'.",
                              Identifier,
                              ReflectedClass.Identifier));
            }

            var service = GetService <ISearchAvailableObjectsService> (_searchServiceDefinition.Value);

            return(service.Search(referencingObject, this, searchArguments));
        }
        public IBusinessObject[] Search(IBusinessObject referencingObject, IBusinessObjectReferenceProperty property, ISearchAvailableObjectsArguments searchArguments)
        {
            ArgumentUtility.CheckNotNull("property", property);
            if (!SupportsProperty(property))
            {
                var message = string.Format("The property '{0}' on type '{1}' is not supported by the BindableDomainObjectSearchAllService: The service "
                                            + "only supports relation properties (ie. references to other DomainObject instances).", property.Identifier,
                                            property.ReflectedClass.Identifier);
                throw new ArgumentException(message, "property");
            }

            var referencedDomainObjectType = GetDomainObjectType(property);
            var referencingDomainObject    = referencingObject as DomainObject;

            var clientTransaction = referencingDomainObject != null ? referencingDomainObject.DefaultTransactionContext.ClientTransaction : ClientTransaction.Current;

            if (clientTransaction == null)
            {
                throw new InvalidOperationException("No ClientTransaction has been associated with the current thread or the referencing object.");
            }

            return(GetAllObjects(clientTransaction, referencedDomainObjectType));
        }
Example #13
0
        public IBusinessObject[] Search(IBusinessObject referencingObject, IBusinessObjectReferenceProperty property, ISearchAvailableObjectsArguments searchArguments)
        {
            var defaultSearchArguments = searchArguments as DefaultSearchArguments;

            if (defaultSearchArguments == null || string.IsNullOrEmpty(defaultSearchArguments.SearchStatement))
            {
                return(new IBusinessObject[0]);
            }

            QueryDefinition definition = DomainObjectsConfiguration.Current.Query.QueryDefinitions.GetMandatory(defaultSearchArguments.SearchStatement);

            if (definition.QueryType != QueryType.Collection)
            {
                throw new ArgumentException(string.Format("The query '{0}' is not a collection query.", defaultSearchArguments.SearchStatement));
            }

            var referencingDomainObject = referencingObject as DomainObject;

            var clientTransaction = referencingDomainObject != null ? referencingDomainObject.DefaultTransactionContext.ClientTransaction : ClientTransaction.Current;

            if (clientTransaction == null)
            {
                throw new InvalidOperationException("No ClientTransaction has been associated with the current thread or the referencing object.");
            }

            var result           = clientTransaction.QueryManager.GetCollection(QueryFactory.CreateQuery(definition));
            var availableObjects = new IBusinessObjectWithIdentity[result.Count];

            if (availableObjects.Length > 0)
            {
                result.ToArray().CopyTo(availableObjects, 0);
            }

            return(availableObjects);
        }