chore: deploy initial code base

This commit is contained in:
Thom Lamb
2026-05-12 10:34:30 -05:00
parent cce2961782
commit a81300a571
1829 changed files with 248331 additions and 1 deletions
@@ -0,0 +1,38 @@
using Strata.ContinuousImprovement.Biz.DbContexts;
using Strata.ContinuousImprovement.Client.Test.Integration.Setup;
using Strata.ContinuousImprovement.Client.Test.Integration.Tests;
using System.Diagnostics.CodeAnalysis;
[ExcludeFromCodeCoverage]
[SetUpFixture]
public class ClientIntegrationTestFixture
{
[OneTimeSetUp]
public virtual async Task SetDbContextAndServices()
{
#if DEBUG
//When running locally sets the profile to the CI profile so you have access to resources
Environment.SetEnvironmentVariable("AWS_Profile", "sdt-continuous-improvement-service-role");
#endif
var clientService = new ClientServiceBase();
await clientService.ClientValidation();
var services = ServiceCollectionFactory.Create();
await services.SetupServiceProperties(clientService.StrataId);
}
[OneTimeTearDown]
public async Task TearDown()
{
try
{
var centralDbContext = ServiceProperties.CentralDbContext as CentralDbContext;
if (centralDbContext == null) { return; }
_ = await centralDbContext.Database.EnsureDeletedAsync(CancellationToken.None);
}
catch (Exception ex)
{
throw;
}
}
}
@@ -0,0 +1,52 @@
using Microsoft.EntityFrameworkCore;
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.ContinuousImprovement.Biz.DbContexts;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
namespace Strata.ContinuousImprovement.Client.Test.Integration.Setup
{
[ExcludeFromCodeCoverage]
public static class ServiceCollectionFactory
{
// dev master
private static readonly Guid DevMasterDatabase = new("54409f55-5ddf-4748-8222-9ccfb04fb4f5");
private static readonly Guid SeleniumAutomationDatabase = new("6bcd9090-3446-4cc1-b1aa-38afae76a1c6");
private static readonly Guid SeleniumAutomationRefreshed4Master = new("feb7a099-8b2a-436c-9aba-0f853c8c60c9");
private static readonly string IntegrationTesting = $"ci_client_{DateTime.Now:yyyyMMdd}_{Guid.NewGuid():N}";
public static IServiceCollection Create()
{
var services = new ServiceCollection();
var jazzDbGuid = Debugger.IsAttached ? SeleniumAutomationRefreshed4Master : SeleniumAutomationDatabase;
// for now, though
jazzDbGuid = DevMasterDatabase;
try
{
var configuration = StrataConfigurationFactory.GetConfiguration();
services.AddSingleton(configuration);
services.AddStrataAuthentication(configuration);
services.AddStrataCors(configuration);
services.AddContinuousImprovementServices(configuration, IntegrationTesting);
services.AddAsyncDbContextFactory<JazzDbContext>(options =>
{
options
.WithConnectionString((provider, token) => provider.GetConnectionStringFromSmc(jazzDbGuid, token))
.WithDbContextOptions((connectionString, provider, builder) =>
builder.UseSqlServer(connectionString, options => { options.CommandTimeout(300); }));
});
services.AddLogging();
}
catch (Exception)
{
throw;
}
return services;
}
}
}
@@ -0,0 +1,138 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Strata.Analytics.Client;
using Strata.Analytics.Models.Workbooks;
using Strata.ContinuousImprovement.Biz.DbContexts;
using Strata.ContinuousImprovement.Biz.DbContexts.Snowflake;
using Strata.ContinuousImprovement.Biz.Generics;
using Strata.ContinuousImprovement.Biz.OpportunityTypeWorkbooks;
using Strata.ContinuousImprovement.Biz.OpportunityWorkbooks;
using Strata.ContinuousImprovement.JazzEntityFrameworkStub;
using Strata.SqlTools.Configuration.Common.AsyncFactory;
namespace Strata.ContinuousImprovement.Client.Test.Integration.Setup
{
public static class ServiceProperties
{
// dev master
internal static readonly Guid DatabaseGuid = new("54409f55-5ddf-4748-8222-9ccfb04fb4f5");
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
public static IContinuousImprovementService ContinuousImprovementService { get; set; }
public static ICentralDbContext CentralDbContext { get; set; }
public static JazzEntityFrameworkFactory JazzConnBuilderFactory { get; set; }
public static IJazzDbContext JazzDbContext { get; set; }
public static ISnowflakeDatabaseContext SnowflakeDatabaseContext { get; set; }
public static IServiceCollection Services { get; set; }
public static IServiceProvider ServiceProvider { get; set; }
public static IAnalyticsService AnalyticsService { get; set; }
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
private static int WorkbookId = 9;
public static async Task SetupServiceProperties(this IServiceCollection services, int strataId = 0)
{
Services = services;
var serviceProvider = services.BuildServiceProvider();
ServiceProvider = serviceProvider;
try
{
var sfConnBuilderFactory = serviceProvider.GetRequiredService<ISnowflakeDatabaseContextFactory>();
SnowflakeDatabaseContext = sfConnBuilderFactory.Create($"{DatabaseGuid:N}");
}
catch (Exception)
{
// ILB
}
try
{
var jazzConnBuilderFactory = serviceProvider.GetRequiredService<IAsyncDbContextFactory<JazzDbContext>>();
JazzDbContext = await jazzConnBuilderFactory.CreateDbContextAsync(CancellationToken.None);
}
catch (Exception)
{
// ILB
}
await BuildPostgresDb(strataId);
BuildAnalyticsService(strataId);
}
private static async Task BuildPostgresDb(int strataId)
{
try
{
CentralDbContext = ServiceProvider.GetService<CentralDbContext>() as CentralDbContext
?? throw new NullReferenceException(nameof(CentralDbContext));
var centralDbContext = CentralDbContext as CentralDbContext;
if (centralDbContext == null) { throw new NullReferenceException(nameof(centralDbContext)); }
await centralDbContext.Database.MigrateAsync(CancellationToken.None);
JazzConnBuilderFactory = new JazzEntityFrameworkFactory();
await JazzConnBuilderFactory.EnsureCreatedAsync(centralDbContext, JazzDbContext, CancellationToken.None);
var workbook = new OpportunityWorkbook
{
StrataId = strataId,
WorkbookId = WorkbookId,
OpportunityGuid = Guid.NewGuid(),
Name = "Test",
};
Assert.That(centralDbContext, Is.Not.Null);
await centralDbContext.OpportunityWorkbooks.AddAsync(workbook, CancellationToken.None);
var oppTypeWorkbook = new OpportunityTypeWorkbook
{
StrataId = strataId,
WorkbookId = WorkbookId,
OpportunityType = (int)OpportunityTypes.ChargeCode,
Name = "Test",
};
Assert.That(centralDbContext, Is.Not.Null);
await centralDbContext.OpportunityTypeWorkbooks.AddAsync(oppTypeWorkbook, CancellationToken.None);
await centralDbContext.SaveChangesAsync(CancellationToken.None);
}
catch (Exception)
{
throw;
}
}
private static void BuildAnalyticsService(int strataId)
{
var analyticsService = Mock.Of<IAnalyticsService>();
var workbook = new Workbook
{
Name = "Test",
WorkbookId = WorkbookId,
IsHidden = false,
StrataId = strataId,
};
var workbooks = new List<Workbook> { workbook };
workbooks.AddRange(Enumerable.Range(1, 1000).Where(i => i != WorkbookId).Select(i => new Workbook
{
Name = $"Test {i}",
WorkbookId = i,
IsHidden = (i % 2 == 0),
StrataId = (i % 3 == 0) ? 9 : strataId,
}));
//GetWorkbooksAsync
Mock.Get(analyticsService)
.Setup(s => s.GetWorkbookAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
.Returns<int, CancellationToken>((id, token)
=> Task.FromResult(id == WorkbookId ? workbook : null));
Mock.Get(analyticsService)
.Setup(s => s.GetWorkbooksAsync(It.IsAny<bool>(), It.IsAny<CancellationToken>()))
.Returns<bool, CancellationToken>((isHidden, token)
=> Task.FromResult(workbooks.Where(w => w.IsHidden == isHidden)));
AnalyticsService = analyticsService;
}
}
}
@@ -0,0 +1,8 @@
namespace Strata.ContinuousImprovement.Client.Test.Integration.Setup
{
public class VaultResponse
{
public string Password { get; set; }
}
}