예제 #1
0
        public void GetProvider()
        {
            IBusinessObjectProvider provider = BusinessObjectProvider.GetProvider(typeof(StubBusinessObjectProviderAttribute));

            Assert.That(provider, Is.TypeOf(typeof(StubBusinessObjectProvider)));
            Assert.That(((BusinessObjectProvider)provider).ProviderAttribute, Is.TypeOf(typeof(StubBusinessObjectProviderAttribute)));
        }
        /// <summary>
        /// Sets the <see cref="IBusinessObjectProvider"/> to be associated with the <see cref="BusinessObjectProviderAttribute"/> type specified.
        /// </summary>
        /// <param name="businessObjectProviderAttributeType">
        /// A <see cref="Type"/> derived from <see cref="BusinessObjectProviderAttribute"/>. Must not be <see langword="null" />.
        /// </param>
        /// <param name="provider">
        /// The <see cref="IBusinessObjectProvider"/> instance to be associated with the <paramref name="businessObjectProviderAttributeType"/>.
        /// Pass <see langword="null"/> to remove the association.
        /// </param>
        public static void SetProvider(Type businessObjectProviderAttributeType, IBusinessObjectProvider provider)
        {
            ArgumentUtility.CheckNotNullAndTypeIsAssignableFrom(
                "businessObjectProviderAttributeType", businessObjectProviderAttributeType, typeof(BusinessObjectProviderAttribute));

            if (provider != null)
            {
                BusinessObjectProviderAttribute attribute = CreateBusinessObjectProviderAttribute(businessObjectProviderAttributeType);
                if (!TypeExtensions.CanAscribeTo(provider.GetType(), attribute.BusinessObjectProviderType))
                {
                    throw new ArgumentException(
                              "The provider is not compatible with the provider-type required by the businessObjectProviderAttributeType's instantiation.", "provider");
                }

                if (provider is BusinessObjectProvider)
                {
                    ((BusinessObjectProvider)provider)._providerAttribute = attribute;
                }
            }

            s_businessObjectProviderStore.Remove(businessObjectProviderAttributeType);
            if (provider != null)
            {
                s_businessObjectProviderStore.Add(businessObjectProviderAttributeType, provider);
            }
        }
예제 #3
0
        public void GetProvider_WithDifferentAttributesResultingInDifferentProviders()
        {
            IBusinessObjectProvider provider = BusinessObjectProvider.GetProvider(typeof(StubBusinessObjectProviderAttribute));

            Assert.That(provider, Is.TypeOf(typeof(StubBusinessObjectProvider)));
            Assert.That(provider, Is.Not.SameAs(BusinessObjectProvider.GetProvider(typeof(Stub2BusinessObjectProviderAttribute))));
            Assert.That(provider, Is.Not.SameAs(BusinessObjectProvider.GetProvider(typeof(DerivedStubBusinessObjectProviderAttribute))));
        }
예제 #4
0
 public void GetProvider_WithMixin()
 {
     using (MixinConfiguration.BuildNew().ForClass(typeof(StubBusinessObjectProvider)).AddMixin <MixinStub>().EnterScope())
     {
         IBusinessObjectProvider provider = BusinessObjectProvider.GetProvider(typeof(StubBusinessObjectProviderAttribute));
         Assert.That(provider, Is.InstanceOf(typeof(IMixinTarget)));
     }
 }
예제 #5
0
        public void SetUp()
        {
            Initialize();

            OptionsMenu  = new StubDropDownMenu();
            DropDownList = new StubDropDownList();

            Control = MockRepository.GenerateStub <IBocReferenceValue>();
            Control.Stub(stub => stub.ClientID).Return(c_clientID);
            Control.Stub(stub => stub.Command).Return(new BocCommand());
            Control.Command.Type = CommandType.Event;
            Control.Command.Show = CommandShow.Always;

            Control.Stub(stub => stub.OptionsMenu).Return(OptionsMenu);

            IPage pageStub = MockRepository.GenerateStub <IPage>();

            pageStub.Stub(stub => stub.WrappedInstance).Return(new PageMock());
            Control.Stub(stub => stub.Page).Return(pageStub);

            ClientScriptManagerMock = MockRepository.GenerateMock <IClientScriptManager>();
            pageStub.Stub(stub => stub.ClientScript).Return(ClientScriptManagerMock);

            BusinessObject = TypeWithReference.Create("MyBusinessObject");
            BusinessObject.ReferenceList = new[]
            {
                TypeWithReference.Create("ReferencedObject 0"),
                TypeWithReference.Create("ReferencedObject 1"),
                TypeWithReference.Create("ReferencedObject 2")
            };
            _dataSource = new BusinessObjectReferenceDataSource();
            _dataSource.BusinessObject = (IBusinessObject)BusinessObject;

            _provider = ((IBusinessObject)BusinessObject).BusinessObjectClass.BusinessObjectProvider;
            _provider.AddService <IBusinessObjectWebUIService> (new ReflectionBusinessObjectWebUIService());

            StateBag stateBag = new StateBag();

            Control.Stub(mock => mock.Attributes).Return(new AttributeCollection(stateBag));
            Control.Stub(mock => mock.Style).Return(Control.Attributes.CssStyle);
            Control.Stub(mock => mock.LabelStyle).Return(new Style(stateBag));
            Control.Stub(mock => mock.DropDownListStyle).Return(new DropDownListStyle());
            Control.Stub(mock => mock.ControlStyle).Return(new Style(stateBag));
            Control.Stub(stub => stub.GetValueName()).Return(c_valueName);
            Control.Stub(stub => stub.PopulateDropDownList(Arg <DropDownList> .Is.NotNull))
            .WhenCalled(
                invocation =>
            {
                foreach (var item in BusinessObject.ReferenceList)
                {
                    ((DropDownList)invocation.Arguments[0]).Items.Add(new ListItem(item.DisplayName, item.UniqueIdentifier));
                }
            });

            Control.Stub(stub => stub.GetLabelText()).Return("MyText");

            _resourceUrlFactory = new FakeResourceUrlFactory();
        }
예제 #6
0
        public override void SetUp()
        {
            base.SetUp();

            _serviceFactoryStub = MockRepository.GenerateStub <IBusinessObjectServiceFactory>();
            _provider           = new StubBusinessObjectProvider(_serviceFactoryStub);
            _mockRepository     = new MockRepository();

            BusinessObjectProvider.SetProvider <StubBusinessObjectProviderAttribute> (null);
            BusinessObjectProvider.SetProvider <BindableObjectProviderAttribute> (null);
        }
        private static IBusinessObjectProvider CreateBusinessObjectProviderFromAttribute(Type businessObjectProviderAttributeType)
        {
            BusinessObjectProviderAttribute attribute = CreateBusinessObjectProviderAttribute(businessObjectProviderAttributeType);
            IBusinessObjectProvider         provider  = CreateBusinessObjectProvider(attribute.BusinessObjectProviderType);

            if (provider is BusinessObjectProvider)
            {
                ((BusinessObjectProvider)provider)._providerAttribute = attribute;
            }

            return(provider);
        }
예제 #8
0
        /// <summary>
        ///   Gets the <see cref="IBusinessObjectService"/> from the <paramref name="businessObjectProvider"/> and queries it for a <see cref="string"/>
        ///   to be used as tool-tip.
        /// </summary>
        /// <param name="businessObject">
        ///   The <see cref="IBusinessObject"/> to be passed to the <see cref="IBusinessObjectWebUIService"/>'s
        ///   <see cref="IBusinessObjectWebUIService.GetIcon"/> method.
        /// </param>
        /// <param name="businessObjectProvider">
        ///   The <see cref="IBusinessObjectProvider"/> to be used to get the <see cref="IconInfo"/> object. Must not be <see langowrd="null"/>.
        /// </param>
        public static string GetToolTip(IBusinessObject businessObject, IBusinessObjectProvider businessObjectProvider)
        {
            ArgumentUtility.CheckNotNull("businessObjectProvider", businessObjectProvider);

            var webUIService = businessObjectProvider.GetService <IBusinessObjectWebUIService>();

            if (webUIService != null)
            {
                return(webUIService.GetToolTip(businessObject));
            }

            return(null);
        }
        public void SetUp()
        {
            Initialize();

            OptionsMenu = new StubDropDownMenu();
            TextBox     = new StubTextBox();

            Control = MockRepository.GenerateStub <IBocAutoCompleteReferenceValue> ();
            Control.Stub(stub => stub.ClientID).Return(c_clientID);
            Control.Stub(stub => stub.GetTextValueName()).Return(c_textValueName);
            Control.Stub(stub => stub.GetKeyValueName()).Return(c_keyValueName);
            Control.Stub(stub => stub.Command).Return(new BocCommand());
            Control.Command.Type = CommandType.Event;
            Control.Command.Show = CommandShow.Always;
            Control.Stub(stub => stub.SearchServicePath).Return("~/SearchService.asmx");

            Control.Stub(stub => stub.OptionsMenu).Return(OptionsMenu);

            IPage pageStub = MockRepository.GenerateStub <IPage> ();

            Control.Stub(stub => stub.Page).Return(pageStub);

            ClientScriptManagerMock = MockRepository.GenerateMock <IClientScriptManager> ();
            pageStub.Stub(stub => stub.ClientScript).Return(ClientScriptManagerMock);

            BusinessObject = TypeWithReference.Create("MyBusinessObject");
            BusinessObject.ReferenceList = new[]
            {
                TypeWithReference.Create("ReferencedObject 0"),
                TypeWithReference.Create("ReferencedObject 1"),
                TypeWithReference.Create("ReferencedObject 2")
            };
            _dataSource = new BusinessObjectReferenceDataSource();
            _dataSource.BusinessObject = (IBusinessObject)BusinessObject;

            _provider = ((IBusinessObject)BusinessObject).BusinessObjectClass.BusinessObjectProvider;
            _provider.AddService <IBusinessObjectWebUIService> (new ReflectionBusinessObjectWebUIService());

            StateBag stateBag = new StateBag();

            Control.Stub(mock => mock.Attributes).Return(new AttributeCollection(stateBag));
            Control.Stub(mock => mock.Style).Return(Control.Attributes.CssStyle);
            Control.Stub(mock => mock.CommonStyle).Return(new Style(stateBag));
            Control.Stub(mock => mock.LabelStyle).Return(new Style(stateBag));
            Control.Stub(mock => mock.TextBoxStyle).Return(new SingleRowTextBoxStyle());
            Control.Stub(mock => mock.ControlStyle).Return(new Style(stateBag));

            Control.Stub(stub => stub.GetLabelText()).Return("MyText");

            _resourceUrlFactory = new FakeResourceUrlFactory();
        }
        public void BusinessObjectProvider_CreatePropertyPath()
        {
            IBusinessObjectProvider provider = null;
            var propertyStub = MockRepository.GenerateStub <IBusinessObjectProperty>();

            propertyStub.Stub(_ => _.ReflectedClass).Return(MockRepository.GenerateStub <IBusinessObjectClass>());
            propertyStub.ReflectedClass.Stub(_ => _.GetPropertyDefinition(Arg <string> .Is.Anything)).Return(propertyStub);
            IBusinessObjectProperty[] properties = new[] { propertyStub };

            var path = provider.CreatePropertyPath(properties);

            Assert.That(path, Is.InstanceOf <StaticBusinessObjectPropertyPath>());
            Assert.That(path.Properties, Is.EqualTo(properties));
        }
예제 #11
0
        public void WithoutSearchServiceAttribute_AndNoDefaultSearchService_FromPropertyType()
        {
            IBusinessObjectClassService      businessObjectClassServiceMock      = _mockRepository.StrictMock <IBusinessObjectClassService> ();
            IBusinessObjectProvider          businessObjectProviderMock          = _mockRepository.StrictMock <IBusinessObjectProvider> ();
            IBusinessObjectClassWithIdentity businessObjectClassWithIdentityMock = _mockRepository.StrictMock <IBusinessObjectClassWithIdentity> ();
            IBusinessObjectReferenceProperty property = CreatePropertyWithoutMixing("NoSearchService");

            Expect.Call(businessObjectClassWithIdentityMock.BusinessObjectProvider).Return(businessObjectProviderMock).Repeat.Any();
            Expect.Call(businessObjectProviderMock.GetService(typeof(ISearchAvailableObjectsService))).Return(null);
            Expect.Call(businessObjectClassServiceMock.GetBusinessObjectClass(typeof(ClassFromOtherBusinessObjectImplementation)))
            .Return(businessObjectClassWithIdentityMock);
            _mockRepository.ReplayAll();

            _bindableObjectProviderForDeclaringType.AddService(businessObjectClassServiceMock);

            _mockRepository.VerifyAll();
            Assert.That(property.SupportsSearchAvailableObjects, Is.False);
        }
        public static IBusinessObjectPropertyPath CreatePropertyPath(this IBusinessObjectProvider provider, IBusinessObjectProperty[] properties)
        {
            ArgumentUtility.CheckNotNullOrEmpty("properties", properties);

            return(StaticBusinessObjectPropertyPath.Create(properties));
        }
예제 #13
0
        public void GetProvider_FromOtherBusinessObjectImplementation()
        {
            IBusinessObjectProvider provider = BusinessObjectProvider.GetProvider(typeof(OtherBusinessObjectImplementationProviderAttribute));

            Assert.That(provider, Is.TypeOf(typeof(OtherBusinessObjectImplementationProvider)));
        }
예제 #14
0
 public NotAccessibleBusinessObjectPropertyPathResult(IBusinessObjectProvider businessObjectProvider)
 {
     _businessObjectProvider = businessObjectProvider;
 }
        public void SetUp()
        {
            Initialize();

            OptionsMenu = new StubDropDownMenu();
            TextBox     = new StubTextBox();

            Control = MockRepository.GenerateStub <IBocAutoCompleteReferenceValue>();
            Control.Stub(stub => stub.ClientID).Return(c_clientID);
            Control.Stub(stub => stub.ControlType).Return("BocAutoCompleteReferenceValue");
            Control.Stub(stub => stub.GetTextValueName()).Return(c_textValueName);
            Control.Stub(stub => stub.GetKeyValueName()).Return(c_keyValueName);
            Control.Stub(stub => stub.BusinessObjectUniqueIdentifier).Return(c_uniqueidentifier);
            Control.Stub(stub => stub.Command).Return(new BocCommand());
            Control.Command.Type = CommandType.Event;
            Control.Command.Show = CommandShow.Always;
            Control.Stub(stub => stub.SearchServicePath).Return("~/SearchService.asmx");

            Control.Stub(stub => stub.OptionsMenu).Return(OptionsMenu);

            IPage pageStub = MockRepository.GenerateStub <IPage>();

            pageStub.Stub(stub => stub.Form).Return(new HtmlForm());
            Control.Stub(stub => stub.Page).Return(pageStub);

            ClientScriptManagerMock = MockRepository.GenerateMock <IClientScriptManager>();
            pageStub.Stub(stub => stub.ClientScript).Return(ClientScriptManagerMock);

            BusinessObject = TypeWithReference.Create("MyBusinessObject");
            BusinessObject.ReferenceList = new[]
            {
                TypeWithReference.Create("ReferencedObject 0"),
                TypeWithReference.Create("ReferencedObject 1"),
                TypeWithReference.Create("ReferencedObject 2")
            };

            _dataSource = new BusinessObjectReferenceDataSource();
            _dataSource.BusinessObject = (IBusinessObject)BusinessObject;

            _provider = ((IBusinessObject)BusinessObject).BusinessObjectClass.BusinessObjectProvider;
            _provider.AddService <IBusinessObjectWebUIService> (new ReflectionBusinessObjectWebUIService());

            DataSource = new BindableObjectDataSource {
                Type = typeof(TypeWithReference)
            };
            DataSource.Register(Control);

            StateBag stateBag = new StateBag();

            Control.Stub(mock => mock.Attributes).Return(new AttributeCollection(stateBag));
            Control.Stub(mock => mock.Style).Return(Control.Attributes.CssStyle);
            Control.Stub(mock => mock.CommonStyle).Return(new Style(stateBag));
            Control.Stub(mock => mock.LabelStyle).Return(new Style(stateBag));
            Control.Stub(mock => mock.TextBoxStyle).Return(new SingleRowTextBoxStyle());
            Control.Stub(mock => mock.ControlStyle).Return(new Style(stateBag));

            Control.Stub(stub => stub.GetLabelText()).Return("MyText");
            Control.Stub(stub => stub.ResolveClientUrl(null)).IgnoreArguments().Do((Func <string, string>)(url => url.TrimStart('~')));
            Control.Stub(stub => stub.GetResourceManager()).Return(NullResourceManager.Instance);

            _resourceUrlFactory = new FakeResourceUrlFactory();
        }
 /// <summary>
 /// Sets the <see cref="IBusinessObjectProvider"/> to be associated with the <see cref="BusinessObjectProviderAttribute"/> type specified.
 /// </summary>
 /// <typeParam name="TBusinessObjectProviderAttribute">
 /// A <see cref="Type"/> derived from <see cref="BusinessObjectProviderAttribute"/>. Must not be <see langword="null" />.
 /// </typeParam>
 /// <param name="provider">
 /// The <see cref="IBusinessObjectProvider"/> instance to be associated with the <typeParamref name="TBusinessObjectProviderAttribute"/>.
 /// Pass <see langword="null"/> to remove the association.
 /// </param>
 public static void SetProvider <TBusinessObjectProviderAttribute> (IBusinessObjectProvider provider)
     where TBusinessObjectProviderAttribute : BusinessObjectProviderAttribute
 {
     SetProvider(typeof(TBusinessObjectProviderAttribute), provider);
 }