Inheritance: ActionFilterAttribute
コード例 #1
0
		/// <summary>
		/// Tests to determine if the current culture is supported
		/// based on a culture attribute.
		/// </summary>
		/// <param name="cultureAttribute">The attribute to examine</param>
		/// <returns></returns>
		public bool IsCultureSupported( CultureAttribute cultureAttribute )
		{
            string include = cultureAttribute.Include;
            string exclude = cultureAttribute.Exclude;

            //try
            //{
				if (include != null && !IsCultureSupported(include))
				{
					reason = string.Format("Only supported under culture {0}", include);
					return false;
				}

				if (exclude != null && IsCultureSupported(exclude))
				{
					reason = string.Format("Not supported under culture {0}", exclude);
					return false;
				}
            //}
            //catch( ArgumentException ex )
            //{
            //    reason = string.Format( "Invalid culture: {0}", ex.ParamName );
            //    return false; 
            //}

			return true;
		}
コード例 #2
0
 private void ExpectMatch(CultureAttribute attr)
 {
     if (!detector.IsCultureSupported(attr))
     {
         Assert.Fail(string.Format("Failed to match attribute with Include=\"{0}\",Exclude=\"{1}\"", attr.Include, attr.Exclude));
     }
 }
コード例 #3
0
        /// <summary>
        /// Tests to determine if the current culture is supported
        /// based on a culture attribute.
        /// </summary>
        /// <param name="cultureAttribute">The attribute to examine</param>
        /// <returns></returns>
        public bool IsCultureSupported(CultureAttribute cultureAttribute)
        {
            string include = cultureAttribute.Include;
            string exclude = cultureAttribute.Exclude;

            //try
            //{
            if (include != null && !IsCultureSupported(include))
            {
                reason = string.Format("Only supported under culture {0}", include);
                return(false);
            }

            if (exclude != null && IsCultureSupported(exclude))
            {
                reason = string.Format("Not supported under culture {0}", exclude);
                return(false);
            }
            //}
            //catch( ArgumentException ex )
            //{
            //    reason = string.Format( "Invalid culture: {0}", ex.ParamName );
            //    return false;
            //}

            return(true);
        }
コード例 #4
0
		private void ExpectFailure( CultureAttribute attr, string msg )
		{
			if ( detector.IsCultureSupported( attr ) )
				Assert.Fail( string.Format( "Should not match attribute with Include=\"{0}\",Exclude=\"{1}\"",
					attr.Include, attr.Exclude ) );
			Assert.AreEqual( msg, detector.Reason );
		}
コード例 #5
0
 public void SetUpMethod()
 {
     this._cultureAttribute = new CultureAttribute();;
     this._filterContext    = new Mock <ActionExecutedContext>();
     this._httpContext      = new Mock <HttpContextBase>();
     this._httpRequest      = new Mock <HttpRequestBase>();
     this._routeData        = new Mock <RouteData>();
 }
コード例 #6
0
ファイル: AppController.cs プロジェクト: kshurov/NextGen
        /// <summary>
        /// Switch the current UI culture
        /// </summary>
        /// <param name="id"></param>
        /// <param name="returnUrl"></param>
        public void Lang(string id, string returnUrl)
        {
            // Set culture to use next
            CultureAttribute.SavePreferredCulture(HttpContext.Response, id);

            // Return to the calling URL (or go to the site's home page)
            HttpContext.Response.Redirect(returnUrl);
        }
コード例 #7
0
        protected void Application_Start()
        {
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            CultureAttribute.Register();

            // Load configuration data
            AppSettings = YbqAppSettings.Initialize();
        }
コード例 #8
0
        public void CanMatchAttributeWithIncludeAndExclude()
        {
            CultureAttribute attr = new CultureAttribute("en,fr,de,it");

            attr.Exclude = "fr-CA,fr-BE";
            ExpectMatch(attr);
            attr.Exclude = "fr-FR";
            ExpectFailure(attr, "Not supported under culture fr-FR");
        }
コード例 #9
0
 private void ExpectFailure(CultureAttribute attr, string msg)
 {
     if (detector.IsCultureSupported(attr))
     {
         Assert.Fail(string.Format("Should not match attribute with Include=\"{0}\",Exclude=\"{1}\"",
                                   attr.Include, attr.Exclude));
     }
     Assert.AreEqual(msg, detector.Reason);
 }
コード例 #10
0
ファイル: HomeController.cs プロジェクト: radtek/Ninja
        public ActionResult Language(string culture_)
        {
            CultureAttribute.SavePreferredCulture(Response, culture_, 1);

            System.Globalization.CultureInfo cultureInfo = GetCulture(culture_);

            Thread.CurrentThread.CurrentCulture   = cultureInfo;
            Thread.CurrentThread.CurrentUICulture = cultureInfo;

            return(RedirectToAction("Index"));
        }
コード例 #11
0
        public void CultureAttributeExcludingCurrentCultureSkipsTest()
        {
            string           name = System.Globalization.CultureInfo.CurrentCulture.Name;
            CultureAttribute attr = new CultureAttribute(name);

            attr.Exclude = name;
            attr.ApplyToTest(test);
            Assert.That(test.RunState, Is.EqualTo(RunState.Skipped));
            Assert.That(test.Properties.Get(PropertyNames.SkipReason),
                        Is.EqualTo("Not supported under culture " + name));
        }
コード例 #12
0
        public void AutoImplementGenericMethod()
        {
            Type        t = typeof(K);
            TypeBuilder b = CreateTypeBuilder(t);

            EmitHelper.ImplementEmptyStubMethod(b, t.GetMethod("M"), false);
            Type             builtType = b.CreateTypeInfo().AsType();
            K                o         = (K)Activator.CreateInstance(builtType);
            CultureAttribute cOrigin   = new CultureAttribute();
            CultureAttribute c         = cOrigin;

            Assert.That(o.M <int>(), Is.Null);
        }
コード例 #13
0
        public void CanMatchAttributeWithExclude()
        {
            CultureAttribute attr = new CultureAttribute();

            attr.Exclude = "en";
            ExpectMatch(attr);
            attr.Exclude = "en,de,it";
            ExpectMatch(attr);
            attr.Exclude = "fr";
            ExpectFailure(attr, "Not supported under culture fr");
            attr.Exclude = "fr-FR,fr-BE,fr-CA";
            ExpectFailure(attr, "Not supported under culture fr-FR,fr-BE,fr-CA");
        }
コード例 #14
0
        public void AutoImplementStubRefClass()
        {
            Type        t = typeof(J);
            TypeBuilder b = CreateTypeBuilder(t);

            EmitHelper.ImplementEmptyStubMethod(b, t.GetMethod("M"), false);
            Type             builtType = b.CreateTypeInfo().AsType();
            J                o         = (J)Activator.CreateInstance(builtType);
            CultureAttribute cOrigin   = new CultureAttribute();
            CultureAttribute c         = cOrigin;

            Assert.That(o.M(ref c), Is.EqualTo(0));
            Assert.That(c, Is.SameAs(cOrigin));
        }
コード例 #15
0
        public void CultureAttributeExcludingOtherCultureRunsTest()
        {
            string other = "fr-FR";

            if (System.Globalization.CultureInfo.CurrentCulture.Name == other)
            {
                other = "en-US";
            }

            CultureAttribute attr = new CultureAttribute();

            attr.Exclude = other;
            attr.ApplyToTest(test);
            Assert.That(test.RunState, Is.EqualTo(RunState.Runnable));
        }
コード例 #16
0
        public void Set(String lang)
        {
            try
            {
                // Set culture to use next
                CultureAttribute.SavePreferredCulture(HttpContext.Response, lang);

                // Return to the calling URL (or go to the site's home page)
                HttpContext.Response.Redirect(HttpContext.Request.UrlReferrer.AbsolutePath);
            }
            catch (Exception ex)
            {
                NLog_logger.Loger.Error(ex);
            }
        }
コード例 #17
0
        public bool IsCultureSupported(CultureAttribute cultureAttribute)
        {
            string include = cultureAttribute.Include;
            string exclude = cultureAttribute.Exclude;

            if (include != null && !IsCultureSupported(include))
            {
                reason = $"Only supported under culture {include}";
                return(false);
            }
            if (exclude != null && IsCultureSupported(exclude))
            {
                reason = $"Not supported under culture {exclude}";
                return(false);
            }
            return(true);
        }
コード例 #18
0
ファイル: Global.asax.cs プロジェクト: kshurov/NextGen
        protected void Application_Start()
        {
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            CultureAttribute.Register();

            // Load configuration data
            AppSettings = TaskZeroSettings.Initialize();

            // Configure the MementoFX
            var container = MementoStartup.UnityConfig <InMemoryBus, MongoDbEventStore>();

            // Save global references to the FX core elements
            Bus = container.Resolve <IBus>();
            AggregateRepository = container.Resolve <IRepository>();
            // Add sagas and handlers to the bus
            Bus.RegisterSaga <ManageTaskSaga>();
            Bus.RegisterHandler <NotificationHandler>();
            Bus.RegisterHandler <ManageTaskDenormalizer>();
        }
コード例 #19
0
        public void CultureAttributeExcludingOtherCultureRunsTest()
        {
            string other = "fr-FR";
            if (System.Globalization.CultureInfo.CurrentCulture.Name == other)
                other = "en-US";

            CultureAttribute attr = new CultureAttribute();
            attr.Exclude = other;
            attr.ApplyToTest(test);
            Assert.That(test.RunState, Is.EqualTo(RunState.Runnable));
        }
コード例 #20
0
 public void CultureAttributeExcludingCurrentCultureSkipsTest()
 {
     string name = System.Globalization.CultureInfo.CurrentCulture.Name;
     CultureAttribute attr = new CultureAttribute(name);
     attr.Exclude = name;
     attr.ApplyToTest(test);
     Assert.That(test.RunState, Is.EqualTo(RunState.Skipped));
     Assert.That(test.Properties.Get(PropertyNames.SkipReason),
         Is.EqualTo("Not supported under culture " + name));
 }
コード例 #21
0
 public abstract byte M(out CultureAttribute i);
コード例 #22
0
 public abstract byte M(ref CultureAttribute i);
コード例 #23
0
		public void CanMatchAttributeWithExclude()
		{
			CultureAttribute attr = new CultureAttribute();
			attr.Exclude = "en";
			ExpectMatch( attr );
			attr.Exclude = "en,de,it";
			ExpectMatch( attr );
			attr.Exclude = "fr";
			ExpectFailure( attr, "Not supported under culture fr");
			attr.Exclude = "fr-FR,fr-BE,fr-CA";
			ExpectFailure( attr, "Not supported under culture fr-FR,fr-BE,fr-CA" );
		}
コード例 #24
0
        public void ConstructorAndCulturePropertyTest()
        {
            CultureAttribute cultureAttribute = new CultureAttribute("en-US");

            Assert.AreEqual("en-US", cultureAttribute.Culture);
        }
コード例 #25
0
		private void ExpectMatch( CultureAttribute attr )
		{
			if ( !detector.IsCultureSupported( attr ) )
				Assert.Fail( string.Format( "Failed to match attribute with Include=\"{0}\",Exclude=\"{1}\"", attr.Include, attr.Exclude ) );
		}
コード例 #26
0
		public void CanMatchAttributeWithIncludeAndExclude()
		{
			CultureAttribute attr = new CultureAttribute( "en,fr,de,it" );
			attr.Exclude="fr-CA,fr-BE";
			ExpectMatch( attr );
			attr.Exclude = "fr-FR";
			ExpectFailure( attr, "Not supported under culture fr-FR" );
		}