public async Task AzureFileTestAsync() { var connectionString = ConfigurationManager.AppSettings["settings:sink:AzureFile:ConnectionString"]; var settingsConfig = new SettingsConfiguration().WriteTo.AzureFileStorage(connectionString) .ReadFrom.AzureFileStorage(connectionString); settingsConfig.OnSettingsSaving += (sender, args) => { args.Should().NotBeNull(); args.Data.Should().NotBeNull(); }; settingsConfig.OnSettingsLoading += (sender, args) => { args.Should().NotBeNull(); args.Data.Should().NotBeNull(); }; var settingsMgr = settingsConfig.CreateSettingsMgr <ISettingsObjectMgrAsync>(); settingsMgr.Should().NotBeNull(); settingsMgr.Should().BeAssignableTo <ISettingsObjectMgrAsync>(); var settings = new CustomSettings(); await settingsMgr.WriteSettingsAsync(settings); settings.String1 = "Test1"; var settingsNew = await settingsMgr.ReadSettingsAsync <CustomSettings>(); settings.String1.Should().NotBe(settingsNew.String1); }
public void OverrideTest() { var defaultSettings = new CustomSettings(); var settingsConfig = new SettingsConfiguration().WriteTo.Memory(defaultSettings) .ReadFrom.Memory(defaultSettings) .ReaderOverrides.WithAction <CustomSettings>( (s) => { s.String1 = "Override1"; return(s); }) .WriterOverrides.WithAction <CustomSettings>( (s) => { return(s); }); var settingsMgr = settingsConfig.CreateSettingsMgr <ISettingsObjectMgr>(); var settings = settingsMgr.ReadSettings <CustomSettings>(); settings.String1.Should().Be("Override1"); }
public void AzureDocumentDbTest() { var endPointUri = new Uri(ConfigurationManager.AppSettings["settings:sink:AzureDocumentDb:EndPoint"]); var authKey = ConfigurationManager.AppSettings["settings:sink:AzureDocumentDb:AuthorizationKey"]; var settingsConfig = new SettingsConfiguration().WriteTo.AzureDocumentDb(endPointUri, authKey).ReadFrom.AzureDocumentDb(endPointUri, authKey); settingsConfig.OnSettingsSaving += (sender, args) => { args.Should().NotBeNull(); args.Data.Should().NotBeNull(); }; settingsConfig.OnSettingsLoading += (sender, args) => { args.Should().NotBeNull(); args.Data.Should().NotBeNull(); }; var settingsMgr = settingsConfig.CreateSettingsMgr <ISettingsObjectMgr>(); settingsMgr.Should().NotBeNull(); settingsMgr.Should().BeAssignableTo <ISettingsObjectMgr>(); var settings = new CustomSettings(); settingsMgr.WriteSettings(settings); settings.String1 = "Test1"; var settingsNew = settingsMgr.ReadSettings <CustomSettings>(); settings.String1.Should().NotBe(settingsNew.String1); }
public void Initialize() { var defaultSettings = new CustomSettings(); var settingsConfig = new SettingsConfiguration().WriteTo.Memory(defaultSettings) .ReadFrom.Memory(defaultSettings) .ReaderOverrides.WithAction <CustomSettings>( (s) => { s.String1 = "Override1"; return(s); }) .WriterOverrides.WithAction <CustomSettings>( (s) => { return(s); }); var settingsMgr = settingsConfig.CreateSettingsMgr <ISettingsObjectMgr>(); SettingsManager.SetSettingsManager(settingsMgr); }
public void JsonNetTest() { var f = System.IO.Path.Combine(TestContext.CurrentContext.WorkDirectory, "customSettings.json"); var settingsConfig = new SettingsConfiguration().WriteTo.JsonNet(f).ReadFrom.JsonNet(f); settingsConfig.OnSettingsSaving += (sender, args) => { args.Should().NotBeNull(); args.Data.Should().NotBeNull(); }; settingsConfig.OnSettingsLoading += (sender, args) => { args.Should().NotBeNull(); args.Data.Should().NotBeNull(); }; var settingsMgr = settingsConfig.CreateSettingsMgr <ISettingsObjectMgr>(); settingsMgr.Should().NotBeNull(); settingsMgr.Should().BeAssignableTo <ISettingsObjectMgr>(); var settings = new CustomSettings(); settingsMgr.WriteSettings(settings); settings.String1 = "Test1"; var settingsNew = settingsMgr.ReadSettings <CustomSettings>(); settingsNew.Should().NotBeNull(); settingsNew.Should().BeOfType <CustomSettings>(); settings.String1.Should().NotBe(settingsNew.String1); settings.Should().BeOfType <CustomSettings>(); }
public async Task AzureDocumentDbMaxVersionsTest() { var endPointUri = new Uri(ConfigurationManager.AppSettings["settings:sink:AzureDocumentDb:EndPoint"]); var authKey = ConfigurationManager.AppSettings["settings:sink:AzureDocumentDb:AuthorizationKey"]; var databaseName = "AppSettings"; var collectionName = "Config"; int maxVersions = 3; var settingsConfig = new SettingsConfiguration().WriteTo .AzureDocumentDb(endPointUri, authKey, maxVersions: maxVersions, databaseName: databaseName, collectionName: collectionName) .ReadFrom.AzureDocumentDb(endPointUri, authKey); settingsConfig.OnSettingsSaving += (sender, args) => { args.Should().NotBeNull(); args.Data.Should().NotBeNull(); }; settingsConfig.OnSettingsLoading += (sender, args) => { args.Should().NotBeNull(); args.Data.Should().NotBeNull(); }; var settingsMgr = settingsConfig.CreateSettingsMgr <ISettingsObjectMgr>(); settingsMgr.Should().NotBeNull(); settingsMgr.Should().BeAssignableTo <ISettingsObjectMgr>(); var settings = new CustomSettings(); for (int i = 0; i <= maxVersions; i++) { settings.Int1 = i; settingsMgr.WriteSettings(settings); } var client = new DocumentClient(endPointUri, authKey); await client.OpenAsync(); var database = client .CreateDatabaseQuery() .Where(x => x.Id == databaseName) .AsEnumerable() .FirstOrDefault(); var collection = client.CreateDocumentCollectionQuery(database.SelfLink) .Where(x => x.Id == collectionName) .AsEnumerable() .FirstOrDefault(); var documents = client.CreateDocumentQuery(collection.SelfLink) .OrderByDescending(x => x.Timestamp) .Select(x => x) .ToList(); documents.Count.Should().BeLessOrEqualTo(maxVersions); }