Template
296 lines
11 KiB
C#
296 lines
11 KiB
C#
using FluentAssertions;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Strata.ContinuousImprovement.Biz.Filter;
|
|
using Strata.ContinuousImprovement.Biz.Pagination;
|
|
using Strata.ContinuousImprovement.Biz.QualityVariation.Breakdowns;
|
|
using Strata.ContinuousImprovement.Biz.QualityVariation.Breakdowns.Filters;
|
|
using Strata.ContinuousImprovement.JazzEntityFrameworkStub;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Strata.ContinuousImprovement.Biz.Test.Unit.QualityVariation.Breakdowns
|
|
{
|
|
[TestFixture, Category("Unit")]
|
|
public class QVIBreakdownServiceTest
|
|
{
|
|
private Mock<IQVIBreakdownService> _qviBreakdownServiceMock;
|
|
|
|
[SetUp]
|
|
public void TestSetUp()
|
|
{
|
|
_qviBreakdownServiceMock = new Mock<IQVIBreakdownService>();
|
|
}
|
|
|
|
[TestCaseSource(nameof(GetFrameworkWithFilterData))]
|
|
public async Task TestGetPagedAsyncWithFramework(JazzEntityFrameworkFactory jazzEntityFrameworkFactory, QVIBreakdownFilters filters, CancellationToken cancellationToken)
|
|
{
|
|
// arrange
|
|
var qviBreakdownService = new QVIBreakdownService(jazzEntityFrameworkFactory, null, null);
|
|
|
|
try
|
|
{
|
|
// act
|
|
var taskResult = await qviBreakdownService
|
|
.GetPagedAsync(new PagingOptions(), filters, cancellationToken);
|
|
|
|
// assert
|
|
var result = taskResult.Data;
|
|
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName))
|
|
{
|
|
result.Should().BeNullOrEmpty();
|
|
return;
|
|
}
|
|
|
|
result.Should()
|
|
.NotBeNullOrEmpty()
|
|
.And.AllBeOfType<QVIBreakdown>();
|
|
|
|
if (filters.BreakdownIds.Any())
|
|
result.Should()
|
|
.Contain(vo => filters.BreakdownIds.Contains(vo.BreakdownId.ToString()));
|
|
}
|
|
catch (AssertionException)
|
|
{
|
|
// Intentionally left empty
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
e.Should().BeOfType<OperationCanceledException>();
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestFirstPage_Sorted_Asc()
|
|
{
|
|
// arrange
|
|
var qviBreakdownService = new QVIBreakdownService(new JazzEntityFrameworkFactory(), null, null);
|
|
var filters = new QVIBreakdownFilters()
|
|
{
|
|
IdentifiedSavings = 0,
|
|
BreakdownIds = new List<string>(),
|
|
ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345")
|
|
};
|
|
|
|
var pagingOptions = new PagingOptions() { SortField = "QVICasesTotal", SortOrder = SortOrder.Asc };
|
|
|
|
// act
|
|
var taskResult = await qviBreakdownService
|
|
.GetPagedAsync(pagingOptions, filters, CancellationToken.None);
|
|
|
|
// assert
|
|
taskResult.Data.Should().NotBeNullOrEmpty()
|
|
.And.AllBeOfType<QVIBreakdown>()
|
|
.And.HaveCountGreaterThan(1);
|
|
taskResult.Data.First().QVICasesTotal
|
|
.Should().BeLessThan(taskResult.Data.Last().QVICasesTotal);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestFirstPage_Sorted_Desc()
|
|
{
|
|
// arrange
|
|
var qviBreakdownService = new QVIBreakdownService(new JazzEntityFrameworkFactory(), null, null);
|
|
var filters = new QVIBreakdownFilters()
|
|
{
|
|
IdentifiedSavings = 0,
|
|
BreakdownIds = new List<string>(),
|
|
ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345")
|
|
};
|
|
|
|
var pagingOptions = new PagingOptions() { SortField = "QVICasesTotal", SortOrder = SortOrder.Desc };
|
|
|
|
// act
|
|
var taskResult = await qviBreakdownService
|
|
.GetPagedAsync(pagingOptions, filters, CancellationToken.None);
|
|
|
|
// assert
|
|
taskResult.Data.Should().NotBeNullOrEmpty()
|
|
.And.AllBeOfType<QVIBreakdown>()
|
|
.And.HaveCountGreaterThan(1);
|
|
taskResult.Data.First().QVICasesTotal
|
|
.Should().BeGreaterThan(taskResult.Data.Last().QVICasesTotal);
|
|
}
|
|
|
|
[TestCaseSource(nameof(GetFilterData))]
|
|
public void TestValidateFilters(QVIBreakdownFilters filters)
|
|
{
|
|
if (filters == null) return;
|
|
if (filters.BreakdownIds.Any())
|
|
filters.BreakdownIds.Should()
|
|
.AllBeOfType<string>()
|
|
.And.NotBeNullOrEmpty();
|
|
}
|
|
|
|
[TestCaseSource(typeof(JazzEntityFrameworkFactory), nameof(JazzEntityFrameworkFactory.GetFrameworksWithCancellation))]
|
|
public async Task TestGetFilterOptionsAsync(JazzEntityFrameworkFactory jazzEntityFrameworkFactory, CancellationToken cancellationToken)
|
|
{
|
|
// arrange
|
|
var qviBreakdownService = new QVIBreakdownService(jazzEntityFrameworkFactory, null, null);
|
|
|
|
try
|
|
{
|
|
// act
|
|
var taskResult = await qviBreakdownService
|
|
.GetFilterOptionsAsync(new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345"), cancellationToken);
|
|
|
|
// assert
|
|
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName))
|
|
{
|
|
taskResult.Should().BeNull();
|
|
return;
|
|
}
|
|
taskResult.Should()
|
|
.BeOfType<QVIBreakdownFilterOptions>()
|
|
.And.NotBeNull();
|
|
taskResult.Breakdowns.Should().AllBeOfType<FilterMember>().And.NotBeNullOrEmpty()
|
|
.And.NotContain(cd => string.IsNullOrEmpty(cd.Id))
|
|
.And.NotContain(cd => string.IsNullOrEmpty(cd.Text));
|
|
}
|
|
catch (NotImplementedException nie)
|
|
{
|
|
nie.Should().BeOfType<NotImplementedException>();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
e.Should().BeOfType<OperationCanceledException>();
|
|
}
|
|
}
|
|
|
|
#region JazzDbService Tests
|
|
|
|
[TestCaseSource(typeof(JazzEntityFrameworkFactory), nameof(JazzEntityFrameworkFactory.GetFrameworks))]
|
|
public async Task TestGetAllAsync(JazzEntityFrameworkFactory jazzEntityFrameworkFactory)
|
|
{
|
|
// arrange
|
|
var qviBreakdownService = new QVIBreakdownService(jazzEntityFrameworkFactory, null, null);
|
|
|
|
// act
|
|
var taskResult = await qviBreakdownService.GetAllAsync(CancellationToken.None);
|
|
|
|
// assert
|
|
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName))
|
|
{
|
|
taskResult.Should().BeNullOrEmpty();
|
|
}
|
|
else
|
|
{
|
|
taskResult.Should().NotBeNullOrEmpty();
|
|
}
|
|
}
|
|
|
|
[Test, Ignore("Broken due to removal of Key from VariationCaseType")]
|
|
public async Task TestGetAllAsync_Filtered()
|
|
{
|
|
// arrange
|
|
var factory = new JazzEntityFrameworkFactory();
|
|
var filters = factory.QVIOpportunities;
|
|
var qviBreakdownService = new QVIBreakdownService(factory, null, null);
|
|
|
|
// act
|
|
var taskResult = await qviBreakdownService.GetAllAsync(CancellationToken.None);
|
|
|
|
// assert
|
|
taskResult.Should().NotBeNullOrEmpty()
|
|
.And.AllBeOfType<QVIBreakdown>()
|
|
.And.HaveCountGreaterThan(0)
|
|
.And.NotContain(o => string.IsNullOrEmpty(o.ToString()))
|
|
.And.Contain(o => filters.Select(f => f.BreakdownName).Contains(o.BreakdownName))
|
|
.And.Contain(o => filters.Select(f => f.ConfigurationGuid).Contains(o.ConfigurationGuid));
|
|
}
|
|
|
|
[TestCaseSource(typeof(JazzEntityFrameworkFactory), nameof(JazzEntityFrameworkFactory.GetFrameworks)), Ignore("Complex key issue")]
|
|
public async Task TestGetById(JazzEntityFrameworkFactory jazzEntityFrameworkFactory)
|
|
{
|
|
// arrange
|
|
var qviBreakdownService = new QVIBreakdownService(jazzEntityFrameworkFactory, null, null);
|
|
var tempResult = await qviBreakdownService.GetAllAsync(CancellationToken.None);
|
|
|
|
// act
|
|
var taskResult =
|
|
await qviBreakdownService.GetById(tempResult.FirstOrDefault()?.BreakdownId ?? 1, CancellationToken.None);
|
|
|
|
// assert
|
|
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName))
|
|
{
|
|
taskResult.Should().BeNull();
|
|
}
|
|
else
|
|
{
|
|
taskResult.Should().NotBeNull()
|
|
.And.BeOfType<QVIBreakdown>();
|
|
}
|
|
|
|
}
|
|
|
|
[TestCaseSource(typeof(JazzEntityFrameworkFactory), nameof(JazzEntityFrameworkFactory.GetFrameworks)), Ignore("Complex key issue")]
|
|
public async Task TestGetByIds(JazzEntityFrameworkFactory jazzEntityFrameworkFactory)
|
|
{
|
|
// arrange
|
|
var qviBreakdownService = new QVIBreakdownService(jazzEntityFrameworkFactory, null, null);
|
|
var tempResult = await qviBreakdownService.GetAllAsync(CancellationToken.None);
|
|
var ids = tempResult.Select(o => o.BreakdownId);
|
|
|
|
// act
|
|
var taskResult = await qviBreakdownService.GetByIds(ids, CancellationToken.None);
|
|
|
|
// assert
|
|
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName))
|
|
{
|
|
taskResult.Should().BeNullOrEmpty();
|
|
}
|
|
else
|
|
{
|
|
taskResult.Should().NotBeNullOrEmpty()
|
|
.And.AllBeOfType<QVIBreakdown>();
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
[TearDown]
|
|
public void TestTearDown()
|
|
{
|
|
|
|
// Method intentionally left empty.
|
|
|
|
}
|
|
|
|
#region TestCaseData
|
|
|
|
public static IEnumerable<TestCaseData> GetFilterData()
|
|
{
|
|
yield return new TestCaseData(new QVIBreakdownFilters { ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") }).SetName("No Filters");
|
|
yield return new TestCaseData(new QVIBreakdownFilters { IdentifiedSavings = 1999, ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") }).SetName(
|
|
"By Identified Savings");
|
|
yield return new TestCaseData(new QVIBreakdownFilters { BreakdownIds = new[] { "1" }, ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") })
|
|
.SetName("By Breakdown");
|
|
}
|
|
|
|
public static IEnumerable<TestCaseData> GetFrameworkWithFilterData()
|
|
{
|
|
var testCases = GetFilterData().ToList();
|
|
var jeffs = JazzEntityFrameworkFactory.GetFrameworksWithCancellation()
|
|
.Select(tcd => tcd.Arguments);
|
|
foreach (var tcd in jeffs)
|
|
{
|
|
var jeff = (JazzEntityFrameworkFactory)tcd[0];
|
|
var ct = (CancellationToken)tcd[1];
|
|
foreach (var testCase in testCases)
|
|
{
|
|
yield return new TestCaseData(jeff, testCase.Arguments.GetValue(0), ct)
|
|
.SetName($"{testCase.TestName} {(string.IsNullOrEmpty(jeff.TestName) ? "w/o Jeff" : "w/Jeff")}")
|
|
.SetCategory(jeff.TestName);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|