Template
chore: deploy initial code base
This commit is contained in:
+291
@@ -0,0 +1,291 @@
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Strata.ContinuousImprovement.Biz.Filter;
|
||||
using Strata.ContinuousImprovement.Biz.Pagination;
|
||||
using Strata.ContinuousImprovement.Biz.QualityVariation.Events;
|
||||
using Strata.ContinuousImprovement.Biz.QualityVariation.Events.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.Events
|
||||
{
|
||||
[TestFixture, Category("Unit")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Minor Code Smell", "S101:Types should be named in PascalCase", Justification = "Standard abbreviation")]
|
||||
public class QVIEventServiceTest
|
||||
{
|
||||
private Mock<IQVIEventService> _qviEventSeriveMock;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetUp()
|
||||
{
|
||||
_qviEventSeriveMock = new Mock<IQVIEventService>();
|
||||
}
|
||||
|
||||
|
||||
[TestCaseSource(nameof(GetFrameworkWithFilterData))]
|
||||
public async Task TestGetPagedAsyncWithFramework(JazzEntityFrameworkFactory jazzEntityFrameworkFactory, QVIEventFilters filters, CancellationToken cancellationToken)
|
||||
{
|
||||
// arrange
|
||||
var qviEventService = new QVIEventService(jazzEntityFrameworkFactory, null, null);
|
||||
|
||||
try
|
||||
{
|
||||
// act
|
||||
var taskResult = await qviEventService.GetPagedAsync(new PagingOptions(), filters, cancellationToken);
|
||||
|
||||
// assert
|
||||
var result = taskResult.Data;
|
||||
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName))
|
||||
{
|
||||
result.Should().BeNullOrEmpty();
|
||||
return;
|
||||
}
|
||||
|
||||
result.Should().NotBeNullOrEmpty().And.AllBeOfType<QVIEvent>();
|
||||
|
||||
if (filters.QualityVariationEventIds.Any())
|
||||
result.Should()
|
||||
.Contain(vo => filters.QualityVariationEventIds.Contains(vo.QualityVariationEventName.ToString()));
|
||||
}
|
||||
catch (AssertionException)
|
||||
{
|
||||
// Intentionally left empty
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.Should().BeOfType<OperationCanceledException>();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestFirstPage_Sorted_Asc()
|
||||
{
|
||||
// arrange
|
||||
var qviEventService = new QVIEventService(new JazzEntityFrameworkFactory(), null, null);
|
||||
var filters = new QVIEventFilters()
|
||||
{
|
||||
QualityVariationEventIds = new List<string>(),
|
||||
IdentifiedSavings = 0,
|
||||
QVICases = 0,
|
||||
ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345")
|
||||
};
|
||||
|
||||
var pagingOptions = new PagingOptions() { SortField = "QVICasesTotal", SortOrder = SortOrder.Asc };
|
||||
|
||||
// act
|
||||
var taskResult = await qviEventService.GetPagedAsync(pagingOptions, filters, CancellationToken.None);
|
||||
|
||||
// assert
|
||||
taskResult.Data.Should().NotBeNullOrEmpty()
|
||||
.And.AllBeOfType<QVIEvent>()
|
||||
.And.HaveCountGreaterThan(1);
|
||||
taskResult.Data.First().QVICasesTotal.Should().BeLessThan(taskResult.Data.Last().QVICasesTotal);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestFirstPage_Sorted_Desc()
|
||||
{
|
||||
// arrange
|
||||
var qviEventService = new QVIEventService(new JazzEntityFrameworkFactory(), null, null);
|
||||
var filters = new QVIEventFilters()
|
||||
{
|
||||
QualityVariationEventIds = new List<string>(),
|
||||
IdentifiedSavings = 0,
|
||||
QVICases = 0,
|
||||
ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345")
|
||||
};
|
||||
|
||||
var pagingOptions = new PagingOptions() { SortField = "QVICasesTotal", SortOrder = SortOrder.Desc };
|
||||
|
||||
// act
|
||||
var taskResult = await qviEventService
|
||||
.GetPagedAsync(pagingOptions, filters, CancellationToken.None);
|
||||
|
||||
// assert
|
||||
taskResult.Data.Should().NotBeNullOrEmpty()
|
||||
.And.AllBeOfType<QVIEvent>()
|
||||
.And.HaveCountGreaterThan(1);
|
||||
taskResult.Data.First().QVICasesTotal.Should().BeGreaterThan(taskResult.Data.Last().QVICasesTotal);
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(GetFilterData))]
|
||||
public void TestValidateFilters(QVIEventFilters filters)
|
||||
{
|
||||
if (filters == null) return;
|
||||
if (filters.QualityVariationEventIds.Any())
|
||||
filters.QualityVariationEventIds.Should()
|
||||
.AllBeOfType<string>()
|
||||
.And.NotBeNullOrEmpty();
|
||||
}
|
||||
|
||||
[TestCaseSource(typeof(JazzEntityFrameworkFactory), nameof(JazzEntityFrameworkFactory.GetFrameworksWithCancellation))]
|
||||
public async Task TestGetFilterOptionsAsync(JazzEntityFrameworkFactory jazzEntityFrameworkFactory, CancellationToken cancellationToken)
|
||||
{
|
||||
// arrange
|
||||
var qviEventService = new QVIEventService(jazzEntityFrameworkFactory, null, null);
|
||||
|
||||
try
|
||||
{
|
||||
// act
|
||||
var taskResult = await qviEventService
|
||||
.GetFilterOptionsAsync(new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345"), cancellationToken);
|
||||
|
||||
// assert
|
||||
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName))
|
||||
{
|
||||
taskResult.Should().BeNull();
|
||||
return;
|
||||
}
|
||||
taskResult.Should().BeOfType<QVIEventFilterOptions>().And.NotBeNull();
|
||||
taskResult.QualityVariationEvents.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 qviEventService = new QVIEventService(jazzEntityFrameworkFactory, null, null);
|
||||
|
||||
// act
|
||||
var taskResult = await qviEventService.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 qviEventService = new QVIEventService(factory, null, null);
|
||||
|
||||
// act
|
||||
var taskResult = await qviEventService.GetAllAsync(CancellationToken.None);
|
||||
|
||||
// assert
|
||||
taskResult.Should().NotBeNullOrEmpty()
|
||||
.And.AllBeOfType<QVIEvent>()
|
||||
.And.HaveCountGreaterThan(0)
|
||||
.And.NotContain(o => string.IsNullOrEmpty(o.ToString()))
|
||||
.And.Contain(o => filters.Select(f => f.QualityVariationEventName).Contains(o.QualityVariationEventName))
|
||||
.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 qviEventService = new QVIEventService(jazzEntityFrameworkFactory, null, null);
|
||||
var tempResult = await qviEventService.GetAllAsync(CancellationToken.None);
|
||||
|
||||
// act
|
||||
var taskResult =
|
||||
await qviEventService.GetById(tempResult.FirstOrDefault()?.QualityVariationEventId ?? 1, CancellationToken.None);
|
||||
|
||||
// assert
|
||||
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName))
|
||||
{
|
||||
taskResult.Should().BeNull();
|
||||
}
|
||||
else
|
||||
{
|
||||
taskResult.Should().NotBeNull()
|
||||
.And.BeOfType<QVIEvent>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[TestCaseSource(typeof(JazzEntityFrameworkFactory), nameof(JazzEntityFrameworkFactory.GetFrameworks)), Ignore("Complex key issue")]
|
||||
public async Task TestGetByIds(JazzEntityFrameworkFactory jazzEntityFrameworkFactory)
|
||||
{
|
||||
// arrange
|
||||
var qviEventService = new QVIEventService(jazzEntityFrameworkFactory, null, null);
|
||||
var tempResult = await qviEventService.GetAllAsync(CancellationToken.None);
|
||||
var ids = tempResult.Select(o => o.QualityVariationEventId);
|
||||
|
||||
// act
|
||||
var taskResult = await qviEventService.GetByIds(ids, CancellationToken.None);
|
||||
|
||||
// assert
|
||||
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName))
|
||||
{
|
||||
taskResult.Should().BeNullOrEmpty();
|
||||
}
|
||||
else
|
||||
{
|
||||
taskResult.Should().NotBeNullOrEmpty()
|
||||
.And.AllBeOfType<QVIEvent>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[TearDown]
|
||||
public void TestTearDown()
|
||||
{
|
||||
// Method intentionally left empty.
|
||||
|
||||
}
|
||||
|
||||
#region TestCaseData
|
||||
|
||||
public static IEnumerable<TestCaseData> GetFilterData()
|
||||
{
|
||||
yield return new TestCaseData(new QVIEventFilters { ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") }).SetName("No Filters");
|
||||
yield return new TestCaseData(new QVIEventFilters { IdentifiedSavings = 1999, ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") }).SetName(
|
||||
"By Identified Savings");
|
||||
yield return new TestCaseData(new QVIEventFilters { QualityVariationEventIds = new[] { "1" }, ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") })
|
||||
.SetName("By Event ID");
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user