/// <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; }
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)); } }
/// <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); }
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 ); }
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>(); }
/// <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); }
protected void Application_Start() { RouteConfig.RegisterRoutes(RouteTable.Routes); CultureAttribute.Register(); // Load configuration data AppSettings = YbqAppSettings.Initialize(); }
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"); }
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); }
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")); }
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)); }
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); }
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"); }
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)); }
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)); }
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); } }
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); }
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>(); }
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)); }
public abstract byte M(out CultureAttribute i);
public abstract byte M(ref CultureAttribute i);
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" ); }
public void ConstructorAndCulturePropertyTest() { CultureAttribute cultureAttribute = new CultureAttribute("en-US"); Assert.AreEqual("en-US", cultureAttribute.Culture); }
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 ) ); }
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" ); }