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.
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user