public void WithCustomResource()
        {
            CultureInfo prev   = Thread.CurrentThread.CurrentCulture;
            CultureInfo prevUI = Thread.CurrentThread.CurrentUICulture;

            try
            {
                Thread.CurrentThread.CurrentCulture   = CultureInfo.InvariantCulture;
                Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

                ResourceManager resourceManager = new ResourceManager("Castle.Components.Validator.Tests.Messages", typeof(CachedValidationRegistryTestCase).Assembly);
                registry = new CachedValidationRegistry(resourceManager);
                string fromResource = registry.GetStringFromResource("time_invalid");
                Assert.AreEqual("This is a test value", fromResource);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture   = prev;
                Thread.CurrentThread.CurrentUICulture = prevUI;
            }
        }
        public void WillFallbackToDefaultResourceIfNotFoundOnCustomOne()
        {
            CultureInfo prev   = Thread.CurrentThread.CurrentCulture;
            CultureInfo prevUI = Thread.CurrentThread.CurrentUICulture;

            try
            {
                Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture("mk-MK");
                Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("mk-MK");

                ResourceManager resourceManager = new ResourceManager("Castle.Components.Validator.Tests.Messages", typeof(CachedValidationRegistryTestCase).Assembly);
                registry = new CachedValidationRegistry(resourceManager);
                string fromResource = registry.GetStringFromResource("collection_not_empty");
                Assert.AreEqual("Collection must not be empty", fromResource);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture   = prev;
                Thread.CurrentThread.CurrentUICulture = prevUI;
            }
        }
예제 #3
0
        /// <summary>
        /// Initializes the MethodValidatorFacility
        /// </summary>
        protected override void Init()
        {
            IValidatorRegistry registry;

            if (Kernel.HasComponent(typeof(IValidatorRegistry)))
            {
                registry = Kernel.Resolve <IValidatorRegistry>();
            }
            else
            {
                registry = new CachedValidationRegistry();
            }

            IValidatorRegistry adapter = new ParameterValidatorRegistryAdapter(registry);

            Kernel.AddComponentInstance("methodValidator.metaStore", new MethodValidatorMetaStore(adapter));

            Kernel.AddComponent("methodValidator.interceptor", typeof(MethodValidatorInterceptor));
            Kernel.AddComponent("methodValidator.contributor", typeof(MethodValidationContributor));
            Kernel.ComponentModelBuilder.AddContributor(new MethodValidatorComponentInspector());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="StubMonoRailServices"/> class.
        /// </summary>
        /// <param name="urlBuilder">The URL builder.</param>
        /// <param name="filterFactory">The filter factory.</param>
        /// <param name="viewEngineManager">The view engine manager.</param>
        /// <param name="actionSelector">The action selector.</param>
        /// <param name="dynamicActionProviderFactory">The dynamic action provider factory.</param>
        public StubMonoRailServices(IUrlBuilder urlBuilder, IFilterFactory filterFactory, IViewEngineManager viewEngineManager,
                                    IActionSelector actionSelector, IDynamicActionProviderFactory dynamicActionProviderFactory)
        {
            this.UrlBuilder                   = urlBuilder;
            this.FilterFactory                = filterFactory;
            this.ViewEngineManager            = viewEngineManager;
            this.ActionSelector               = actionSelector;
            this.DynamicActionProviderFactory = dynamicActionProviderFactory;
            controllerTree         = new DefaultControllerTree();
            ControllerFactory      = new DefaultControllerFactory(controllerTree);
            StaticResourceRegistry = new DefaultStaticResourceRegistry();

            ControllerContextFactory = new DefaultControllerContextFactory();

            ControllerDescriptorProvider = new DefaultControllerDescriptorProvider(
                new DefaultHelperDescriptorProvider(),
                new DefaultFilterDescriptorProvider(),
                new DefaultLayoutDescriptorProvider(),
                new DefaultRescueDescriptorProvider(),
                new DefaultResourceDescriptorProvider(),
                new DefaultTransformFilterDescriptorProvider(),
                new DefaultReturnBinderDescriptorProvider(),
                new DefaultDynamicActionProviderDescriptorProvider());

            ResourceFactory    = new DefaultResourceFactory();
            ScaffoldingSupport = new StubScaffoldingSupport();
            CacheProvider      = new StubCacheProvider();
            HelperFactory      = new DefaultHelperFactory();
            ServiceInitializer = new DefaultServiceInitializer();

            ExtensionManager = new ExtensionManager(this);

            ValidatorRegistry = new CachedValidationRegistry();

            JSONSerializer = new NewtonsoftJSONSerializer();

            DictionaryAdapterFactory = new DictionaryAdapterFactory();

            ScriptBuilder = new DefaultScriptBuilder();
        }
예제 #5
0
 public void SetUp()
 {
     cachedValidationRegistry = new CachedValidationRegistry(new ResourceManager("Castle.Components.Validator.Messages", typeof(CachedValidationRegistry).Assembly));
     runner = new ValidatorRunner(cachedValidationRegistry);
 }
		public void WithCustomResource()
		{
			CultureInfo prev = Thread.CurrentThread.CurrentCulture;
			CultureInfo prevUI = Thread.CurrentThread.CurrentUICulture;
			try
			{
				Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
				Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

				ResourceManager resourceManager = new ResourceManager("Castle.Components.Validator.Tests.Messages", typeof(CachedValidationRegistryTestCase).Assembly);
				registry = new CachedValidationRegistry(resourceManager);
				string fromResource = registry.GetStringFromResource("time_invalid");
				Assert.AreEqual("This is a test value", fromResource);
			}
			finally
			{
				Thread.CurrentThread.CurrentCulture = prev;
				Thread.CurrentThread.CurrentUICulture = prevUI;
			}

		}
		public void Init()
		{
			registry = new CachedValidationRegistry();
		}
		public void WillFallbackToDefaultResourceIfNotFoundOnCustomOne()
		{
			CultureInfo prev = Thread.CurrentThread.CurrentCulture;
			CultureInfo prevUI = Thread.CurrentThread.CurrentUICulture;
			try
			{
				Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("mk-MK");
				Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("mk-MK");

				ResourceManager resourceManager = new ResourceManager("Castle.Components.Validator.Tests.Messages", typeof(CachedValidationRegistryTestCase).Assembly);
				registry = new CachedValidationRegistry(resourceManager);
				string fromResource = registry.GetStringFromResource("collection_not_empty");
				Assert.AreEqual("Collection must not be empty", fromResource);
			}
			finally
			{
				Thread.CurrentThread.CurrentCulture = prev;
				Thread.CurrentThread.CurrentUICulture = prevUI;
			}
		}
 public void Init()
 {
     registry = new CachedValidationRegistry();
 }
 public void SetUp()
 {
     cachedValidationRegistry = new CachedValidationRegistry(new ResourceManager("Castle.Components.Validator.Messages", typeof(CachedValidationRegistry).Assembly));
     runner = new ValidatorRunner(cachedValidationRegistry);
 }