Template
chore: deploy initial code base
This commit is contained in:
+225
@@ -0,0 +1,225 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Strata.ContinuousImprovement.Api.Controllers;
|
||||
using Strata.ContinuousImprovement.Biz.Configuration;
|
||||
using Strata.ContinuousImprovement.Biz.DbContexts;
|
||||
using Strata.ContinuousImprovement.Biz.Exploration;
|
||||
using Strata.ContinuousImprovement.Biz.Exploration.CaseTypeFamilies;
|
||||
using Strata.ContinuousImprovement.Biz.Exploration.Filters;
|
||||
using Strata.ContinuousImprovement.JazzEntityFrameworkStub;
|
||||
using Strata.FeatureFlags.Client;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Strata.ContinuousImprovement.Api.Test.Unit.Controllers
|
||||
{
|
||||
[TestFixture, Category("Unit"), Category("Controller")]
|
||||
public class ExplorationControllerTests
|
||||
{
|
||||
public JazzEntityFrameworkFactory JazzEntityFrameworkFactory { get; set; }
|
||||
public JazzDbContext JazzDbContext { get; set; }
|
||||
public ExplorationController ExplorationController { get; set; }
|
||||
public IConfigurationService ConfigurationService { get; set; }
|
||||
public IExplorationService ExplorationService { get; set; }
|
||||
public IFeatureFlagServiceClient FeatureFlagServiceClient { get; set; }
|
||||
|
||||
[OneTimeSetUp]
|
||||
public async Task ClientNetworkOpportunityLinkControllerTestsSetup()
|
||||
{
|
||||
// Arrange
|
||||
JazzEntityFrameworkFactory = new JazzEntityFrameworkFactory();
|
||||
JazzDbContext = await JazzEntityFrameworkFactory.CreateDbContextAsync(nameof(ConfigurationsControllerTests), CancellationToken.None);
|
||||
ConfigurationService = Mock.Of<IConfigurationService>();
|
||||
ExplorationService = Mock.Of<IExplorationService>();
|
||||
FeatureFlagServiceClient = Mock.Of<IFeatureFlagServiceClient>();
|
||||
|
||||
// Act
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public async Task Setup()
|
||||
{
|
||||
// Arrange
|
||||
ExplorationController = new ExplorationController(ExplorationService, ConfigurationService, FeatureFlagServiceClient, Mock.Of<ILogger<ExplorationController>>());
|
||||
|
||||
// Act
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ExplorationControllerTest()
|
||||
{
|
||||
// Assert
|
||||
ExplorationController.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(GetCaseTypeFamilySummariesTestCases))]
|
||||
public async Task GetCaseTypeFamilySummariesTest(Guid configurationGuid)
|
||||
{
|
||||
// Arrange
|
||||
var configuration = JazzDbContext.Configurations.First();
|
||||
var explorationInfo = new ExplorationInfo
|
||||
{
|
||||
ConfigurationGuid = JazzEntityFrameworkFactory.CurrentConfigurationGuid,
|
||||
ExclusionCriteria = new Biz.Exploration.Filters.ExclusionCriteria(),
|
||||
Filters = new Biz.Exploration.Filters.Filter
|
||||
{
|
||||
DischargeDateStart = new System.DateTime(2024, 1, 1),
|
||||
DischargeDateEnd = new System.DateTime(2024, 12, 31),
|
||||
FilterChipItems = new List<FilterChipItem>()
|
||||
}
|
||||
};
|
||||
var result = new List<CaseTypeFamilySummaryData>();
|
||||
if (configuration.ConfigurationGuid == configurationGuid)
|
||||
{
|
||||
Mock.Get(ConfigurationService)
|
||||
.Setup(s => s.GetById(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<Guid, CancellationToken>(
|
||||
(configurationGuid, token) => Task.FromResult(JazzDbContext.Configurations.First()));
|
||||
Mock.Get(ConfigurationService)
|
||||
.Setup(s => s.Contains(It.IsAny<Biz.Configuration.Configuration>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<Biz.Configuration.Configuration, CancellationToken>(
|
||||
(configuration, token) => Task.FromResult(true));
|
||||
Mock.Get(ConfigurationService)
|
||||
.Setup(s => s.IsConfigurationValid(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<Guid, CancellationToken>(
|
||||
(configurationGuid, token) => Task.FromResult(true));
|
||||
}
|
||||
else
|
||||
{
|
||||
Mock.Get(ConfigurationService)
|
||||
.Setup(s => s.GetById(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<Guid, CancellationToken>(
|
||||
(configurationGuid, token) => Task.FromResult(default(Strata.ContinuousImprovement.Biz.Configuration.Configuration)));
|
||||
Mock.Get(ConfigurationService)
|
||||
.Setup(s => s.Contains(It.IsAny<Biz.Configuration.Configuration>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<Biz.Configuration.Configuration, CancellationToken>(
|
||||
(configuration, token) => Task.FromResult(false));
|
||||
Mock.Get(ConfigurationService)
|
||||
.Setup(s => s.IsConfigurationValid(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<Guid, CancellationToken>(
|
||||
(configurationGuid, token) => Task.FromResult(false));
|
||||
}
|
||||
|
||||
Mock.Get(ExplorationService)
|
||||
.Setup(s => s.GetCaseTypeFamilySummariesAsync(It.IsAny<ExplorationInfo>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<ExplorationInfo, CancellationToken>(
|
||||
(explorationInfo, token) => Task.FromResult(result.AsEnumerable()));
|
||||
|
||||
// Act
|
||||
var controllerResponse = await ExplorationController.GetCaseTypeFamilySummaries(explorationInfo, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
controllerResponse.Should().NotBeNull();
|
||||
if (controllerResponse.Result is OkObjectResult okResult)
|
||||
{
|
||||
okResult.Should().NotBeNull();
|
||||
var value = okResult.Value as IEnumerable<CaseTypeFamilySummaryData>;
|
||||
value.Should().NotBeNull();
|
||||
}
|
||||
else
|
||||
{
|
||||
controllerResponse.Result.Should().BeOfType<BadRequestResult>();
|
||||
}
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(GetCaseTypeFamilyDetailsTestCases))]
|
||||
public async Task GetCaseTypeFamilyDetailsTest(Guid configurationGuid)
|
||||
{
|
||||
// Arrange
|
||||
var configuration = JazzDbContext.Configurations.First();
|
||||
var explorationInfo = new ExplorationDetailInfo
|
||||
{
|
||||
ConfigurationGuid = JazzEntityFrameworkFactory.CurrentConfigurationGuid,
|
||||
CaseTypeFamilyId = 0,
|
||||
ExclusionCriteria = new Biz.Exploration.Filters.ExclusionCriteria(),
|
||||
Filters = new Biz.Exploration.Filters.Filter
|
||||
{
|
||||
DischargeDateStart = new System.DateTime(2024, 1, 1),
|
||||
DischargeDateEnd = new System.DateTime(2024, 12, 31),
|
||||
FilterChipItems = new List<FilterChipItem>()
|
||||
}
|
||||
};
|
||||
var result = new CaseTypeFamilyDetailInfo
|
||||
{
|
||||
Metrics = new CaseTypeFamilyMetric(),
|
||||
CaseTypeFamilyDetails = Enumerable.Empty<CaseTypeFamilyDetailData>()
|
||||
};
|
||||
if (configuration.ConfigurationGuid == configurationGuid)
|
||||
{
|
||||
Mock.Get(ConfigurationService)
|
||||
.Setup(s => s.GetById(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<Guid, CancellationToken>(
|
||||
(configurationGuid, token) => Task.FromResult(JazzDbContext.Configurations.First()));
|
||||
Mock.Get(ConfigurationService)
|
||||
.Setup(s => s.Contains(It.IsAny<Biz.Configuration.Configuration>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<Biz.Configuration.Configuration, CancellationToken>(
|
||||
(configuration, token) => Task.FromResult(true));
|
||||
Mock.Get(ConfigurationService)
|
||||
.Setup(s => s.IsConfigurationValid(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<Guid, CancellationToken>(
|
||||
(configurationGuid, token) => Task.FromResult(true));
|
||||
}
|
||||
else
|
||||
{
|
||||
Mock.Get(ConfigurationService)
|
||||
.Setup(s => s.GetById(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<Guid, CancellationToken>(
|
||||
(configurationGuid, token) => Task.FromResult(default(Strata.ContinuousImprovement.Biz.Configuration.Configuration)));
|
||||
Mock.Get(ConfigurationService)
|
||||
.Setup(s => s.Contains(It.IsAny<Biz.Configuration.Configuration>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<Biz.Configuration.Configuration, CancellationToken>(
|
||||
(configuration, token) => Task.FromResult(false));
|
||||
Mock.Get(ConfigurationService)
|
||||
.Setup(s => s.IsConfigurationValid(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<Guid, CancellationToken>(
|
||||
(configurationGuid, token) => Task.FromResult(false));
|
||||
}
|
||||
Mock.Get(ExplorationService)
|
||||
.Setup(s => s.GetCaseTypeFamilyDetailsAsync(It.IsAny<ExplorationDetailInfo>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<ExplorationDetailInfo, CancellationToken>(
|
||||
(exploration, token) => Task.FromResult(result));
|
||||
|
||||
// Act
|
||||
var controllerResponse = await ExplorationController.GetCaseTypeFamilyDetails(explorationInfo, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
controllerResponse.Should().NotBeNull();
|
||||
if (controllerResponse.Result is OkObjectResult okResult)
|
||||
{
|
||||
okResult.Should().NotBeNull();
|
||||
okResult.Value.Should().BeOfType<CaseTypeFamilyDetailInfo>();
|
||||
configuration.ConfigurationGuid.Should().Be(configurationGuid);
|
||||
}
|
||||
else if (controllerResponse.Result is BadRequestResult badRequestResult)
|
||||
{
|
||||
badRequestResult.Should().NotBeNull();
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<TestCaseData> GetCaseTypeFamilySummariesTestCases()
|
||||
{
|
||||
var configurationGuid = JazzEntityFrameworkFactory.CurrentConfigurationGuid;
|
||||
|
||||
yield return new TestCaseData(configurationGuid)
|
||||
.SetName("summaries valid configuration");
|
||||
yield return new TestCaseData(Guid.NewGuid())
|
||||
.SetName("summaries invalid configuration");
|
||||
}
|
||||
|
||||
public static IEnumerable<TestCaseData> GetCaseTypeFamilyDetailsTestCases()
|
||||
{
|
||||
var configurationGuid = JazzEntityFrameworkFactory.CurrentConfigurationGuid;
|
||||
|
||||
yield return new TestCaseData(configurationGuid)
|
||||
.SetName("details valid configuration");
|
||||
yield return new TestCaseData(Guid.NewGuid())
|
||||
.SetName("details invalid configuration");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user