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(); _verifySettings = TestExtensions.TestSettings(); } [TestCaseSource(nameof(OpportunityDetailQueryTestCases))] public async Task OpportunityDetailQueryTest(OpportunityLevel opportunityLevel, IEnumerable 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 OpportunityDetailQueryTestCases() { var configuration = Mock.Of(); configuration.DepartmentRollupGlobalId = ""; var sqlParameters = new SqlParameter[] { new SqlParameter("@chargeCodeIds", new List { 1, 2, 3 }), new SqlParameter("@caseTypeIds", new List { 7, 8, 9 }), new SqlParameter("@oppLevelIds", new List{ 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()) { 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(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(oppLevel)} {parameterName.Substring(1)} Default {(isUsingSnowflake ? "Snowflake" : "")}"); break; } } } } } } }