Exemple #1
0
        private static void AssertTranslationExists(string culture, IEnumerable <string> ids, string category)
        {
            var options = new LocaleOptions
            {
                Locale = culture
            };
            var service = new GlobalizedLocalizationService(options);
            var notFoundTranslations = new List <string>();

            foreach (var scopeId in ids)
            {
                var localizedString = service.GetString(category, scopeId);
                if (string.IsNullOrEmpty(localizedString))
                {
                    var errormsg = string.Format("Could not find translation of Id '{0}' in {1}", scopeId,
                                                 string.IsNullOrEmpty(culture) ? "IdentityServers internals" : culture);
                    notFoundTranslations.Add(errormsg);
                }
                else
                {
                    Assert.NotEqual("", localizedString.Trim());
                }
            }
            if (notFoundTranslations.Any())
            {
                var concated = notFoundTranslations.Aggregate((x, y) => x + ", " + y);
                throw new AssertActualExpectedException("Some translation", "NOTHING!", concated);
            }
        }
 private void Validate(LocaleOptions options)
 {
     if (options.Locale == null || options.Locale.Trim() == string.Empty || !GetAvailableLocales().Contains(options.Locale))
     {
         throw new ApplicationException(string.Format("Localization '{0}' unavailable. Create a Pull Request on GitHub!", options.Locale));
     }
 }
        private static void AssertTranslationExists(string culture, IEnumerable<string> ids, string category)
        {
            var options = new LocaleOptions
            {
                Locale = culture
            };
            var service = new GlobalizedLocalizationService(options);
            var notFoundTranslations = new List<string>();
            
            foreach (var id in ids)
            {
                var localizedString = service.GetString(category, id);
                if (string.IsNullOrEmpty(localizedString))
                {
                    var errormsg = string.Format("Could not find translation of Id '{0}' in {1}", id,
                        string.IsNullOrEmpty(culture) ? "IdentityServers internals" : culture);
                    notFoundTranslations.Add(errormsg);

                }
                else
                {
                    string message = string.Format("{0} - {1}:{2} - {3}", culture, category, id, localizedString);
                    Trace.WriteLine(message);
                    Debug.WriteLine(message);
                    Console.WriteLine(message);
                    Assert.NotEqual("", localizedString.Trim());    
                }
                
            }
            if (notFoundTranslations.Any())
            {
                var concated = notFoundTranslations.Aggregate((x, y) => x + ", " + y);
                throw new AssertActualExpectedException("Some translation", "NOTHING!", concated );
            }
        }
 public void ThrowsExceptionForUnknownLocales(string locale)
 {
     var options = new LocaleOptions
     {
         Locale = locale
     };
     Assert.Throws<ApplicationException>(() => new GlobalizedLocalizationService(options));
 }
Exemple #5
0
        public void ThrowsExceptionForUnknownLocales(string locale)
        {
            var options = new LocaleOptions
            {
                Locale = locale
            };

            Assert.Throws <ApplicationException>(() => new GlobalizedLocalizationService(options));
        }
Exemple #6
0
        public void ShouldThrowExceptionForNotFoundLocale()
        {
            var options = new LocaleOptions
            {
                Locale = "notexisting"
            };

            Assert.Throws <ApplicationException>(() => new GlobalizedLocalizationService(options));
        }
 public static ILocalizationService Create(LocaleOptions options)
 {
     var inner = AvailableLocalizationServices[options.Locale];
     if (options.FallbackLocalizationService != null)
     {
         return new FallbackDecorator(inner, options.FallbackLocalizationService);
     }
     return new FallbackDecorator(inner, AvailableLocalizationServices[Constants.Default]);
 }
Exemple #8
0
        public static ILocalizationService Create(LocaleOptions options)
        {
            var inner = AvailableLocalizationServices[options.Locale];

            if (options.FallbackLocalizationService != null)
            {
                return(new FallbackDecorator(inner, options.FallbackLocalizationService));
            }
            return(new FallbackDecorator(inner, AvailableLocalizationServices[Constants.Default]));
        }
Exemple #9
0
        public void ContainsEnglishLocalesAsWell(string locale)
        {
            var env     = new Dictionary <string, object>();
            var options = new LocaleOptions
            {
                LocaleProvider = e => locale
            };
            var global   = new GlobalizedLocalizationService(new OwinEnvironmentService(env), options);
            var resource = global.GetString(IdSrvConstants.Messages, MessageIds.MissingClientId);

            Assert.Equal("client_id is missing", resource);
        }
Exemple #10
0
        public void FetchesResourceWhenUsingLocaleProviderFunc()
        {
            var options = new LocaleOptions
            {
                LocaleProvider = env => "nb-NO"
            };
            var envServiceMock = new Fake <OwinEnvironmentService>().FakedObject;

            var service         = new GlobalizedLocalizationService(envServiceMock, options);
            var norwegianString = service.GetString(IdSrvConstants.Messages, MessageIds.MissingClientId);

            Assert.Equal("ClientId mangler", norwegianString);
        }
Exemple #11
0
        public void UnknownLocalesUseDefaultLocale(string locale)
        {
            var options = new LocaleOptions
            {
                LocaleProvider = env => locale
            };

            var envServiceMock = new Fake <OwinEnvironmentService>().FakedObject;

            var service = new GlobalizedLocalizationService(envServiceMock, options);

            var resource = service.GetString(IdSrvConstants.Messages, MessageIds.MissingClientId);

            Assert.Equal("client_id is missing", resource);
        }
Exemple #12
0
        public static IdentityServerServiceFactory Configure(string connString, string schema)
        {
            var efConfig = new EntityFrameworkServiceOptions
            {
                ConnectionString = connString,
                Schema           = schema,
                //SynchronousReads = true
            };

            // these two calls just pre-populate the test DB from the in-memory configuration
            ConfigureClients(Clients.Get(true), efConfig);
            ConfigureScopes(Scopes.Get(), efConfig);

            var factory = new IdentityServerServiceFactory();

            factory.RegisterConfigurationServices(efConfig);
            factory.RegisterOperationalServices(efConfig);

            factory.ConfigureClientStoreCache();
            factory.ConfigureScopeStoreCache();

            factory.CorsPolicyService = new Registration <ICorsPolicyService>(new DefaultCorsPolicyService {
                AllowAll = true
            });

            var localeOpts = new LocaleOptions
            {
                LocaleProvider = env =>
                {
                    var owinContext            = new OwinContext(env);
                    var owinRequest            = owinContext.Request;
                    var headers                = owinRequest.Headers;
                    var accept_language_header = headers["accept-language"].ToString();
                    var languages              = accept_language_header
                                                 .Split(',')
                                                 .Select(StringWithQualityHeaderValue.Parse)
                                                 .OrderByDescending(s => s.Quality.GetValueOrDefault(1));
                    var locale = languages.First().Value;

                    return(locale);
                }
            };

            factory.Register(new Registration <LocaleOptions>(localeOpts));
            factory.LocalizationService = new Registration <ILocalizationService, GlobalizedLocalizationService>();

            return(factory);
        }
Exemple #13
0
        public void FetchesResrouceBasedOnOwinEnvironment()
        {
            IDictionary <string, object> environment = new Dictionary <string, object>();

            environment["UserSettings.Language"] = "nb-NO";
            var owinEnvironmentService = new OwinEnvironmentService(environment);
            var options = new LocaleOptions
            {
                LocaleProvider = env => env["UserSettings.Language"].ToString()
            };

            var service         = new GlobalizedLocalizationService(owinEnvironmentService, options);
            var norwegianString = service.GetString(IdSrvConstants.Messages, MessageIds.MissingClientId);

            Assert.Equal("ClientId mangler", norwegianString);
        }
Exemple #14
0
        public void Configuration(IAppBuilder app)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.Trace()
                         .CreateLogger();

            app.Map("/core", coreApp =>
            {
                var factory = new IdentityServerServiceFactory()
                              .UseInMemoryUsers(Users.Get())
                              .UseInMemoryClients(Clients.Get())
                              .UseInMemoryScopes(Scopes.Get());


                var opts = new LocaleOptions
                {
                    LocaleProvider = env =>
                    {
                        var owinContext            = new OwinContext(env);
                        var owinRequest            = owinContext.Request;
                        var headers                = owinRequest.Headers;
                        var accept_language_header = headers["accept-language"].ToString();
                        var languages              = accept_language_header.Split(',').Select(StringWithQualityHeaderValue.Parse).OrderByDescending(s => s.Quality.GetValueOrDefault(1));
                        var locale = languages.First().Value;

                        return(locale);
                    }
                };
                factory.Register(new Registration <LocaleOptions>(opts));
                factory.LocalizationService = new Registration <ILocalizationService, GlobalizedLocalizationService>();


                var options = new IdentityServerOptions
                {
                    SiteName = "IdentityServer33 - Localized from accept-language http header Messages",

                    SigningCertificate = Certificate.Get(),
                    Factory            = factory
                };

                coreApp.UseIdentityServer(options);
            });
        }
Exemple #15
0
        public void UsesFallbackWhenIsSet()
        {
            const string someid = "SomeId";
            var          mock   = new Fake <ILocalizationService>();

            mock.CallsTo(loc => loc.GetString(IdSrvConstants.Messages, someid)).Returns("fallbackValue");

            var localeOptions = new LocaleOptions
            {
                LocaleProvider = env => "nb-NO",
                FallbackLocalizationService = mock.FakedObject
            };
            var envServiceMock = new Fake <OwinEnvironmentService>();
            var service        = new GlobalizedLocalizationService(envServiceMock.FakedObject, localeOptions);

            var result = service.GetString(IdSrvConstants.Messages, someid);

            Assert.Equal("fallbackValue", result);
        }
Exemple #16
0
        // ===========================================================================
        // = Public Methods
        // ===========================================================================

        public IDictionary <string, string> GenerateParameters()
        {
            IDictionary <string, string> parameters = new Dictionary <string, string>();

            if (GeneralOptions != null)
            {
                parameters = parameters.MergeWith(GeneralOptions.GenerateParameters());
            }

            if (LocaleOptions != null)
            {
                parameters = parameters.MergeWith(LocaleOptions.GenerateParameters());
            }

            if (LocationOptions != null)
            {
                parameters = parameters.MergeWith(LocationOptions.GenerateParameters());
            }

            return(parameters);
        }
        private void ParseConnectionString()
        {
            if (_connectionString != String.Empty)
            {
                _connectionProperties = SplitConnectionString(_connectionString);
                // if data source = $Embedded$ then mark Ppvt option as selected
                var dataSrc = _connectionProperties["Data Source"];

                if (_ppvtRegex.Match(dataSrc).Success) // if we are connected to PowerPivot
                {
                    PowerBIModeSelected    = false;
                    ServerModeSelected     = false;
                    PowerPivotModeSelected = true;
                    NotifyOfPropertyChange(() => PowerPivotModeSelected);
                }
                else
                {
                    if (_connectionProperties.ContainsKey("Application Name"))
                    {
                        if (_connectionProperties["Application Name"].StartsWith("DAX Studio (Power BI)"))
                        {
                            PowerPivotModeSelected = false;
                            ServerModeSelected     = false;
                            PowerBIModeSelected    = true;
                            NotifyOfPropertyChange(() => PowerBIModeSelected);
                        }
                    }
                    foreach (var p in _connectionProperties)
                    {
                        switch (p.Key.ToLower())
                        {
                        case "data source":
                            DataSource = PowerBIModeSelected ? "": p.Value;
                            break;

                        case "roles":
                            Roles = p.Value;
                            break;

                        case "effectiveusername":
                            EffectiveUserName = p.Value;
                            break;

                        case "mdx compatibility":
                            MdxCompatibility = MdxCompatibilityOptions.Find(x => x.StartsWith(p.Value));
                            break;

                        case "directquerymode":
                            DirectQueryMode = p.Value;
                            break;

                        case "application name":
                            ApplicationName = p.Value;
                            break;

                        case "locale identifier":
                            Locale = LocaleOptions.GetByLcid(int.Parse(p.Value));
                            break;

                        case "show hidden cubes":
                            // do nothing
                            break;

                        default:
                            AdditionalOptions += string.Format("{0}={1};", p.Key, p.Value);
                            break;
                        }
                    }
                }
            }
            else
            {
                if (!PowerPivotModeSelected)
                {
                    ServerModeSelected = true;
                }
                if (RecentServers.Count > 0)
                {
                    DataSource = RecentServers[0];
                }
            }
        }
Exemple #18
0
 public GlobalizedLocalizationService(LocaleOptions options = null)
 {
     _service = LocalizationServiceFactory.Create(options);
 }
 public GlobalizedLocalizationService(LocaleOptions options = null)
 {
     var internalOpts = options ?? new LocaleOptions();
     Validate(internalOpts);
     _service = LocalizationServiceFactory.Create(internalOpts);
 }