Template
chore: deploy initial code base
This commit is contained in:
+124
@@ -0,0 +1,124 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Strata.ContinuousImprovement.Biz.Configuration;
|
||||
using Strata.ContinuousImprovement.Biz.DbContexts;
|
||||
using Strata.ContinuousImprovement.Biz.FiscalMonths;
|
||||
using Strata.ContinuousImprovement.JazzEntityFrameworkStub;
|
||||
using Strata.SqlTools.Configuration.Common.AsyncFactory;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Strata.ContinuousImprovement.Biz.Test.Unit.Configuration
|
||||
{
|
||||
[TestFixture, Category("Unit")]
|
||||
public class ConfigurationServiceTest
|
||||
{
|
||||
|
||||
private Mock<IConfigurationService> _configurationServiceMock;
|
||||
private Mock<IAsyncDbContextFactory<JazzDbContext>> _dbContextFactoryMock;
|
||||
private Mock<IJazzDbContext> _jazzDbContextMock;
|
||||
private Mock<IFiscalMonthResolver> _fiscalMonthResolverMock;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetUp()
|
||||
{
|
||||
_configurationServiceMock = new Mock<IConfigurationService>();
|
||||
_dbContextFactoryMock = new Mock<IAsyncDbContextFactory<JazzDbContext>>();
|
||||
_jazzDbContextMock = new Mock<IJazzDbContext>();
|
||||
_fiscalMonthResolverMock = new Mock<IFiscalMonthResolver>();
|
||||
}
|
||||
|
||||
[TestCaseSource(typeof(JazzEntityFrameworkFactory), nameof(JazzEntityFrameworkFactory.GetFrameworksWithCancellation))]
|
||||
public async Task TestGetDefaultConfigurationMock(JazzEntityFrameworkFactory framework, CancellationToken cancellationToken)
|
||||
{
|
||||
// arrange
|
||||
await framework.CreateDbContextAsync(CancellationToken.None);
|
||||
var dfltConfiguration = framework.Configurations.OrderBy(c => c.DisplayOrder).First();
|
||||
_configurationServiceMock
|
||||
.Setup(vos => vos
|
||||
.GetDefaultConfigurationAsync(It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(dfltConfiguration);
|
||||
var logger = Mock.Of<ILogger<ConfigurationService>>();
|
||||
var _configurationService = new ConfigurationService(framework, null, null, logger, _fiscalMonthResolverMock.Object);
|
||||
try
|
||||
{
|
||||
// act
|
||||
var taskResult = await _configurationService.GetDefaultConfigurationAsync(cancellationToken);
|
||||
|
||||
// assert
|
||||
if (taskResult == null)
|
||||
{
|
||||
framework.JazzDbContext.Should().BeNull();
|
||||
return;
|
||||
}
|
||||
taskResult.Should().BeOfType<Biz.Configuration.Configuration>();
|
||||
taskResult.Name.Should().Be(dfltConfiguration.Name);
|
||||
taskResult.DisplayOrder.Should().Be(dfltConfiguration.DisplayOrder);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
cancellationToken.Should().NotBe(CancellationToken.None);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Intentionally left empty
|
||||
}
|
||||
}
|
||||
|
||||
[TestCaseSource(typeof(JazzEntityFrameworkFactory), nameof(JazzEntityFrameworkFactory.GetFrameworksWithCancellation))]
|
||||
public async Task TestGetDefaultConfiguration(JazzEntityFrameworkFactory jazzEntityFrameworkFactory, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
// arrange
|
||||
var logger = Mock.Of<ILogger<ConfigurationService>>();
|
||||
await jazzEntityFrameworkFactory.CreateDbContextAsync(CancellationToken.None);
|
||||
var configurationService = new ConfigurationService(jazzEntityFrameworkFactory, null, null, logger, _fiscalMonthResolverMock.Object);
|
||||
|
||||
// act
|
||||
var taskResult = await configurationService.GetDefaultConfigurationAsync(cancellationToken);
|
||||
|
||||
// assert
|
||||
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName))
|
||||
{
|
||||
taskResult.Should().BeNull();
|
||||
}
|
||||
else
|
||||
{
|
||||
taskResult.Should().NotBeNull()
|
||||
.And.BeOfType<Biz.Configuration.Configuration>();
|
||||
taskResult.QVIOpportunityBreakdownName.Should().NotBeNullOrEmpty();
|
||||
taskResult.QVIOpportunityBreakdownNamePlural.Should().NotBeNullOrEmpty();
|
||||
taskResult.QVIOpportunityBreakdownEnum.Should()
|
||||
.Be((int)taskResult.QVIOpportunityBreakdown);
|
||||
}
|
||||
}
|
||||
catch (AggregateException ae)
|
||||
{
|
||||
ae.Should().NotBeOfType<AggregateException>();
|
||||
}
|
||||
catch (InvalidOperationException ioe)
|
||||
{
|
||||
ioe.Should().NotBeOfType<InvalidOperationException>();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
cancellationToken.Should().NotBe(CancellationToken.None);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Intentionally left blank
|
||||
}
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TestTearDown()
|
||||
{
|
||||
// Method intentionally left empty.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Strata.ContinuousImprovement.Biz.FiscalMonths;
|
||||
using Strata.ContinuousImprovement.Biz.Generics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using config = Strata.ContinuousImprovement.Biz.Configuration;
|
||||
|
||||
namespace Strata.ContinuousImprovement.Biz.Test.Unit.Configuration
|
||||
{
|
||||
|
||||
[TestFixture, Category("Unit")]
|
||||
public class ConfigurationTest
|
||||
{
|
||||
private IEnumerable<OpportunityTypes> excludedOpportTypes = new List<OpportunityTypes>()
|
||||
{
|
||||
OpportunityTypes.Blank,
|
||||
OpportunityTypes.Network
|
||||
};
|
||||
private IEnumerable<OpportunityTypes> OpportTypes { get; set; }
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetup()
|
||||
{
|
||||
OpportTypes = Enum.GetValues(typeof(OpportunityTypes))
|
||||
.Cast<OpportunityTypes>()
|
||||
.Where(x => !excludedOpportTypes.Contains(x));
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(ConfigTestCases))]
|
||||
public void TestConfiguration(string rollup, string ids, int breakdown,
|
||||
IEnumerable<int> configuredIds, string name, string plural)
|
||||
{
|
||||
var config = new config.Configuration
|
||||
{
|
||||
DepartmentRollupGlobalId = rollup,
|
||||
EntityIdsCSV = string.IsNullOrEmpty(rollup) ? "" : ids,
|
||||
CustomEntityIdsCSV = string.IsNullOrEmpty(rollup) ? ids : "",
|
||||
QVIOpportunityBreakdown = (Biz.Configuration.Configuration.QVIOpportunityBreakdowns)breakdown
|
||||
};
|
||||
config.ConfiguredEntityIds.Should().AllBeEquivalentTo(configuredIds);
|
||||
config.QVIOpportunityBreakdownEnum.Should().Be(breakdown);
|
||||
config.QVIOpportunityBreakdownName.Should().Be(name);
|
||||
config.QVIOpportunityBreakdownNamePlural.Should().Be(plural);
|
||||
config.ServiceLineDimensionGuid.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(StartEndDateTestCases))]
|
||||
public void TestGetBaselineStartDate(DateTime expectedStartDate, DateTime endDate)
|
||||
{
|
||||
var configuration = GetConfigurationByDate(endDate);
|
||||
var opportunityTypeIds = Enum.GetValues<OpportunityTypes>().Cast<byte>().ToList();
|
||||
foreach (var opType in OpportTypes.Where(t => opportunityTypeIds.Contains((byte)t)))
|
||||
{
|
||||
var actualStartDate = configuration.GetBaselineStartDate(opType);
|
||||
actualStartDate.Should().Be(expectedStartDate);
|
||||
}
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(StartEndDateTestCases))]
|
||||
public void TestGetLastFiscalYearStartDate(DateTime expectedStartDate, DateTime endDate)
|
||||
{
|
||||
var configuration = GetConfigurationByDate(endDate, true);
|
||||
|
||||
var actualStartDate = configuration.GetLastFiscalYearStartDate();
|
||||
expectedStartDate = expectedStartDate.AddYears(-1);
|
||||
actualStartDate.Should().Be(expectedStartDate);
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(StartEndDateTestCases))]
|
||||
public void TestGetFiscalYearStartDate(DateTime expectedStartDate, DateTime endDate)
|
||||
{
|
||||
var configuration = GetConfigurationByDate(endDate, true);
|
||||
|
||||
var actualStartDate = configuration.GetFiscalYearStartDate();
|
||||
actualStartDate.Should().Be(expectedStartDate);
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(TrackingCurrentMonthEndDateTestCases))]
|
||||
public void TestTrackingCurrentMonthEndDate(
|
||||
OpportunityTypes opportunityType,
|
||||
DateTime trackingCurrentMonth,
|
||||
DateTime expectedEndDate)
|
||||
{
|
||||
var configuration = GetConfigurationWithTrackingMonth(trackingCurrentMonth, opportunityType);
|
||||
|
||||
var actualEndDate = configuration.TrackingCurrentMonthEndDate(opportunityType);
|
||||
|
||||
actualEndDate.Should().Be(expectedEndDate);
|
||||
actualEndDate.Hour.Should().Be(0);
|
||||
actualEndDate.Minute.Should().Be(0);
|
||||
actualEndDate.Second.Should().Be(0);
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(TrackingCurrentMonthEndDateTestCases))]
|
||||
public void TestGetTrackingCurrentMonthEndDate(
|
||||
OpportunityTypes opportunityType,
|
||||
DateTime trackingCurrentMonth,
|
||||
DateTime expectedEndDate)
|
||||
{
|
||||
var configuration = GetConfigurationWithTrackingMonth(trackingCurrentMonth, opportunityType);
|
||||
|
||||
var actualEndDate = configuration.GetTrackingCurrentMonthEndDate(opportunityType);
|
||||
|
||||
actualEndDate.Should().Be(expectedEndDate.AddDays(-1));
|
||||
}
|
||||
|
||||
#region Configuration Test Cases
|
||||
|
||||
private static IEnumerable<TestCaseData> ConfigTestCases()
|
||||
{
|
||||
yield return new TestCaseData("Rollup", "1,2,3,4", 4,
|
||||
new[] { 1, 2, 3, 4 }, "Breakdown", "Breakdowns")
|
||||
.SetName("Default With Rollup");
|
||||
yield return new TestCaseData("", "1,2,3,4", 4,
|
||||
new[] { 1, 2, 3, 4 }, "Breakdown", "Breakdowns")
|
||||
.SetName("Default w/o Rollup");
|
||||
yield return new TestCaseData("Rollup", "1,2,3,4",
|
||||
(int)config.Configuration.QVIOpportunityBreakdowns.Entity,
|
||||
new[] { 1, 2, 3, 4 }, "Entity", "Entities")
|
||||
.SetName("Entity With Rollup");
|
||||
yield return new TestCaseData("", "1,2,3,4",
|
||||
(int)config.Configuration.QVIOpportunityBreakdowns.Entity,
|
||||
new[] { 1, 2, 3, 4 }, "Entity", "Entities")
|
||||
.SetName("Entity w/o Rollup");
|
||||
yield return new TestCaseData("Rollup", "1,2,3,4",
|
||||
(int)config.Configuration.QVIOpportunityBreakdowns.ServiceLine,
|
||||
new[] { 1, 2, 3, 4 }, "Service Line", "Service Lines")
|
||||
.SetName("Service Line With Rollup");
|
||||
yield return new TestCaseData("", "1,2,3,4",
|
||||
(int)config.Configuration.QVIOpportunityBreakdowns.ServiceLine,
|
||||
new[] { 1, 2, 3, 4 }, "Service Line", "Service Lines")
|
||||
.SetName("Service Line w/o Rollup");
|
||||
yield return new TestCaseData("Rollup", "1,2,3,4",
|
||||
(int)config.Configuration.QVIOpportunityBreakdowns.PhysicianSpecialty,
|
||||
new[] { 1, 2, 3, 4 }, "Physician Specialty", "Physician Specialties")
|
||||
.SetName("Physician Specialty With Rollup");
|
||||
yield return new TestCaseData("", "1,2,3,4",
|
||||
(int)config.Configuration.QVIOpportunityBreakdowns.PhysicianSpecialty,
|
||||
new[] { 1, 2, 3, 4 }, "Physician Specialty", "Physician Specialties")
|
||||
.SetName("Physician Specialty w/o Rollup");
|
||||
}
|
||||
|
||||
private static IEnumerable<TestCaseData> StartEndDateTestCases()
|
||||
{
|
||||
yield return new TestCaseData(new DateTime(2023, 3, 1), new DateTime(2024, 2, 29));
|
||||
yield return new TestCaseData(new DateTime(2024, 3, 1), new DateTime(2025, 2, 28));
|
||||
}
|
||||
|
||||
private static IEnumerable<TestCaseData> TrackingCurrentMonthEndDateTestCases()
|
||||
{
|
||||
yield return new TestCaseData(
|
||||
OpportunityTypes.ChargeCode,
|
||||
new DateTime(2024, 3, 15),
|
||||
new DateTime(2024, 4, 1))
|
||||
.SetName("ChargeCode - March 2024");
|
||||
|
||||
yield return new TestCaseData(
|
||||
OpportunityTypes.QualityVariation,
|
||||
new DateTime(2024, 6, 20),
|
||||
new DateTime(2024, 7, 1))
|
||||
.SetName("QualityVariation - June 2024");
|
||||
|
||||
yield return new TestCaseData(
|
||||
OpportunityTypes.Variation,
|
||||
new DateTime(2024, 12, 5),
|
||||
new DateTime(2025, 1, 1))
|
||||
.SetName("Variation - December 2024");
|
||||
|
||||
yield return new TestCaseData(
|
||||
OpportunityTypes.OrgDefined,
|
||||
new DateTime(2024, 2, 10),
|
||||
new DateTime(2024, 3, 1))
|
||||
.SetName("OrgDefined - February 2024");
|
||||
|
||||
yield return new TestCaseData(
|
||||
OpportunityTypes.Exploration,
|
||||
new DateTime(2024, 1, 31),
|
||||
new DateTime(2024, 2, 1))
|
||||
.SetName("Exploration - January 2024");
|
||||
|
||||
yield return new TestCaseData(
|
||||
OpportunityTypes.ChargeCode,
|
||||
new DateTime(2024, 2, 29),
|
||||
new DateTime(2024, 3, 1))
|
||||
.SetName("ChargeCode - Leap Year February");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Utils
|
||||
|
||||
private static config.Configuration GetConfigurationByDate(DateTime date, bool isFiscalMonthResolver = false)
|
||||
{
|
||||
var configuration = new config.Configuration
|
||||
{
|
||||
FiscalYearID = (short)date.Year,
|
||||
OrgDefinedEndDate = date,
|
||||
VariationEndDate = date,
|
||||
QualityVariationEndDate = date
|
||||
};
|
||||
|
||||
if (isFiscalMonthResolver)
|
||||
{
|
||||
var lastFiscalMonth = new FiscalMonth
|
||||
{
|
||||
FiscalMonthId = (byte)date.Month
|
||||
};
|
||||
var fmr = Mock.Of<IFiscalMonthResolver>();
|
||||
Mock.Get(fmr)
|
||||
.Setup(s => s.LastFiscalMonth())
|
||||
.Returns(() => lastFiscalMonth);
|
||||
configuration.FiscalMonthResolver = fmr;
|
||||
}
|
||||
return configuration;
|
||||
}
|
||||
|
||||
private static config.Configuration GetConfigurationWithTrackingMonth(
|
||||
DateTime trackingCurrentMonth,
|
||||
OpportunityTypes opportunityType)
|
||||
{
|
||||
var configuration = new config.Configuration();
|
||||
|
||||
switch (opportunityType)
|
||||
{
|
||||
case OpportunityTypes.ChargeCode:
|
||||
configuration.OrgDefinedTrackingCurrentMonth = trackingCurrentMonth;
|
||||
break;
|
||||
case OpportunityTypes.QualityVariation:
|
||||
configuration.QualityVariationTrackingCurrentMonth = trackingCurrentMonth;
|
||||
break;
|
||||
default:
|
||||
configuration.VariationTrackingCurrentMonth = trackingCurrentMonth;
|
||||
break;
|
||||
}
|
||||
|
||||
return configuration;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user