public override void Configure(Container container) { LogManager.LogFactory = new ConsoleLogFactory(); IAppSettings appSettings = new DictionarySettings( new Dictionary<string, string> { { "backup.history", "5" }, { "auth.api-keys", "1337"} }); container.Register(c => appSettings); container.RegisterAutoWired<IISManager>(); container.RegisterAs<AppSettingsApiKeyValidator, IApiKeyValidator>(); Plugins.Add(new RequestLogsFeature { RequiredRoles = null }); }
public void ShouldInitializeSettings() { var settings = new Dictionary<string, string> { { "oauth.aad.TenantId", "tenant789" }, { "oauth.aad.ClientId", "client1234" }, { "oauth.aad.ClientSecret", "secret456" }, { "oauth.aad.CallbackUrl", "http://example.com/auth" }, { "oauth.aad.DomainHint", "servicestack.net" }, { "oauth.aad.ResourceId", "r2d2" }, { "oauth.aad.FailureRedirectPath", "/bad/news" }, }; var appSettings = new DictionarySettings(settings); Subject = new AadAuthProvider(appSettings); Subject.TenantId.Should().Be("tenant789"); Subject.ClientId.Should().Be("client1234"); Subject.ClientSecret.Should().Be("secret456"); Subject.ConsumerKey.Should().Be(Subject.ClientId); Subject.ConsumerSecret.Should().Be(Subject.ClientSecret); Subject.AuthorizeUrl.Should().Be("https://login.microsoftonline.com/tenant789/oauth2/authorize"); Subject.AccessTokenUrl.Should().Be("https://login.microsoftonline.com/tenant789/oauth2/token"); Subject.CallbackUrl.Should().Be("http://example.com/auth"); Subject.DomainHint.Should().Be("servicestack.net"); Subject.ResourceId.Should().Be("r2d2"); Subject.FailureRedirectPath.Should().Be("/bad/news"); }
public void Can_preload_AppSettings() { GetAppSettings(); var allSettings = new Dictionary<string, string>(); Db.ScanAll<ConfigSetting>().Each(x => allSettings[x.Id] = x.Value); var cachedSettings = new DictionarySettings(allSettings); Assert.That(cachedSettings.Get("RealKey"), Is.EqualTo("This is a real value")); }
public void ShouldUseGivenUrls() { var settings = new Dictionary<string, string> { { "oauth.aad.AuthorizeUrl", "https://authorize.example" }, { "oauth.aad.AccessTokenUrl", "https://token.example" }, }; var appSettings = new DictionarySettings(settings); Subject = new AadAuthProvider(appSettings); Subject.AuthorizeUrl.Should().Be("https://authorize.example"); Subject.AccessTokenUrl.Should().Be("https://token.example"); }
public void Does_work_with_ParseKeyValueText() { var textFile = @" EmptyKey RealKey This is a real value ListKey A,B,C,D,E IntKey 42 DictionaryKey A:1,B:2,C:3,D:4,E:5 ObjectKey {SomeSetting:Test,SomeOtherSetting:12,FinalSetting:Final}"; var settings = textFile.ParseKeyValueText(); var appSettings = new DictionarySettings(settings); Assert.That(appSettings.Get("EmptyKey"), Is.EqualTo("")); Assert.That(appSettings.Get("RealKey"), Is.EqualTo("This is a real value")); Assert.That(appSettings.Get("IntKey", defaultValue: 1), Is.EqualTo(42)); var list = appSettings.GetList("ListKey"); Assert.That(list, Has.Count.EqualTo(5)); Assert.That(list, Is.EqualTo(new List<string> { "A", "B", "C", "D", "E" })); var map = appSettings.GetDictionary("DictionaryKey"); Assert.That(map, Has.Count.EqualTo(5)); Assert.That(map.Keys, Is.EqualTo(new List<string> { "A", "B", "C", "D", "E" })); Assert.That(map.Values, Is.EqualTo(new List<string> { "1", "2", "3", "4", "5" })); var value = appSettings.Get("ObjectKey", new SimpleAppSettings()); Assert.That(value, Is.Not.Null); Assert.That(value.FinalSetting, Is.EqualTo("Final")); Assert.That(value.SomeOtherSetting, Is.EqualTo(12)); Assert.That(value.SomeSetting, Is.EqualTo("Test")); }
public void Can_preload_AppSettings() { GetAppSettings(); var allSettings = settings.GetAll(); var cachedSettings = new DictionarySettings(allSettings); Assert.That(cachedSettings.Get("RealKey"), Is.EqualTo("This is a real value")); }
public void Can_preload_AppSettings() { GetAppSettings(); using (var db = settings.DbFactory.Open()) { var allSettings = db.Dictionary<string,string>( db.From<ConfigSetting>().Select(x => new { x.Id, x.Value})); var cachedSettings = new DictionarySettings(allSettings); Assert.That(cachedSettings.Get("RealKey"), Is.EqualTo("This is a real value")); } }
public void Does_parse_byte_array_as_Base64() { var authKey = AesUtils.CreateKey(); var appSettings = new DictionarySettings(new Dictionary<string, string> { { "AuthKey", Convert.ToBase64String(authKey) } }); Assert.That(appSettings.Get<byte[]>("AuthKey"), Is.EquivalentTo(authKey)); }