public void Config_InvalidUrl(string testCase, bool optional) { // Create path to appsettings file string jsonPath = $"TestCases\\ApiSource\\Anon-Win\\ConfigParam\\InvalidUrl\\input{testCase}.json"; // Get initial config containing api connection and authentication info var initConfig = new ConfigurationBuilder().AddJsonFile(jsonPath, false).Build(); // Create the final builder IConfigurationBuilder builder = new ConfigurationBuilder(); IConfiguration actualConfig; if (optional) { var listExpected = JsonConvert.DeserializeObject <List <ConfigSetting> >(File.ReadAllText($"TestCases\\ApiSource\\Anon-Win\\ConfigParam\\InvalidUrl\\expected{testCase}.json")); builder.AddApiSource(initConfig, optional); actualConfig = builder.Build(); var listActual = actualConfig.GetConfigSettings(); Assert.True(TestHelper.SettingsAreEqual(listActual, listExpected)); } else { Assert.Throws <System.UriFormatException>(() => builder.AddApiSource(initConfig, optional)); } }
public void Config_SectionNotFound(string testCase, bool optional) { // Create path to appsettings file string jsonPath = $"TestCases\\ApiSource\\Cert-ApiKey\\ConfigParam\\SectionNotFound\\input{testCase}.json"; // Get initial config containing non-default database settings var initConfig = new ConfigurationBuilder().AddJsonFile(jsonPath, false).Build(); // Create the final builder IConfigurationBuilder builder = new ConfigurationBuilder(); if (optional) { var listExpected = JsonConvert.DeserializeObject <List <ConfigSetting> >(File.ReadAllText($"testCases\\ApiSource\\Cert-ApiKey\\ConfigParam\\SectionNotFound\\expected{testCase}.json")); builder.AddApiSource(initConfig, optional); IConfiguration actualConfig; actualConfig = builder.Build(); var listActual = actualConfig.GetConfigSettings(); Assert.True(TestHelper.SettingsAreEqual(listActual, listExpected)); } else { Assert.Throws <System.Exception>(() => builder.AddApiSource(initConfig, optional)); } }
public void Config_Good(string testCase, bool optional) { // Create path to appsettings file string jsonPath = $"TestCases\\ApiSource\\Anon-Win\\ConfigParam\\Good\\input{testCase}.json"; // Get initial config containing non-default database settings var initConfigBuilder = new ConfigurationBuilder(); initConfigBuilder.SetBasePath(Directory.GetCurrentDirectory()); initConfigBuilder.AddJsonFile(jsonPath, false); var initConfig = initConfigBuilder.Build(); // Create the final builder IConfigurationBuilder finalBuilder = new ConfigurationBuilder(); // Add the API source to the final builder finalBuilder.AddApiSource(initConfig, optional); // Build the final config var actual = finalBuilder.Build(); // Convert to lists and compare var listActual = actual.GetConfigSettings(); var listExpected = JsonConvert.DeserializeObject <List <ConfigSetting> >(File.ReadAllText($"TestCases\\ApiSource\\Anon-Win\\expected{testCase}.json")); Assert.True(TestHelper.SettingsAreEqual(listActual, listExpected)); }
public void RouteParams_WinDefOptional_Good(string configUrlVar, bool optional, string testCase) { var builder = new ConfigurationBuilder(); IConfiguration actual = builder.AddApiSource(configUrlVar, optional).Build(); var listActual = actual.GetConfigSettings(); var listExpected = JsonConvert.DeserializeObject <List <ConfigSetting> >(File.ReadAllText($"TestCases\\ApiSource\\expected{testCase}.json")); Assert.True(TestHelper.SettingsAreEqual(listActual, listExpected)); }
public void RouteParams_NullEnvVar(string configUrlVar, string authType, string authSecretVar, string[] routeParams, bool optional, string testCase) { var builder = new ConfigurationBuilder(); if (optional) { var listExpected = JsonConvert.DeserializeObject <List <ConfigSetting> >(File.ReadAllText($"testCases\\ApiSource\\Anon-Win\\OptParams\\NullUrlVarParam\\expected{testCase}.json")); builder.AddApiSource(configUrlVar, authType, authSecretVar, routeParams, optional); IConfiguration config; config = builder.Build(); var listActual = config.GetConfigSettings(); Assert.True(TestHelper.SettingsAreEqual(listActual, listExpected)); } else { Assert.Throws <System.Exception>(() => builder.AddApiSource(configUrlVar, null, authType, routeParams, optional)); } }
public void RouteParams_CertNoSecret(string configUrlVar, string authType, string authSecretVar, string[] routeParams, bool optional, string testCase) { IConfiguration actual; var builder = new ConfigurationBuilder(); if (optional) { builder.AddApiSource(configUrlVar, authType, authSecretVar, routeParams, optional); var listExpected = JsonConvert.DeserializeObject <List <ConfigSetting> >(File.ReadAllText($"TestCases\\ApiSource\\Cert-ApiKey\\OptParams\\CertNoSecret\\expected{testCase}.json")); actual = builder.Build(); var listActual = actual.GetConfigSettings(); Assert.True(TestHelper.SettingsAreEqual(listActual, listExpected)); } else { Assert.Throws <System.Exception>(() => builder.AddApiSource(configUrlVar, authType, authSecretVar, routeParams, optional)); } }
public void RouteParams_AppIdOptional_Good(string configUrlVar, string authType, string authSecretVar, string[] routeParams, bool optional, string testCase) { var builder = new ConfigurationBuilder(); IConfiguration actual = builder.AddApiSource(configUrlVar, authType, authSecretVar, routeParams, optional).Build(); var listActual = actual.GetConfigSettings(); var listExpected = JsonConvert.DeserializeObject <List <ConfigSetting> >(File.ReadAllText($"TestCases\\ApiSource\\Cert-ApiKey\\OptParams\\Good\\expected{authType}{testCase}.json")); Assert.True(TestHelper.SettingsAreEqual(listActual, listExpected)); }
public void JwtBearer_BadClient(string configUrlVar, string authority, string clientId, string clientSecret, string scope, string testCase, bool optional) { IConfiguration actual; // Create the builder IConfigurationBuilder builder = new ConfigurationBuilder(); if (optional) { builder.AddApiSource(configUrlVar, authority, clientId, clientSecret, scope, optional); actual = builder.Build(); var listExpected = JsonConvert.DeserializeObject <List <ConfigSetting> >(File.ReadAllText($"TestCases\\ApiSource\\JwtBearer\\OptParams\\BadClient\\expected{testCase}.json")); var listActual = actual.GetConfigSettings(); Assert.True(TestHelper.SettingsAreEqual(listActual, listExpected)); } else { Assert.Throws <System.Exception>(() => builder.AddApiSource(configUrlVar, authority, clientId, clientSecret, scope, optional)); } }
public void QueryParams_InvalidParams(string configUrlVar, string authType, string param1Name, string param1Value, string param2Name, string param2Value, string testCase, bool optional) { IConfiguration actual; var builder = new ConfigurationBuilder(); Dictionary <string, string> dictParams = new Dictionary <string, string>(); dictParams.Add(param1Name, null); dictParams.Add(param2Name, ""); if (optional) { var listExpected = JsonConvert.DeserializeObject <List <ConfigSetting> >(File.ReadAllText($"testCases\\ApiSource\\Anon-Win\\QueryParams\\InvalidUrl\\expected{testCase}.json")); // builder.AddApiSource(configUrlVar, authType, null, dictParams, optional); builder.AddApiSource(configUrlVar, authType, null, dictParams, optional); actual = builder.Build(); var listActual = actual.GetConfigSettings(); Assert.True(TestHelper.SettingsAreEqual(listActual, listExpected)); } else { Assert.Throws <System.ArgumentNullException>(() => builder.AddApiSource(configUrlVar, authType, null, dictParams, optional)); } }
//TODO: ADD WIN TEST CASES public void QueryParams_Good(string configUrlVar, string authType, string param1Name, string param1Value, string param2Name, string param2Value, string testCase, bool optional) { var builder = new ConfigurationBuilder(); Dictionary <string, string> dictParams = new Dictionary <string, string>(); dictParams.Add(param1Name, param1Value); dictParams.Add(param2Name, param2Value); IConfiguration actual = builder.AddApiSource(configUrlVar, authType, null, dictParams, optional).Build(); var listActual = actual.GetConfigSettings(); var listExpected = JsonConvert.DeserializeObject <List <ConfigSetting> >(File.ReadAllText($"TestCases\\ApiSource\\Anon-Win\\QueryParams\\Good\\expected{testCase}.json")); Assert.True(TestHelper.SettingsAreEqual(listActual, listExpected)); }
public void JwtBearer_QParam_Good(string configUrlVar, string authorityVar, string clientIdVar, string clientSecretVar, string clientScopeVar, string param1Name, string param1Value, string param2Name, string param2Value, string testCase) { var builder = new ConfigurationBuilder(); Dictionary <string, string> dictParams = new Dictionary <string, string>(); dictParams.Add(param1Name, param1Value); dictParams.Add(param2Name, param2Value); IConfiguration actual = builder.AddApiSource(configUrlVar, authorityVar, clientIdVar, clientSecretVar, clientScopeVar, dictParams).Build(); var listActual = actual.GetConfigSettings(); var listExpected = JsonConvert.DeserializeObject <List <ConfigSetting> >(File.ReadAllText($"TestCases\\ApiSource\\JwtBearer\\QueryParams\\Good\\expected{testCase}.json")); Assert.True(TestHelper.SettingsAreEqual(listActual, listExpected)); }
public void JwtBearer_RParam_Good(string configUrlVar, string authorityVar, string clientIdVar, string clientSecretVar, string clientScopeVar, string appId, string testCase) { // Create the builder IConfigurationBuilder builder = new ConfigurationBuilder(); // Add the DBSource to the final builder builder.AddApiSource(configUrlVar, authorityVar, clientIdVar, clientSecretVar, clientScopeVar, new string[] { appId }); // Build the final config var actual = builder.Build(); // Convert to lists and compare var listActual = actual.GetConfigSettings(); var listExpected = JsonConvert.DeserializeObject <List <ConfigSetting> >(File.ReadAllText($"TestCases\\ApiSource\\JwtBearer\\OptParams\\Good\\expected{testCase}.json")); Assert.True(TestHelper.SettingsAreEqual(listActual, listExpected)); }
public void RouteParams_WrongUrl(string configUrlVar, string authType, string authSecretVar, string[] routeParams, bool optional, string testCase) //FAIL ON BUILD { IConfiguration actual; var builder = new ConfigurationBuilder(); builder.AddApiSource(configUrlVar, authType, authSecretVar, routeParams, optional); if (optional) { var listExpected = JsonConvert.DeserializeObject <List <ConfigSetting> >(File.ReadAllText($"testCases\\ApiSource\\Anon-Win\\OptParams\\WrongUrl\\expected{testCase}.json")); actual = builder.Build(); var listActual = actual.GetConfigSettings(); Assert.True(TestHelper.SettingsAreEqual(listActual, listExpected)); } else { Assert.Throws <System.Net.Http.HttpRequestException>(() => actual = builder.Build()); } }