Template
chore: deploy initial code base
This commit is contained in:
+253
@@ -0,0 +1,253 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Strata.ContinuousImprovement.Biz.ChargeCode;
|
||||
using Strata.ContinuousImprovement.Biz.ChargeCode.Opportunities;
|
||||
using Strata.ContinuousImprovement.Biz.DbContexts;
|
||||
using Strata.ContinuousImprovement.Biz.Test.Unit.Utilities;
|
||||
using Strata.ContinuousImprovement.JazzEntityFrameworkStub;
|
||||
using Strata.Schema.Client.Dtos;
|
||||
using Strata.SqlTools.Configuration.Common.AsyncFactory;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using VerifyNUnit;
|
||||
|
||||
namespace Strata.ContinuousImprovement.Biz.Test.Unit.ChargeCode.Opportunities
|
||||
{
|
||||
[TestFixture()]
|
||||
public class CCOpportunityServiceTests : OpportunityServiceTests
|
||||
{
|
||||
public IJazzDbContext DbContext { get; set; }
|
||||
private IAsyncDbContextFactory<JazzDbContext> _dbContextFactory { get; set; }
|
||||
public ICCOpportunityService CCOpportunityService { get; set; }
|
||||
public IOptions<ChargeCodeOpportunityValidationSection> SectionAccessor { get; set; }
|
||||
public ILogger<CCOpportunityService> Logger { get; set; }
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
var chargeCodeDimensionGuid = Guid.NewGuid();
|
||||
var caseTypeDimensionGuid = Guid.NewGuid();
|
||||
Mock.Get(SchemaServiceClient)
|
||||
.Setup(s => s.GetDimensionByGlobalIdAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<string, CancellationToken>((globalId, token) =>
|
||||
globalId switch
|
||||
{
|
||||
"Charge Code" => Task.FromResult(new Schema.Client.Dtos.Info.ScoreDimensionInfoDto { DimensionGuid = chargeCodeDimensionGuid }),
|
||||
"Case Type" => Task.FromResult(new Schema.Client.Dtos.Info.ScoreDimensionInfoDto { DimensionGuid = caseTypeDimensionGuid }),
|
||||
_ => Task.FromResult(new Schema.Client.Dtos.Info.ScoreDimensionInfoDto { DimensionGuid = Guid.NewGuid() })
|
||||
});
|
||||
Mock.Get(SchemaServiceClient)
|
||||
.Setup(x => x.GetHierarchyNodesFromHierarchyPathsAsync(It.IsAny<Guid>(), It.IsAny<IEnumerable<string>>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<Guid, IEnumerable<string>, CancellationToken>((dimensionGuid, codeHpaths, token)
|
||||
=> Task.FromResult(new List<HierarchyNodeDto> {
|
||||
new HierarchyNodeDto{
|
||||
Path = "Path",
|
||||
PathDisplay = "PathDisplay",
|
||||
Name = "Name",
|
||||
Count = 10,
|
||||
IsLeaf= false
|
||||
}
|
||||
}.AsEnumerable()));
|
||||
Mock.Get(SchemaServiceClient)
|
||||
.Setup(x => x.GetDimensionMembersFromHierarchyPathsAsync(It.IsAny<Guid>(), It.IsAny<IEnumerable<string>>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<Guid, IEnumerable<string>, CancellationToken>((dimensionGuid, codeHpaths, token)
|
||||
=> Task.FromResult(new List<MemberDto> {
|
||||
new MemberDto
|
||||
{
|
||||
Name ="Name",
|
||||
Id = "02"
|
||||
}
|
||||
}.AsEnumerable()));
|
||||
Mock.Get(SchemaServiceClient)
|
||||
.Setup(x => x.GetFilteredDimensionMembersByGlobalIdAsync<ChargeCodePickerModel>(It.IsAny<string>(), It.IsAny<List<int>>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(Task.FromResult(new List<ChargeCodePickerModel> {
|
||||
new ChargeCodePickerModel(){
|
||||
ChargeCodeId = 99,
|
||||
Name = "TestName",
|
||||
CostDriver = "TestCostDriver",
|
||||
Rollup = "TestRollup"
|
||||
}
|
||||
}.AsEnumerable()));
|
||||
var principal = TestUtilities.GetClaimsPrincipalAccessor();
|
||||
var defaultUser = principal.GetCurrentClaimsPrincipal();
|
||||
Mock.Get(ClaimsPrincipalAccessor)
|
||||
.Setup(x => x.GetCurrentClaimsPrincipal())
|
||||
.Returns(defaultUser);
|
||||
|
||||
SectionAccessor = Mock.Of<IOptions<ChargeCodeOpportunityValidationSection>>();
|
||||
Mock.Get(SectionAccessor)
|
||||
.Setup(x => x.Value)
|
||||
.Returns(new ChargeCodeOpportunityValidationSection
|
||||
{
|
||||
MaxChargeCodeSelections = 10,
|
||||
MaxOpportunityLevelSelections = 10,
|
||||
});
|
||||
Logger = Mock.Of<ILogger<CCOpportunityService>>();
|
||||
|
||||
CCOpportunityService = new CCOpportunityService(DbContextFactory,
|
||||
null, // CentralDbContext,
|
||||
ClaimsPrincipalAccessor,
|
||||
ConfigurationService,
|
||||
AuthorizationServiceClient,
|
||||
IdServiceClient,
|
||||
FiscalMonthResolver,
|
||||
SchemaServiceClient,
|
||||
BackgroundJobClient,
|
||||
NotificationHubContext,
|
||||
SectionAccessor,
|
||||
InitiativeService,
|
||||
SnowflakeDatabaseContext,
|
||||
UpdateFactOpportunitySavingsService,
|
||||
Logger);
|
||||
}
|
||||
|
||||
[Test()]
|
||||
public async Task CCOpportunityServiceTest()
|
||||
{
|
||||
await Verifier.Verify(CCOpportunityService, VerifySettings)
|
||||
.UseFileName(TestContext.CurrentContext.TestName());
|
||||
}
|
||||
|
||||
[Test()]
|
||||
public async Task GetDbContextAsyncTest()
|
||||
{
|
||||
var dbContext = await CCOpportunityService.GetDbContext(CancellationToken.None);
|
||||
var names = dbContext.AllOpportunities.Select(opp => $"All - {opp.Name} {opp.OpportunityId}").ToList();
|
||||
names.AddRange(dbContext.ChargeCodeOpportunities.Select(opp => opp.Name ?? ""));
|
||||
names.AddRange(dbContext.EncounterOpportunities.Select(opp => opp.Name ?? ""));
|
||||
names.AddRange(dbContext.FFOpportunities.Select(opp => opp.Name ?? ""));
|
||||
names.AddRange(dbContext.GeneralLedgerOpportunities.Select(opp => opp.Name ?? ""));
|
||||
names.AddRange(dbContext.Initiatives.Select(opp => $"Initiative - {opp.Name} {opp.OpportunityId}"));
|
||||
names.AddRange(dbContext.PayrollOpportunities.Select(opp => opp.Name ?? ""));
|
||||
names.AddRange(dbContext.VariationOpportunities.Where(opp => opp.OpportunityKey.StartsWith("UV"))
|
||||
.Select(opp => $"{opp.CostDriver ?? ""} {opp.ServiceLineName ?? ""} {opp.EntityName ?? ""} {opp.OpportunityId}"));
|
||||
await Verifier.Verify(new
|
||||
{
|
||||
names = names.Distinct().OrderBy(x => x),
|
||||
counts = new[] {
|
||||
dbContext.Configurations.Count(),
|
||||
dbContext.AllOpportunities.Count(opp => !opp.OpportunityKey.StartsWith("FE")),
|
||||
dbContext.ChargeCodeOpportunities.Count(),
|
||||
dbContext.EncounterOpportunities.Count(),
|
||||
dbContext.FFOpportunities.Count(),
|
||||
dbContext.GeneralLedgerOpportunities.Count(),
|
||||
dbContext.Initiatives.Count(),
|
||||
dbContext.PayrollOpportunities.Count(),
|
||||
dbContext.VariationOpportunities.Count(opp => opp.OpportunityKey.StartsWith("UV"))
|
||||
}
|
||||
}, VerifySettings)
|
||||
.IgnoreInstance<Guid>((x) => true)
|
||||
.UseFileName(TestContext.CurrentContext.TestName());
|
||||
}
|
||||
|
||||
[Test()]
|
||||
public async Task GetChargeCodeCustomPickerMembersAsyncTest()
|
||||
{
|
||||
var result = await CCOpportunityService.GetChargeCodePickerModelMembers(new List<string>
|
||||
{
|
||||
"CC 1"
|
||||
}, CancellationToken.None);
|
||||
await Verifier.Verify(result, VerifySettings)
|
||||
.UseFileName(TestContext.CurrentContext.TestName());
|
||||
}
|
||||
|
||||
[Test()]
|
||||
public async Task ValidateOpportunityLevelsAsyncTest()
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
}
|
||||
|
||||
[Test()]
|
||||
public async Task CreateAsyncTest()
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
}
|
||||
|
||||
[Test(), Ignore("Still working on this")]
|
||||
public async Task UpdateAsyncTest()
|
||||
{
|
||||
var dbGuid = JazzEntityFrameworkFactory.DatabaseGuid;
|
||||
var opportunities = JAZZ_Framework.ChargeCodeOpportunities;
|
||||
var opportunity = opportunities.FirstOrDefault();
|
||||
opportunity.Name += " Updated";
|
||||
|
||||
var result = await CCOpportunityService.UpdateAsync(dbGuid, opportunity, CancellationToken.None);
|
||||
await Verifier.Verify(result, VerifySettings)
|
||||
.DontScrubGuids()
|
||||
.UseFileName(TestContext.CurrentContext.TestName());
|
||||
}
|
||||
|
||||
[Test()]
|
||||
public async Task GetByIdTest()
|
||||
{
|
||||
var opportunities = JAZZ_Framework.CCOpportunities;
|
||||
var opportunity = opportunities.FirstOrDefault();
|
||||
|
||||
var result = await CCOpportunityService.GetById(opportunity.OpportunityGuid, CancellationToken.None);
|
||||
result.Configuration = null;
|
||||
await Verifier.Verify(result, VerifySettings)
|
||||
.DontScrubGuids()
|
||||
.UseFileName(TestContext.CurrentContext.TestName());
|
||||
}
|
||||
|
||||
[Test()]
|
||||
public async Task DeleteAsyncTest()
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
}
|
||||
|
||||
[Test()]
|
||||
public async Task GetInitiativeInfoAsyncTest()
|
||||
{
|
||||
var opportunities = JAZZ_Framework.CCOpportunities;
|
||||
var opportunity = opportunities.FirstOrDefault();
|
||||
|
||||
var result = await CCOpportunityService.GetInitiativeInfoAsync(opportunity.OpportunityGuid, CancellationToken.None);
|
||||
await Verifier.Verify(result, VerifySettings)
|
||||
.DontScrubGuids()
|
||||
.UseFileName(TestContext.CurrentContext.TestName());
|
||||
}
|
||||
|
||||
[Test()]
|
||||
public async Task RefreshOpportunityTrackingDataTest()
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
}
|
||||
|
||||
[Test(), Ignore("Still working on this")]
|
||||
public async Task ExportAsyncTest()
|
||||
{
|
||||
var opportunities = JAZZ_Framework.CCOpportunities;
|
||||
var opportunity = opportunities.FirstOrDefault();
|
||||
|
||||
var export = await CCOpportunityService.ExportAsync(opportunity.OpportunityGuid, new string[] { "CC 1" }, "", CancellationToken.None);
|
||||
var result = export.GetDataTables();
|
||||
await Verifier.Verify(result, VerifySettings)
|
||||
.DontScrubGuids()
|
||||
.UseFileName(TestContext.CurrentContext.TestName());
|
||||
}
|
||||
|
||||
[Test()]
|
||||
public async Task UpdateGoalTotalUnitsOfServiceAsyncTest()
|
||||
{
|
||||
var opportunities = JAZZ_Framework.CCOpportunities;
|
||||
var opportunity = opportunities.FirstOrDefault();
|
||||
|
||||
var result = await CCOpportunityService.UpdateGoalTotalUnitsOfServiceAsync(opportunity.OpportunityGuid, "|CC 1|", 100, CancellationToken.None);
|
||||
//await Verifier.Verify(result, VerifySettings)
|
||||
// .DontScrubGuids()
|
||||
// .UseFileName(TestContext.CurrentContext.TestName());
|
||||
}
|
||||
|
||||
[Test()]
|
||||
public async Task UpdateGoalCostPerUnitAsyncTest()
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
}
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Strata.ContinuousImprovement.Biz.ChargeCode.Opportunities;
|
||||
using Strata.ContinuousImprovement.Biz.Shared;
|
||||
using Strata.ContinuousImprovement.Biz.Test.Unit.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using VerifyNUnit;
|
||||
using VerifyTests;
|
||||
|
||||
namespace Strata.ContinuousImprovement.Biz.Test.Unit.ChargeCode.Opportunities
|
||||
{
|
||||
[TestFixture, Category("Unit")]
|
||||
public class OpportunityDetailLevelQueryTests
|
||||
{
|
||||
private VerifySettings _verifySettings;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
_verifySettings = TestExtensions.TestSettings();
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(OpportunityDetailLevelQueryTestCases))]
|
||||
public async Task OpportunityDetailLevelQueryTest(OpportunityLevel opportunityLevel, QueryHelper encounterQueryHelper,
|
||||
QueryHelper opportunityLevelQueryHelper)
|
||||
{
|
||||
var query = new OpportunityDetailLevelQuery(opportunityLevel, encounterQueryHelper, opportunityLevelQueryHelper);
|
||||
var result = query.GetQuery();
|
||||
await Verifier.Verify(result, _verifySettings)
|
||||
.UseFileName(TestContext.CurrentContext.TestName());
|
||||
}
|
||||
|
||||
public static IEnumerable<TestCaseData> OpportunityDetailLevelQueryTestCases()
|
||||
{
|
||||
var configuration = Mock.Of<Biz.Configuration.Configuration>();
|
||||
configuration.DepartmentRollupGlobalId = "";
|
||||
var sqlParameters = new SqlParameter[] {
|
||||
new SqlParameter("@chargeCodeIds", new List<int> { 1, 2, 3 }),
|
||||
new SqlParameter("@caseTypeIds", new List<int> { 1, 2, 3 }),
|
||||
new SqlParameter("@startDate", new DateTime(2023,1,1)),
|
||||
new SqlParameter("@endDate", new DateTime(2024,1,1)),
|
||||
new SqlParameter("@isBaseline", true)
|
||||
};
|
||||
|
||||
foreach (var parameterName in new[] { "@caseTypeIds", "@indicatorIds" })
|
||||
{
|
||||
sqlParameters[1].ParameterName = parameterName;
|
||||
foreach (var isUsingSnowflake in new[] { true, false })
|
||||
{
|
||||
foreach (var oppLevel in Enum.GetValues<OpportunityLevel>())
|
||||
{
|
||||
switch (oppLevel)
|
||||
{
|
||||
case OpportunityLevel.ServiceLine:
|
||||
foreach (var serviceLine in new[] { "Sg2 Service Line Crosswalk", "Service Line" })
|
||||
{
|
||||
yield return new TestCaseData(oppLevel,
|
||||
new EncounterGroupQueryHelper(sqlParameters),
|
||||
new OpportunityLevelQueryHelper(oppLevel, configuration, serviceLine, $"{(serviceLine.Replace(" ", ""))}Id"))
|
||||
.SetName($"{{m}} {Enum.GetName<OpportunityLevel>(oppLevel)} {parameterName.Substring(1)} {serviceLine} {(isUsingSnowflake ? "Snowflake" : "")}");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
yield return new TestCaseData(oppLevel,
|
||||
new EncounterGroupQueryHelper(sqlParameters),
|
||||
new OpportunityLevelQueryHelper(oppLevel, configuration, "", ""))
|
||||
.SetName($"{{m}} {Enum.GetName<OpportunityLevel>(oppLevel)} {parameterName.Substring(1)} Default {(isUsingSnowflake ? "Snowflake" : "")}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Strata.ContinuousImprovement.Biz.ChargeCode.Opportunities;
|
||||
using Strata.ContinuousImprovement.Biz.DbContexts.Snowflake;
|
||||
using Strata.ContinuousImprovement.Biz.Shared;
|
||||
using Strata.ContinuousImprovement.Biz.Test.Unit.Utilities;
|
||||
using Strata.ContinuousImprovement.Biz.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using VerifyNUnit;
|
||||
using VerifyTests;
|
||||
|
||||
namespace Strata.ContinuousImprovement.Biz.Test.Unit.ChargeCode.Opportunities
|
||||
{
|
||||
[TestFixture, Category("Unit")]
|
||||
public class OpportunityDetailQueryTests
|
||||
{
|
||||
private VerifySettings _verifySettings;
|
||||
private Biz.Configuration.Configuration _configuration;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
_configuration = Mock.Of<Biz.Configuration.Configuration>();
|
||||
_verifySettings = TestExtensions.TestSettings();
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(OpportunityDetailQueryTestCases))]
|
||||
public async Task OpportunityDetailQueryTest(OpportunityLevel opportunityLevel, IEnumerable<SqlParameter> sqlParameters, QueryHelper encounterQueryHelper, QueryHelper opportunityLevelQueryHelper, bool isUsingSnowflake)
|
||||
{
|
||||
var query = new OpportunityDetailQuery(opportunityLevel, encounterQueryHelper, opportunityLevelQueryHelper, isUsingSnowflake);
|
||||
var result = isUsingSnowflake
|
||||
? query.GetQuery().ConvertSqlToSnowflakeParameterSyntax()
|
||||
: query.GetQuery().InterpolateQueryArrayValues(ref sqlParameters);
|
||||
await Verifier.Verify(result, _verifySettings)
|
||||
.UseFileName(TestContext.CurrentContext.TestName());
|
||||
}
|
||||
|
||||
public static IEnumerable<TestCaseData> OpportunityDetailQueryTestCases()
|
||||
{
|
||||
var configuration = Mock.Of<Biz.Configuration.Configuration>();
|
||||
configuration.DepartmentRollupGlobalId = "";
|
||||
var sqlParameters = new SqlParameter[] {
|
||||
new SqlParameter("@chargeCodeIds", new List<int> { 1, 2, 3 }),
|
||||
new SqlParameter("@caseTypeIds", new List<int> { 7, 8, 9 }),
|
||||
new SqlParameter("@oppLevelIds", new List<int>{ 4, 5, 6 }),
|
||||
new SqlParameter("@startDate", new DateTime(2023,1,1)),
|
||||
new SqlParameter("@endDate", new DateTime(2024,1,1)),
|
||||
new SqlParameter("@isBaseline", true)
|
||||
};
|
||||
|
||||
foreach (var parameterName in new[] { "@caseTypeIds", "@indicatorIds" })
|
||||
{
|
||||
sqlParameters[1].ParameterName = parameterName;
|
||||
foreach (var isUsingSnowflake in new[] { true, false })
|
||||
{
|
||||
foreach (var oppLevel in Enum.GetValues<OpportunityLevel>())
|
||||
{
|
||||
switch (oppLevel)
|
||||
{
|
||||
case OpportunityLevel.ServiceLine:
|
||||
foreach (var serviceLine in new[] { "Sg2 Service Line Crosswalk", "Service Line" })
|
||||
{
|
||||
yield return new TestCaseData(oppLevel, sqlParameters,
|
||||
new EncounterGroupQueryHelper(sqlParameters),
|
||||
new OpportunityLevelQueryHelper(oppLevel, configuration, serviceLine, $"{(serviceLine.Replace(" ", ""))}Id"), isUsingSnowflake)
|
||||
.SetName($"{{m}} {Enum.GetName<OpportunityLevel>(oppLevel)} {parameterName.Substring(1)} {serviceLine} {(isUsingSnowflake ? "Snowflake" : "")}");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
yield return new TestCaseData(oppLevel, sqlParameters,
|
||||
new EncounterGroupQueryHelper(sqlParameters),
|
||||
new OpportunityLevelQueryHelper(oppLevel, configuration, "", ""), isUsingSnowflake)
|
||||
.SetName($"{{m}} {Enum.GetName<OpportunityLevel>(oppLevel)} {parameterName.Substring(1)} Default {(isUsingSnowflake ? "Snowflake" : "")}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user