public void DescriptorIsCreatedForControllerAndAction()
		{
			helperDescProviderMock = mockRepository.DynamicMock<IHelperDescriptorProvider>();
			filterDescProviderMock = mockRepository.DynamicMock<IFilterDescriptorProvider>();
			layoutDescProviderMock = mockRepository.DynamicMock<ILayoutDescriptorProvider>();
			rescueDescProviderMock = mockRepository.DynamicMock<IRescueDescriptorProvider>();
			resourceProviderMock = mockRepository.DynamicMock<IResourceDescriptorProvider>();
			transformDescProviderMock = mockRepository.DynamicMock<ITransformFilterDescriptorProvider>();
			returnTypeDescProviderMock = mockRepository.DynamicMock<IReturnBinderDescriptorProvider>();
			dynamicActionProviderDescProviderMock = mockRepository.DynamicMock<IDynamicActionProviderDescriptorProvider>();

			provider = new DefaultControllerDescriptorProvider(helperDescProviderMock,
															   filterDescProviderMock,
															   layoutDescProviderMock,
															   rescueDescProviderMock,
															   resourceProviderMock,
															   transformDescProviderMock, returnTypeDescProviderMock,
															   dynamicActionProviderDescProviderMock);

			Type controllerType = typeof(SingleActionController);
			MethodInfo actionMethod = controllerType.GetMethod("Action1");

			using(mockRepository.Record())
			{
				// Controller level
				Expect.Call(helperDescProviderMock.CollectHelpers(controllerType)).Return(new HelperDescriptor[0]);
				Expect.Call(resourceProviderMock.CollectResources(controllerType)).Return(new ResourceDescriptor[0]);
				Expect.Call(filterDescProviderMock.CollectFilters(controllerType)).Return(new FilterDescriptor[0]);
				Expect.Call(layoutDescProviderMock.CollectLayout(controllerType)).Return(null);
				Expect.Call(rescueDescProviderMock.CollectRescues(controllerType)).Return(new RescueDescriptor[0]);
			
				// Action level
				Expect.Call(resourceProviderMock.CollectResources(actionMethod)).Return(new ResourceDescriptor[0]);
				Expect.Call(rescueDescProviderMock.CollectRescues(actionMethod)).Return(new RescueDescriptor[0]);
				Expect.Call(layoutDescProviderMock.CollectLayout(actionMethod)).Return(null);
				Expect.Call(transformDescProviderMock.CollectFilters(actionMethod)).Return(new TransformFilterDescriptor[0]);
				Expect.Call(returnTypeDescProviderMock.Collect(actionMethod)).Return(null);
				Expect.Call(dynamicActionProviderDescProviderMock.CollectProviders(controllerType)).Return(
					new DynamicActionProviderDescriptor[0]);
			}

			using(mockRepository.Playback())
			{
				ControllerMetaDescriptor metaDesc = provider.BuildDescriptor(controllerType);
				Assert.IsNotNull(metaDesc);
				ActionMetaDescriptor actionMetaDesc = metaDesc.GetAction(actionMethod);
				Assert.IsNotNull(actionMetaDesc);
				Assert.IsNull(actionMetaDesc.AccessibleThrough);
			}
		}
		private void BuildDescriptor()
		{
			provider = new DefaultControllerDescriptorProvider(new DefaultHelperDescriptorProvider(),
															   new DefaultFilterDescriptorProvider(), new DefaultLayoutDescriptorProvider(),
															   new DefaultRescueDescriptorProvider(), new DefaultResourceDescriptorProvider(),
															   new DefaultTransformFilterDescriptorProvider(), new DefaultReturnBinderDescriptorProvider(), 
															   new DefaultDynamicActionProviderDescriptorProvider());
		}
Exemplo n.º 3
0
 public void Controllers(){
     var controllers =
         Container.all<Controller>().Select(c => ControllerInspectionUtil.Inspect(c.GetType())).OrderBy(
             c => c.Name);
     var descb = new DefaultControllerDescriptorProvider();
     Func<ControllerDescriptor, ControllerMetaDescriptor> desc =
         c =>
         ((IControllerDescriptorProvider) Context.GetService(typeof (IControllerDescriptorProvider))).
             BuildDescriptor(
             c.ControllerType);
     Func<MethodInfo, string> getsyg = i =>
                                       i.toSygnatureString();
     Func<MethodInfo, ActionDescriptionAttribute> getmeta = i =>{
                                                                var descs =
                                                                    i.GetCustomAttributes(
                                                                        typeof (ActionDescriptionAttribute),
                                                                        true)
                                                                        .Cast
                                                                        <ActionDescriptionAttribute>().ToList
                                                                        ();
                                                                if (descs.yes()){
                                                                    return descs[0];
                                                                }
                                                                return
                                                                    new ActionDescriptionAttribute(
                                                                        "нет данных");
                                                            };
     Func<IDynamicActionHandler, ActionDescriptionAttribute> getvmeta = i =>{
                                                                            var descs =
                                                                                i.GetType().
                                                                                    GetCustomAttributes(
                                                                                    typeof (
                                                                                        ActionDescriptionAttribute
                                                                                        ), true)
                                                                                    .Cast
                                                                                    <
                                                                                        ActionDescriptionAttribute
                                                                                        >().ToList();
                                                                            if (descs.yes()){
                                                                                return descs[0];
                                                                            }
                                                                            return
                                                                                new ActionDescriptionAttribute
                                                                                    ("нет данных");
                                                                        };
     PropertyBag["controllers"] = controllers;
     PropertyBag["dynamics"] =
         Container.all<IDynamicActionHandler>();
     PropertyBag["desc"] = desc;
     PropertyBag["getsyg"] = getsyg;
     PropertyBag["getmeta"] = getmeta;
     PropertyBag["getvmeta"] = getvmeta;
 }