Template
chore: deploy initial code base
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Strata.DecisionSupport.Biz.Test.Integration.Configuration
|
||||
{
|
||||
public class AWSOptions
|
||||
{
|
||||
[Required(ErrorMessage = "Missing the Snowflake Admin Secret name")]
|
||||
public string SnowflakeAdminSecretName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using Snowflake.Data.Client;
|
||||
using Strata.DecisionSupport.Biz.Services;
|
||||
using Strata.DecisionSupport.Biz.Snowflake;
|
||||
using Strata.Schema.Client;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Strata.DecisionSupport.Biz.Test.Integration
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
[SetUpFixture]
|
||||
public class IntegrationTestBase
|
||||
{
|
||||
protected VerifySettings verifySettings;
|
||||
protected VerifySettings verifyErrorSettings;
|
||||
|
||||
protected readonly Guid GmAutomationDatabase = new("cda90beb-6c2e-41af-9083-857a09fe8183"); // GM Automation (Refreshed)
|
||||
protected Guid VariationOpportunityGuid { get; set; }
|
||||
protected Guid LOSOpportunityGuid { get; set; }
|
||||
protected ISnowflakeDatabaseContext _databaseContext;
|
||||
protected IEncounterQueryService _encounterQueryService;
|
||||
#pragma warning disable NUnit1032
|
||||
protected IServiceProvider _serviceProvider; //used to grab any necessary DI objects
|
||||
#pragma warning restore NUnit1032
|
||||
protected ILogger<IntegrationTestBase>? logger;
|
||||
|
||||
|
||||
//When running locally sets the profile to the data wrangler profile so you have access to resources
|
||||
[OneTimeSetUp]
|
||||
public async Task SetDatabaseContext()
|
||||
{
|
||||
#if DEBUG
|
||||
Environment.SetEnvironmentVariable("AWS_Profile", "sdt-continuous-improvement-service-role");
|
||||
#endif
|
||||
var services = ServiceCollectionFactory.Create();
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
var sfConnBuilderFactory = _serviceProvider.GetRequiredService<ISnowflakeDatabaseContextFactory>();
|
||||
_databaseContext = sfConnBuilderFactory.Create($"{GmAutomationDatabase:N}");
|
||||
verifySettings = TestExtensions.TestSettings();
|
||||
verifyErrorSettings = TestExtensions.TestSettings();
|
||||
verifyErrorSettings.UseDirectory("errorSnapshots");
|
||||
var schemaServiceClient = Mock.Of<ISchemaServiceClient>();
|
||||
_encounterQueryService = new EncounterQueryService(_databaseContext, schemaServiceClient);
|
||||
try
|
||||
{
|
||||
var query = @"select OpportunityGuid from cci.VariationOpportunity where CostDriver = 'Pharmacy' order by Savings DESC limit 1";
|
||||
var opportunityGuid = await _databaseContext.ExecuteScalarAsync<string>(query);
|
||||
VariationOpportunityGuid = new Guid(opportunityGuid ?? Guid.NewGuid().ToString());
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
try
|
||||
{
|
||||
var query = @"select OpportunityGuid from cci.VariationOpportunity where CostDriver = 'LOS' order by Savings DESC limit 1";
|
||||
var opportunityGuid = await _databaseContext.ExecuteScalarAsync<string>(query);
|
||||
LOSOpportunityGuid = new Guid(opportunityGuid ?? Guid.NewGuid().ToString());
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual async Task QueryTest<T, TI>(TI queryInfo)
|
||||
where TI : class
|
||||
where T : class
|
||||
{
|
||||
var query = Query(queryInfo);
|
||||
if (string.IsNullOrEmpty(query)) { return; }
|
||||
try
|
||||
{
|
||||
var result = await _databaseContext
|
||||
.QueryAsync<T>(query, nameof(QueryTest), CancellationToken.None);
|
||||
await Verifier.Verify(result, verifySettings)
|
||||
.UseFileName(TestContext.CurrentContext.TestName(nameof(result)));
|
||||
}
|
||||
catch (SnowflakeDbException dbex)
|
||||
{
|
||||
// ILB
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual string Query<T>(T queryInfo)
|
||||
where T : class
|
||||
=> "";
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
// _serviceProvider.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
using Snowflake.Data.Client;
|
||||
using Strata.DecisionSupport.Biz.Encounters;
|
||||
using Strata.DecisionSupport.Biz.Parameters;
|
||||
using Strata.DecisionSupport.Biz.Services;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Strata.DecisionSupport.Biz.Test.Integration.IntegrationTests
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
[TestFixture, Category("Integration"), Category("DSS")]
|
||||
public class TestEncounterChargeQuery : IntegrationTestBase
|
||||
{
|
||||
|
||||
[TestCaseSource(nameof(EncounterChargeQueryTestCases))]
|
||||
public async Task EncounterChargeQueryTest(EncounterChargeQueryInfo queryInfo)
|
||||
{
|
||||
var query = EncounterQueries.EncounterChargeQuery(queryInfo.First, queryInfo.Rows, queryInfo.Args());
|
||||
try
|
||||
{
|
||||
var result = ((IEnumerable<EncounterChargeInfo>)(await _databaseContext
|
||||
.QueryAsync<EncounterChargeInfo>(query, nameof(EncounterChargeQueryTest), queryInfo.Parameters())));
|
||||
await Verifier.Verify(query, verifySettings)
|
||||
.UseFileName(TestContext.CurrentContext.TestName(nameof(query)));
|
||||
await Verifier.Verify(result, verifySettings)
|
||||
.UseFileName(TestContext.CurrentContext.TestName(nameof(result)));
|
||||
}
|
||||
catch (SnowflakeDbException dbex)
|
||||
{
|
||||
// ILB
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(EncounterChargeQueryTestCases))]
|
||||
public async Task EncounterChargeQueryServiceTest(EncounterChargeQueryInfo queryInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _encounterQueryService.RunEncounterChargeQuery(queryInfo, CancellationToken.None);
|
||||
await Verifier.Verify(result, verifySettings)
|
||||
.UseFileName(TestContext.CurrentContext.TestName(nameof(result)));
|
||||
}
|
||||
catch (SnowflakeDbException dbex)
|
||||
{
|
||||
// ILB
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<TestCaseData> EncounterChargeQueryTestCases()
|
||||
{
|
||||
yield return new TestCaseData(new EncounterChargeQueryInfo(
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
Guid.NewGuid(),
|
||||
[1]))
|
||||
.SetName("{m}");
|
||||
yield return new TestCaseData(new EncounterChargeQueryInfo(
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
Guid.NewGuid(),
|
||||
[1]))
|
||||
.SetName("{m} hasManufacturer hasSupply usingCustomDimension");
|
||||
yield return new TestCaseData(new EncounterChargeQueryInfo(
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
Guid.NewGuid(),
|
||||
[1]))
|
||||
.SetName("{m} hasManufacturer Inferred hasSupply Inferred usingCustomDimension");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
using Snowflake.Data.Client;
|
||||
using Strata.DecisionSupport.Biz.Parameters;
|
||||
using Strata.DecisionSupport.Biz.Services;
|
||||
using Strata.DecisionSupport.Models.Encounters;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Strata.DecisionSupport.Biz.Test.Integration.IntegrationTests
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
[TestFixture, Category("Integration"), Category("DSS")]
|
||||
public class TestEncounterUnitOfServiceQuery : IntegrationTestBase
|
||||
{
|
||||
[TestCaseSource(nameof(TestCases))]
|
||||
public async Task QueryTest(EncounterUnitOfServiceQueryInfo queryInfo)
|
||||
=> await base.QueryTest<EncounterUnitOfService, EncounterUnitOfServiceQueryInfo>(queryInfo);
|
||||
|
||||
protected override string Query<EnounterUnitOfServiceQueryInfo>(EnounterUnitOfServiceQueryInfo queryInfo)
|
||||
=> (queryInfo is IWithArgs args)
|
||||
? EncounterQueries.EncounterUnitOfServiceQuery(args)
|
||||
: EncounterQueries.EncounterUnitOfServiceQuery();
|
||||
|
||||
[TestCaseSource(nameof(ServiceTestCases))]
|
||||
public async Task EncounterUnitOfServiceQueryServiceTest(EncounterUnitOfServiceQueryInfo queryInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _encounterQueryService.RunEncounterUnitOfServiceQuery(queryInfo, CancellationToken.None);
|
||||
await Verifier.Verify(result, verifySettings)
|
||||
.UseFileName(TestContext.CurrentContext.TestName(nameof(result)));
|
||||
}
|
||||
catch (SnowflakeDbException dbex)
|
||||
{
|
||||
// ILB
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<TestCaseData> ServiceTestCases()
|
||||
{
|
||||
yield return new TestCaseData(new EncounterUnitOfServiceQueryInfo(
|
||||
24,
|
||||
[1L, 2L]
|
||||
))
|
||||
.SetName("{m}");
|
||||
}
|
||||
|
||||
public static IEnumerable<TestCaseData> TestCases()
|
||||
{
|
||||
yield return new TestCaseData(new EncounterUnitOfServiceQueryInfo(
|
||||
24,
|
||||
[1L, 2L]
|
||||
))
|
||||
.SetName("{c} {m}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using Snowflake.Data.Client;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Strata.DecisionSupport.Biz.Test.Integration.IntegrationTests
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
[TestFixture, Category("Integration"), Category("DSS")]
|
||||
public class TestException : IntegrationTestBase
|
||||
{
|
||||
|
||||
[Test]
|
||||
public async Task ExceptionTest()
|
||||
{
|
||||
var query = "select ISNULL(null, 0) id\r\n";
|
||||
try
|
||||
{
|
||||
var result = await _databaseContext.QueryAsync<TestClass>(query, nameof(ExceptionTest));
|
||||
}
|
||||
catch (SnowflakeDbException dbex)
|
||||
{
|
||||
await Verifier.Verify(dbex.Message, verifySettings)
|
||||
.UseFileName(TestContext.CurrentContext.TestName());
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public class TestClass
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
using Snowflake.Data.Client;
|
||||
using Strata.DecisionSupport.Biz.Encounters;
|
||||
using Strata.DecisionSupport.Biz.Parameters;
|
||||
using Strata.DecisionSupport.Biz.Services;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Strata.DecisionSupport.Biz.Test.Integration.IntegrationTests
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
[TestFixture, Category("Integration"), Category("DSS")]
|
||||
|
||||
public class TestLOSOpportunityInfoQuery : IntegrationTestBase
|
||||
{
|
||||
[TestCaseSource(nameof(LOSOpportunityInfoQueryTestCases))]
|
||||
public async Task LOSOpportunityInfoQueryTest(LOSOpportunityQueryInfo queryInfo)
|
||||
{
|
||||
var query = EncounterQueries.LOSOpportunityInfoQuery(LOSOpportunityQueryInfo.Args());
|
||||
try
|
||||
{
|
||||
var result = ((IEnumerable<LOSOpportunityInfo>)await _databaseContext
|
||||
.QueryAsync<LOSOpportunityInfo>(query, nameof(LOSOpportunityInfoQueryTest), queryInfo.Parameters()));
|
||||
await Verifier.Verify(query, verifySettings)
|
||||
.UseFileName(TestContext.CurrentContext.TestName(nameof(query)));
|
||||
await Verifier.Verify(result, verifySettings)
|
||||
.UseFileName(TestContext.CurrentContext.TestName(nameof(result)));
|
||||
}
|
||||
catch (SnowflakeDbException dbex)
|
||||
{
|
||||
// ILB
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(LOSOpportunityInfoQueryTestCases))]
|
||||
public async Task LOSOpportunityInfoQueryServiceTest(LOSOpportunityQueryInfo queryInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _encounterQueryService.RunLOSOpportunityInfoQuery(queryInfo, CancellationToken.None);
|
||||
await Verifier.Verify(result, verifySettings)
|
||||
.UseFileName(TestContext.CurrentContext.TestName(nameof(result)));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<TestCaseData> LOSOpportunityInfoQueryTestCases()
|
||||
{
|
||||
yield return new TestCaseData(new LOSOpportunityQueryInfo(
|
||||
Guid.NewGuid(),
|
||||
24,
|
||||
2))
|
||||
.SetName("{m}");
|
||||
}
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
using Snowflake.Data.Client;
|
||||
using Strata.DecisionSupport.Biz.Parameters;
|
||||
using Strata.DecisionSupport.Biz.Test.Unit;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Strata.DecisionSupport.Biz.Test.Integration.IntegrationTests
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
[TestFixture, Category("Integration"), Category("DSS")]
|
||||
public class TestSnowflakeQueries : IntegrationTestBase
|
||||
{
|
||||
[TestCaseSource(typeof(SnowflakeTestCases), nameof(SnowflakeTestCases.TestCases))]
|
||||
public async Task VerifyQuery<TI, T>(TI obj, T queryInfo, Func<IEnumerable<TI>, IEnumerable<TI>> orderby) where TI : class where T : class
|
||||
{
|
||||
var query = Query(queryInfo);
|
||||
var lineReader = query.LineReader();
|
||||
await Verifier.Verify(lineReader, verifySettings)
|
||||
.UseDirectory("snapshotQueries")
|
||||
.UseFileName(TestContext.CurrentContext.TestName());
|
||||
var parameters = queryInfo is IWithParameters hasParameters ? hasParameters.Parameters() : null;
|
||||
if (string.IsNullOrEmpty(query)) { return; }
|
||||
try
|
||||
{
|
||||
IEnumerable<TI> result;
|
||||
result = parameters != null
|
||||
? await _databaseContext.QueryAsync<TI>(query, typeof(T).Name, parameters)
|
||||
: await _databaseContext.QueryAsync<TI>(query, typeof(T).Name);
|
||||
if (orderby != null)
|
||||
{
|
||||
result = orderby(result);
|
||||
}
|
||||
await Verify(result, verifySettings)
|
||||
.UseDirectory("snapshotResults")
|
||||
.UseFileName(TestContext.CurrentContext.TestName());
|
||||
}
|
||||
catch (SnowflakeDbException dbex)
|
||||
{
|
||||
var result = dbex.Message + Environment.NewLine + "".PadLeft(40, '-') + Environment.NewLine + lineReader;
|
||||
await Verifier.Verify(query, verifySettings)
|
||||
.UseDirectory("errorQueries")
|
||||
.UseFileName(TestContext.CurrentContext.TestName());
|
||||
await Verifier.Verify(result, verifyErrorSettings)
|
||||
.UseFileName(TestContext.CurrentContext.TestName());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
protected override string Query<T>(T queryInfo) where T : class
|
||||
=> SnowflakeTestCases.Query(queryInfo);
|
||||
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
using Dapper;
|
||||
using Snowflake.Data.Client;
|
||||
using Strata.DecisionSupport.Biz.Encounters;
|
||||
using Strata.DecisionSupport.Biz.Parameters;
|
||||
using Strata.DecisionSupport.Biz.Services;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Strata.DecisionSupport.Biz.Test.Integration.IntegrationTests
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
[TestFixture, Category("Integration"), Category("DSS")]
|
||||
public class TestVariationEncounterChargeQuery : IntegrationTestBase
|
||||
{
|
||||
[TestCaseSource(nameof(VariationEncounterChargeQueryTestCases))]
|
||||
public async Task VariationEncounterChargeQueryTest(VariationEncounterChargeQueryInfo queryInfo)
|
||||
{
|
||||
|
||||
var query = EncounterQueries.VariationEncounterChargeQuery(queryInfo.First, queryInfo.Rows, queryInfo.Args());
|
||||
|
||||
try
|
||||
{
|
||||
var result = ((IEnumerable<VariationEncounterChargeInfo>)(await _databaseContext
|
||||
.QueryAsync<VariationEncounterChargeInfo>(query, nameof(VariationEncounterChargeQueryTest), queryInfo.Parameters())));
|
||||
await Verifier.Verify(query, verifySettings)
|
||||
.UseFileName(TestContext.CurrentContext.TestName(nameof(query)));
|
||||
await Verifier.Verify(result, verifySettings)
|
||||
.UseFileName(TestContext.CurrentContext.TestName(nameof(result)));
|
||||
}
|
||||
catch (SnowflakeDbException dbex)
|
||||
{
|
||||
// ILB
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(VariationEncounterChargeQueryTestCases))]
|
||||
public async Task VariationEncounterChargeInfoServiceTest(VariationEncounterChargeQueryInfo queryInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _encounterQueryService.RunVariationEncounterChargeQuery(queryInfo, CancellationToken.None);
|
||||
await Verifier.Verify(result, verifySettings)
|
||||
.UseFileName(TestContext.CurrentContext.TestName(nameof(result)));
|
||||
}
|
||||
catch (SnowflakeDbException dbex)
|
||||
{
|
||||
// ILB
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<TestCaseData> VariationEncounterChargeQueryTestCases()
|
||||
{
|
||||
yield return new TestCaseData(new VariationEncounterChargeQueryInfo(false, false, false, false, false, true,
|
||||
new Guid[] { Guid.NewGuid() },
|
||||
new int[] { 1, 2 }, 1, 1000))
|
||||
.SetName("{m}");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Strata.ApiLib.Core.Cors.Extensions;
|
||||
using Strata.ApiLib.Core.StrataAuthentication.Bootstrappers;
|
||||
using Strata.Configuration.Client.DependencyInjection.ConsoleApps;
|
||||
using Strata.ContinuousImprovement.Biz.Configurations;
|
||||
using Strata.DecisionSupport.Biz.Configurations;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Strata.DecisionSupport.Biz.Test.Integration
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public static class ServiceCollectionFactory
|
||||
{
|
||||
public static IServiceCollection Create()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
try
|
||||
{
|
||||
var configuration = StrataConfigurationFactory.GetConfiguration();
|
||||
services.AddSingleton(configuration);
|
||||
services.AddStrataAuthentication(configuration);
|
||||
services.AddStrataCors(configuration);
|
||||
services.AddContinuousImprovementServices(configuration);
|
||||
services.AddDecisionSupportServices(configuration);
|
||||
services.AddLogging();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
using Amazon.SecretsManager.Extensions.Caching;
|
||||
using Amazon.SecretsManager.Model;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Strata.SnowflakeLib;
|
||||
using Strata.SnowflakeLib.Configuration;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.ExceptionServices;
|
||||
|
||||
namespace Strata.DecisionSupport.Biz.Test.Integration
|
||||
{
|
||||
public class SnowflakeTestConnectionStringBuilderFactory : ISnowflakeConnectionStringBuilderFactory
|
||||
{
|
||||
private readonly SecretsManagerCache _secretsManagerCache;
|
||||
private readonly SnowflakeOptions _snowflakeOptions;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor that uses configuration values to generate the factory
|
||||
/// </summary>
|
||||
/// <param name="logger">logger to allow output of message to our centralized logging system</param>
|
||||
/// <param name="secretsManagerCache">aws secrets manager cache injected during DI for faster lookup</param>
|
||||
/// <param name="snowflakeOptions">The options class that holds configuration, forcing the consumer of the nuget to have certain settings</param>
|
||||
/// <param name="claimsPrincipalAccessor">Claims accessor object to expose an interface to pull the identity and database information</param>
|
||||
public SnowflakeTestConnectionStringBuilderFactory(
|
||||
[NotNull] SecretsManagerCache secretsManagerCache,
|
||||
//[NotNull]
|
||||
IOptions<SnowflakeOptions> snowflakeOptions)
|
||||
{
|
||||
try
|
||||
{
|
||||
_secretsManagerCache = secretsManagerCache ?? throw new ArgumentNullException(nameof(secretsManagerCache));
|
||||
_snowflakeOptions = snowflakeOptions?.Value ?? throw new ArgumentNullException(nameof(snowflakeOptions));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method to get a snowflake connection string through secrets manager.
|
||||
/// </summary>
|
||||
/// <param name="secretName">The aws secret name to lookup the snowflake connection string</param>
|
||||
/// <returns>The connection string builder for the connection string stored at the awws secret name</returns>
|
||||
public async Task<SnowflakeConnectionStringBuilder> CreateAsync(string secretName)
|
||||
{
|
||||
return await CreateAsync(secretName, Guid.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method to get a snowflake connection string through secrets manager.
|
||||
/// </summary>
|
||||
/// <param name="secretName">The aws secret name to lookup the snowflake connection string</param>
|
||||
/// <param name="databaseGuid">The database guid used to make the connection</param>
|
||||
/// <returns>The connection string builder for the connection string stored at the awws secret name</returns>
|
||||
public async Task<SnowflakeConnectionStringBuilder> CreateAsync(string secretName, Guid databaseGuid)
|
||||
{
|
||||
SnowflakeConnectionStringBuilder builder = null;
|
||||
|
||||
try
|
||||
{
|
||||
var snowflakeConnectionString = await _secretsManagerCache.GetSecretString(secretName);
|
||||
|
||||
builder = new SnowflakeConnectionStringBuilder(snowflakeConnectionString)
|
||||
{
|
||||
|
||||
URL = _snowflakeOptions.Url,
|
||||
Account = _snowflakeOptions.Account,
|
||||
// IgnoreCase = true,
|
||||
// QueryPassthrough = true,
|
||||
Timeout = (int)TimeSpan.FromHours(10).TotalSeconds,
|
||||
// Other = "RetryStatusCodes=500"
|
||||
DatabaseGuid = databaseGuid
|
||||
};
|
||||
}
|
||||
catch (ResourceNotFoundException e)
|
||||
{
|
||||
ExceptionDispatchInfo.Capture(e).Throw();
|
||||
}
|
||||
catch (InvalidRequestException e)
|
||||
{
|
||||
ExceptionDispatchInfo.Capture(e).Throw();
|
||||
}
|
||||
catch (InvalidParameterException e)
|
||||
{
|
||||
ExceptionDispatchInfo.Capture(e).Throw();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExceptionDispatchInfo.Capture(e).Throw();
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="SnowflakeTestConnectionStringBuilderFactory.cs" />
|
||||
<Compile Remove="StrataSnowflakeConnectionExtensions.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.400.36" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="Moq" Version="4.20.72" />
|
||||
<PackageReference Include="NUnit" Version="4.3.2" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
|
||||
<PackageReference Include="Strata.ApiLib.Core" Version="8.4.1" />
|
||||
<PackageReference Include="Strata.Configuration.Client" Version="9.15.1" />
|
||||
<PackageReference Include="Strata.SnowflakeLib" Version="4.3.0" />
|
||||
<PackageReference Include="Verify.NUnit" Version="29.3.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Strata.DecisionSupport.Biz\Strata.DecisionSupport.Biz.csproj" />
|
||||
<ProjectReference Include="..\Strata.DecisionSupport.Biz.Test.Unit\Strata.DecisionSupport.Biz.Test.Unit.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="NUnit.Framework" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="IntegrationTests\snapshotResults\" />
|
||||
<Folder Include="IntegrationTests\snapshotQueries\" />
|
||||
<Folder Include="IntegrationTests\snapshots\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,48 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Strata.DecisionSupport.Biz.Test.Integration
|
||||
{
|
||||
[ExcludeFromCodeCoverage]
|
||||
public static class TestExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// The test name
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns>
|
||||
/// The name of the test split by camel case for a max length of 200 characters.
|
||||
/// </returns>
|
||||
public static string TestName(this TestContext context, string suffix = "")
|
||||
{
|
||||
var testName = suffix == string.Empty
|
||||
? $"{context.Test.Name}".SplitCamelCase()
|
||||
: $"{context.Test.Name} - {suffix}".SplitCamelCase();
|
||||
testName = testName[..Math.Min(200, testName.Length)];
|
||||
return testName;
|
||||
}
|
||||
|
||||
public static string SplitCamelCase(this string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input)) { return input; }
|
||||
|
||||
const string pattern = "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-r + t-z])|[A-Z](?=[A-Z][s][a-z]))";
|
||||
|
||||
if (input.StartsWith("FY", StringComparison.Ordinal))
|
||||
{ // hack for FY2012, etc
|
||||
return "FY " + Regex.Replace(input.Remove(0, 2), pattern, "$1 ");
|
||||
}
|
||||
input = Regex.Replace(input, @"\{|\}|:|,|\)|\(", "", RegexOptions.Singleline | RegexOptions.IgnoreCase);
|
||||
return Regex.Replace(input, pattern, "$1 ");
|
||||
}
|
||||
|
||||
public static VerifySettings TestSettings()
|
||||
{
|
||||
var settings = new VerifySettings();
|
||||
settings.UseDirectory("snapshots");
|
||||
settings.ScrubInlineGuids();
|
||||
return settings;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"AllowedHosts": "*",
|
||||
"Version": "0.0.0",
|
||||
"configuration": {
|
||||
"basicAuthUsername": "BkQsRDdmdjkFNhKVuTI.TpujQJXuKhGDcV.F_hjADMRTaEUWMJnviaesoOrhhfnz",
|
||||
"basicAuthPassword": "GWPIIWECDqh.hjDNdpxVEfeFe-bYFwPSx-oBGFD_od_SUQVk-QqTIkZY_NXMeqeo"
|
||||
},
|
||||
"endpoints": {
|
||||
"dataschema": "https://dataschema-api.dev.stratanetwork.net/",
|
||||
"schema": "https://schema-api.dev.stratanetwork.net",
|
||||
"analytics": "https://analytics-api.dev.stratanetwork.net"
|
||||
},
|
||||
"StrataConfigServerBaseUrl": "https://configuration.dev.stratanetwork.net",
|
||||
"NetworkOpportunity": {
|
||||
"Creators": [ "" ]
|
||||
},
|
||||
"HealthCheck": {
|
||||
"StrataJazz": true,
|
||||
"Snowflake": true
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"System": "Information",
|
||||
"Microsoft": "Information"
|
||||
}
|
||||
},
|
||||
"hangfire": {
|
||||
"url": "https://localhost:44369",
|
||||
"redis": {
|
||||
"prefix": "continuousimprovement-jobs-service",
|
||||
"configOptions": "ddenredisc01.sdt.local:6379,ddenredisc02.sdt.local:6379,ddenredisc03.sdt.local:6379,ddenredisc04.sdt.local:6379,ddenredisc05.sdt.local:6379,ddenredisc06.sdt.local:6379"
|
||||
}
|
||||
},
|
||||
"accessGudid": {
|
||||
"url": "https://accessgudid.nlm.nih.gov/download/delimited"
|
||||
},
|
||||
"datadog": {
|
||||
"seedgmdnjob": "https://app.datadoghq.com/logs/livetail?query=service%3ASeedGMDNTermDataJob%20env%3Adev&cols=status%2Cenv%2C%40db.strata_id%2C%40db.org_pin%2C%40db.name%2C%40db.instance%2C%40process.name%2Cservice&index=%2A&messageDisplay=inline&stream_sort=desc&viz=stream&from_ts=1692207497147&to_ts=1692293897147&live=true"
|
||||
},
|
||||
"aws": {
|
||||
"snowflakeAdminSecretName": "stratareplication/snowflake/automation/connectionstring"
|
||||
},
|
||||
"strataApi": {
|
||||
"clientSecret": "V_okTrkWYBs-PqMP.inbJShIvMGWcpdqCDq_ZjntVF.ydgRCoYaDVJYEWEIdsjJ_"
|
||||
},
|
||||
"ChargeCodeOpportunityValidation": {
|
||||
"maxChargeCodeSelections": 100,
|
||||
"maxOpportunityLevelSelections": 10
|
||||
},
|
||||
"Snowflake": {
|
||||
"Url": "https://stratadev.us-east-1.privatelink.snowflakecomputing.com",
|
||||
"Account": "stratadev"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user