Template
chore: deploy initial code base
This commit is contained in:
+672
@@ -0,0 +1,672 @@
|
||||
using ClosedXML.Excel;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Strata.ContinuousImprovement.Biz.DbContexts;
|
||||
using Strata.ContinuousImprovement.Biz.Filter;
|
||||
using Strata.ContinuousImprovement.Biz.Generics;
|
||||
using Strata.ContinuousImprovement.Biz.Initiatives;
|
||||
using Strata.ContinuousImprovement.Biz.Pagination;
|
||||
using Strata.ContinuousImprovement.Biz.Test.Unit.Utilities;
|
||||
using Strata.ContinuousImprovement.Biz.UtilizationVariation.Opportunities;
|
||||
using Strata.ContinuousImprovement.Biz.UtilizationVariation.Opportunities.Filters;
|
||||
using Strata.ContinuousImprovement.JazzEntityFrameworkStub;
|
||||
using Strata.SqlTools.Configuration.Common.AsyncFactory;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Strata.ContinuousImprovement.Biz.Test.Unit.UtilizationVariation.Opportunities
|
||||
{
|
||||
[TestFixture, Category("Unit")]
|
||||
public class UVOpportunityServiceTest
|
||||
{
|
||||
|
||||
private Mock<IUVOpportunityService> _variationOpportunityServiceMock;
|
||||
private Mock<IAsyncDbContextFactory<JazzDbContext>> _dbContextFactoryMock;
|
||||
private Mock<IJazzDbContext> _jazzDbContextMock;
|
||||
private IInitiativeService _initiativeService;
|
||||
private IUpdateFactOpportunitySavingsService _updateFactOpportunitySavingsService;
|
||||
private static readonly ResourceFileExtractor _extractor = new ResourceFileExtractor(".Resource.");
|
||||
|
||||
[SetUp]
|
||||
public void TestSetUp()
|
||||
{
|
||||
_variationOpportunityServiceMock = new Mock<IUVOpportunityService>();
|
||||
_dbContextFactoryMock = new Mock<IAsyncDbContextFactory<JazzDbContext>>();
|
||||
_jazzDbContextMock = new Mock<IJazzDbContext>();
|
||||
_initiativeService = Mock.Of<IInitiativeService>();
|
||||
_updateFactOpportunitySavingsService = Mock.Of<IUpdateFactOpportunitySavingsService>();
|
||||
Mock.Get(_initiativeService)
|
||||
.Setup(s => s.DeleteAsync(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(Task.FromResult(true));
|
||||
Mock.Get(_updateFactOpportunitySavingsService)
|
||||
.Setup(s => s.UpdateFactOpportunitySavings(It.IsAny<CancellationToken>()));
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(GetFrameworkWithFilterData))]
|
||||
public async Task TestGetPagedAsyncWithFramework(JazzEntityFrameworkFactory jazzEntityFrameworkFactory, UVFilters filters, CancellationToken cancellationToken)
|
||||
{
|
||||
// arrange
|
||||
var variationOpportunityService = new UVOpportunityService(jazzEntityFrameworkFactory, null, null, _initiativeService, _updateFactOpportunitySavingsService);
|
||||
|
||||
try
|
||||
{
|
||||
// act
|
||||
var taskResult = await variationOpportunityService
|
||||
.GetPagedAsync(new PagingOptions(), filters, cancellationToken);
|
||||
|
||||
// assert
|
||||
var result = taskResult.Data;
|
||||
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName))
|
||||
{
|
||||
result.Should().BeNullOrEmpty();
|
||||
return;
|
||||
}
|
||||
result.Should()
|
||||
.NotBeNullOrEmpty()
|
||||
.And.AllBeOfType<UVOpportunity>();
|
||||
|
||||
if (filters.CaseTypeGuids.Any())
|
||||
result.Should()
|
||||
.Contain(vo => filters.CaseTypeGuids.Contains(vo.CaseTypeGuid));
|
||||
if (filters.EntityIds.Any())
|
||||
result.Should()
|
||||
.Contain(vo => filters.EntityIds.Contains(vo.EntityId.ToString()));
|
||||
if (filters.ServiceLineIds.Any())
|
||||
result.Should()
|
||||
.Contain(vo => filters.ServiceLineIds.Contains(vo.ServiceLineId.ToString()));
|
||||
if (filters.CostDrivers.Any())
|
||||
result.Should()
|
||||
.Contain(vo => filters.CostDrivers.Contains(vo.CostDriver));
|
||||
if (filters.ExcludeInitiatives)␍
|
||||
{
|
||||
result.ToList().ForEach(opportunity => opportunity.HasInitiative.Should().Be(false));␍
|
||||
}
|
||||
if (!string.IsNullOrEmpty(filters.OpportunitySearch))
|
||||
result.Should()
|
||||
.Contain(vo => vo.OpportunityKey.Contains(filters.OpportunitySearch));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.Should().BeOfType<OperationCanceledException>();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestFirstPage_Sorted_Asc()
|
||||
{
|
||||
// arrange
|
||||
var variationOpportunityService = new UVOpportunityService(new JazzEntityFrameworkFactory(), null, null, _initiativeService, _updateFactOpportunitySavingsService);
|
||||
var filters = new UVFilters()
|
||||
{
|
||||
CaseTypeGuids = new List<Guid>(),
|
||||
CostDrivers = new List<string>(),
|
||||
EntityIds = new List<string>(),
|
||||
IdentifiedSavings = 0,
|
||||
ServiceLineIds = new List<string>(),
|
||||
ViewVisible = true,
|
||||
ExcludeInitiatives = false,
|
||||
OpportunitySearch = "",␍
|
||||
ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345")
|
||||
};
|
||||
|
||||
var pagingOptions = new PagingOptions() { SortField = "Cases", SortOrder = SortOrder.Asc };
|
||||
|
||||
// act
|
||||
var taskResult = await variationOpportunityService
|
||||
.GetPagedAsync(pagingOptions, filters, CancellationToken.None);
|
||||
|
||||
// assert
|
||||
taskResult.Data.Should().NotBeNullOrEmpty()
|
||||
.And.AllBeOfType<UVOpportunity>()
|
||||
.And.HaveCountGreaterThan(1);
|
||||
taskResult.Data.First().Cases
|
||||
.Should().BeLessThan(taskResult.Data.Last().Cases);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestFirstPage_Sorted_Desc()
|
||||
{
|
||||
// arrange
|
||||
var variationOpportunityService = new UVOpportunityService(new JazzEntityFrameworkFactory(), null, null, _initiativeService, _updateFactOpportunitySavingsService);
|
||||
var filters = new UVFilters()
|
||||
{
|
||||
CaseTypeGuids = new List<Guid>(),
|
||||
CostDrivers = new List<string>(),
|
||||
EntityIds = new List<string>(),
|
||||
IdentifiedSavings = 0,
|
||||
ServiceLineIds = new List<string>(),
|
||||
ViewVisible = true,
|
||||
ExcludeInitiatives = false,
|
||||
OpportunitySearch = "",␍
|
||||
ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345")
|
||||
};
|
||||
|
||||
var pagingOptions = new PagingOptions() { SortField = "Cases", SortOrder = SortOrder.Desc };
|
||||
|
||||
// act
|
||||
var taskResult = await variationOpportunityService
|
||||
.GetPagedAsync(pagingOptions, filters, CancellationToken.None);
|
||||
|
||||
// assert
|
||||
taskResult.Data.Should().NotBeNullOrEmpty()
|
||||
.And.AllBeOfType<UVOpportunity>()
|
||||
.And.HaveCountGreaterThan(1);
|
||||
taskResult.Data.First().Cases
|
||||
.Should().BeGreaterThan(taskResult.Data.Last().Cases);
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(GetFilterData))]
|
||||
public void TestValidateFilters(UVFilters filters)
|
||||
{
|
||||
if (filters == null) return;
|
||||
if (filters.CaseTypeGuids.Any())
|
||||
filters.CaseTypeGuids.Should()
|
||||
.AllBeOfType<Guid>()
|
||||
.And.NotBeEmpty();
|
||||
if (filters.EntityIds.Any())
|
||||
filters.EntityIds.Should()
|
||||
.AllBeOfType<string>();
|
||||
if (filters.ServiceLineIds.Any())
|
||||
filters.ServiceLineIds.Should()
|
||||
.AllBeOfType<string>();
|
||||
if (filters.CostDrivers.Any())
|
||||
filters.CostDrivers.Should()
|
||||
.AllBeOfType<string>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetExcelWorkbook()
|
||||
{
|
||||
// arrange
|
||||
var framework = new JazzEntityFrameworkFactory();
|
||||
await framework.CreateDbContextAsync(CancellationToken.None);
|
||||
var caseTypeGuid = framework.UVOpportunities.First().CaseTypeGuid;
|
||||
var costDriver = framework.UVOpportunities.First().CostDriver;
|
||||
var entityId = framework.UVOpportunities[1].EntityId;
|
||||
var filters = new UVFilters()
|
||||
{
|
||||
ConfigurationGuid = framework.Configurations.First().ConfigurationGuid,
|
||||
CaseTypeGuids = new[] { caseTypeGuid },
|
||||
CostDrivers = new[] { costDriver },
|
||||
EntityIds = entityId.Split(',', StringSplitOptions.TrimEntries).ToList()
|
||||
};
|
||||
var service = new UVOpportunityService(framework, null, null, _initiativeService, _updateFactOpportunitySavingsService);
|
||||
|
||||
// act
|
||||
var wb = await service.ExportAsync(new SortOptions(), filters, CancellationToken.None);
|
||||
#pragma warning disable S125 // Sections of code should not be commented out
|
||||
//wb.SaveAs(System.IO.Path.Combine(@"C:\Git\continuousimprovement\tests\Strata.ContinuousImprovement.Biz.Test.Unit\Resource", "ExcelFilter.xlsx"));
|
||||
#pragma warning restore S125 // Sections of code should not be commented out
|
||||
|
||||
// assert
|
||||
wb.Worksheets.Should().HaveCount(1);
|
||||
var ws = wb.Worksheet(1);
|
||||
ws.Should().NotBeNull();
|
||||
|
||||
var expected = @"Examples.VariationOpportunity.ExcelFilter.xlsx";
|
||||
using (var expectedStream = _extractor.ReadFileFromResourceToStream(expected))
|
||||
using (var actualStream = new MemoryStream())
|
||||
{
|
||||
wb.SaveAs(actualStream);
|
||||
actualStream.Compare(expectedStream, out var message).Should().BeTrue(message);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetExcelWorkbookNullFilter()
|
||||
{
|
||||
// arrange
|
||||
var framework = new JazzEntityFrameworkFactory();
|
||||
await framework.CreateDbContextAsync(CancellationToken.None);
|
||||
|
||||
var service = new UVOpportunityService(framework, null, null, _initiativeService, _updateFactOpportunitySavingsService);
|
||||
|
||||
// act
|
||||
var wb = await service.ExportAsync(null, null, CancellationToken.None);
|
||||
#pragma warning disable S125 // Sections of code should not be commented out
|
||||
//wb.SaveAs(System.IO.Path.Combine(@"C:\Git\continuousimprovement\tests\Strata.ContinuousImprovement.Biz.Test.Unit\Resource", "ExcelNullFilter.xlsx"));
|
||||
#pragma warning restore S125 // Sections of code should not be commented out
|
||||
|
||||
// assert
|
||||
wb.Worksheets.Should().HaveCount(1);
|
||||
var ws = wb.Worksheet(1);
|
||||
ws.Should().NotBeNull();
|
||||
|
||||
var expected = @"Examples.VariationOpportunity.ExcelNullFilter.xlsx";
|
||||
using (var expectedStream = _extractor.ReadFileFromResourceToStream(expected))
|
||||
using (var actualStream = new MemoryStream())
|
||||
{
|
||||
wb.SaveAs(actualStream);
|
||||
actualStream.Compare(expectedStream, out var message).Should().BeTrue(message);
|
||||
}
|
||||
}
|
||||
|
||||
[TestCaseSource(typeof(JazzEntityFrameworkFactory), nameof(JazzEntityFrameworkFactory.GetFrameworksWithCancellation))]
|
||||
public async Task TestGetExcelWorkbookWithFramework(JazzEntityFrameworkFactory jazzEntityFrameworkFactory, CancellationToken cancellationToken)
|
||||
{
|
||||
// arrange
|
||||
var variationOpportunityService = new UVOpportunityService(jazzEntityFrameworkFactory, null, null, _initiativeService, _updateFactOpportunitySavingsService);
|
||||
var filters = new UVFilters()
|
||||
{
|
||||
CaseTypeGuids = new List<Guid>(),
|
||||
CostDrivers = new List<string>(),
|
||||
EntityIds = new List<string>(),
|
||||
IdentifiedSavings = 0,
|
||||
ServiceLineIds = new List<string>(),
|
||||
ViewVisible = true,
|
||||
ExcludeInitiatives = false,
|
||||
OpportunitySearch = "",
|
||||
ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345")
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
// act
|
||||
var taskResult =
|
||||
await variationOpportunityService.ExportAsync(new SortOptions(), filters, cancellationToken);
|
||||
|
||||
// assert
|
||||
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName))
|
||||
{
|
||||
taskResult.Should().BeNull();
|
||||
}
|
||||
else
|
||||
{
|
||||
taskResult.Should().NotBeNull()
|
||||
.And.BeOfType<XLWorkbook>();
|
||||
var wb = taskResult;
|
||||
wb.Worksheets.Should().HaveCountGreaterThan(0);
|
||||
var ws = wb.Worksheet("Sheet1");
|
||||
ws.ColumnCount().Should().BeGreaterThan(0);
|
||||
ws.RowCount().Should().BeGreaterThan(0);
|
||||
}
|
||||
}
|
||||
catch (TypeInitializationException tie)
|
||||
{
|
||||
tie.Should().BeOfType<TypeInitializationException>();
|
||||
}
|
||||
catch (AssertionException ae)
|
||||
{
|
||||
ae.Should().BeOfType<AssertionException>();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.Should().BeOfType<OperationCanceledException>();
|
||||
}
|
||||
}
|
||||
|
||||
[TestCaseSource(typeof(JazzEntityFrameworkFactory), nameof(JazzEntityFrameworkFactory.GetFrameworksWithCancellation))]
|
||||
public async Task TestGetFilterOptionsAsync(JazzEntityFrameworkFactory jazzEntityFrameworkFactory, CancellationToken cancellationToken)
|
||||
{
|
||||
// arrange
|
||||
var variationOpportunityService = new UVOpportunityService(jazzEntityFrameworkFactory, null, null, _initiativeService, _updateFactOpportunitySavingsService);
|
||||
|
||||
try
|
||||
{
|
||||
// act
|
||||
var taskResult = await variationOpportunityService
|
||||
.GetFilterOptionsAsync(new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345"), cancellationToken);
|
||||
|
||||
// assert
|
||||
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName))
|
||||
{
|
||||
taskResult.Should().BeNull();
|
||||
return;
|
||||
}
|
||||
taskResult.Should()
|
||||
.BeOfType<UVFilterOptions>()
|
||||
.And.NotBeNull();
|
||||
taskResult.CostDrivers.Should().AllBeOfType<FilterMember>().And.NotBeNullOrEmpty()
|
||||
.And.NotContain(cd => string.IsNullOrEmpty(cd.Id))
|
||||
.And.NotContain(cd => string.IsNullOrEmpty(cd.Text));
|
||||
taskResult.CaseTypes.Should().AllBeOfType<FilterMember>().And.NotBeNullOrEmpty();
|
||||
taskResult.Entities.Should().AllBeOfType<FilterMember>().And.NotBeNullOrEmpty();
|
||||
taskResult.ServiceLines.Should().AllBeOfType<FilterMember>().And.NotBeNullOrEmpty();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.Should().BeOfType<OperationCanceledException>();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestSetHidden()
|
||||
{
|
||||
// arrange
|
||||
var framework = new JazzEntityFrameworkFactory();
|
||||
await framework.CreateDbContextAsync(CancellationToken.None);
|
||||
var variationOpportunity = framework.UVOpportunities.First(vo => !vo.IsHidden);
|
||||
var explorationOpportunity = framework.UVOpportunities.Last();
|
||||
var isVariationHidden = variationOpportunity.IsHidden;
|
||||
var isExplorationHidden = explorationOpportunity.IsHidden;
|
||||
var service = new UVOpportunityService(framework, null, null, _initiativeService, _updateFactOpportunitySavingsService);
|
||||
|
||||
// act
|
||||
await service.SetHiddenAsync(variationOpportunity.OpportunityGuid, !isVariationHidden, CancellationToken.None);
|
||||
await service.SetHiddenAsync(explorationOpportunity.OpportunityGuid, !isExplorationHidden, CancellationToken.None);
|
||||
|
||||
// assert
|
||||
var dbContextUpdated = await framework.CreateDbContextAsync(CancellationToken.None);
|
||||
var resultUV = dbContextUpdated.UtilizationVariationOpportunitiesData.SingleOrDefault(opp => opp.OpportunityGuid == variationOpportunity.OpportunityGuid);
|
||||
var resultFE = dbContextUpdated.ExplorationVariationOpportunitiesData.SingleOrDefault(opp => opp.OpportunityGuid == explorationOpportunity.OpportunityGuid);
|
||||
resultUV.IsHidden.Should().Be(!isVariationHidden);
|
||||
resultFE.IsHidden.Should().Be(!isExplorationHidden);
|
||||
}
|
||||
|
||||
[TestCaseSource(typeof(JazzEntityFrameworkFactory), nameof(JazzEntityFrameworkFactory.GetFrameworksWithCancellation))]
|
||||
public async Task TestSetHiddenAsync(JazzEntityFrameworkFactory jazzEntityFrameworkFactory, CancellationToken cancellationToken)
|
||||
{
|
||||
// arrange
|
||||
var variationOpportunityService = new UVOpportunityService(jazzEntityFrameworkFactory, null, null, _initiativeService, _updateFactOpportunitySavingsService);
|
||||
try
|
||||
{
|
||||
var opportunities = variationOpportunityService.GetAllAsync(cancellationToken).Result;
|
||||
var opportunity = opportunities.FirstOrDefault(o => o.IsHidden);
|
||||
if (opportunity == null) return;
|
||||
var isHidden = opportunity.IsHidden;␍
|
||||
␍
|
||||
//act␍
|
||||
await variationOpportunityService.SetHiddenAsync(opportunity.OpportunityGuid, !isHidden,␍
|
||||
cancellationToken);␍
|
||||
␍
|
||||
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName)) return;␍
|
||||
var result = variationOpportunityService.GetById(opportunity.OpportunityGuid, cancellationToken).Result;␍
|
||||
result.IsHidden.Should().Be(!isHidden);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
switch (e.GetType().Name)
|
||||
{
|
||||
case "AggregateException":
|
||||
case "OperationCanceledException":
|
||||
return;
|
||||
}
|
||||
e.Should().NotBeOfType<Exception>();
|
||||
}
|
||||
}
|
||||
|
||||
[TestCaseSource(typeof(JazzEntityFrameworkFactory), nameof(JazzEntityFrameworkFactory.GetFrameworksWithCancellation))]
|
||||
public async Task TestSetHiddenAsync_NoOpportunity(JazzEntityFrameworkFactory jazzEntityFrameworkFactory, CancellationToken cancellationToken)
|
||||
{
|
||||
// arrange
|
||||
var opportunity = jazzEntityFrameworkFactory.UVOpportunities.FirstOrDefault(o => o.IsHidden);
|
||||
if (opportunity == null) return;
|
||||
var isHidden = opportunity.IsHidden;
|
||||
var variationOpportunityService = new UVOpportunityService(jazzEntityFrameworkFactory, null, null, _initiativeService, _updateFactOpportunitySavingsService);
|
||||
|
||||
try
|
||||
{
|
||||
// act
|
||||
await variationOpportunityService.SetHiddenAsync(Guid.Empty, !isHidden,
|
||||
cancellationToken);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.Should().BeOfType<OperationCanceledException>();
|
||||
}
|
||||
}
|
||||
|
||||
[TestCaseSource(typeof(JazzEntityFrameworkFactory), nameof(JazzEntityFrameworkFactory.GetFrameworksWithCancellation))]
|
||||
public async Task TestSetNoteAsync(JazzEntityFrameworkFactory jazzEntityFrameworkFactory, CancellationToken cancellationToken)
|
||||
{
|
||||
// arrange
|
||||
var variationOpportunityService = new UVOpportunityService(jazzEntityFrameworkFactory, null, null, _initiativeService, _updateFactOpportunitySavingsService);
|
||||
try
|
||||
{
|
||||
var opportunities = variationOpportunityService.GetAllAsync(cancellationToken).Result;
|
||||
|
||||
var opportunity = opportunities.FirstOrDefault(o => o.Note == string.Empty);
|
||||
|
||||
if (opportunity == null) return;
|
||||
|
||||
var note = "new test note";
|
||||
// act
|
||||
await variationOpportunityService.SetNoteAsync(opportunity.OpportunityGuid, note,
|
||||
CancellationToken.None);
|
||||
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName)) return;
|
||||
var result = variationOpportunityService.GetById(opportunity.OpportunityGuid, cancellationToken).Result;
|
||||
result.Note.Should().Be(note);
|
||||
|
||||
// assert
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
switch (e.GetType().Name)
|
||||
{
|
||||
case "AggregateException":
|
||||
case "OperationCanceledException":
|
||||
return;
|
||||
}
|
||||
e.Should().NotBeOfType<Exception>();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestSetNote()
|
||||
{
|
||||
// arrange
|
||||
var framework = new JazzEntityFrameworkFactory();
|
||||
await framework.CreateDbContextAsync(CancellationToken.None);
|
||||
var variationOpportunity = framework.UVOpportunities.First(vo => string.IsNullOrEmpty(vo.Note));
|
||||
var explorationOpportunity = framework.UVOpportunities[5];
|
||||
var variationNote = variationOpportunity.Note;
|
||||
var explorationNote = explorationOpportunity.Note;
|
||||
var expected = "Now is the time for all good engineers to write great code!";
|
||||
var service = new UVOpportunityService(framework, null, null, _initiativeService, _updateFactOpportunitySavingsService);
|
||||
|
||||
// act
|
||||
await service.SetNoteAsync(variationOpportunity.OpportunityGuid, expected, CancellationToken.None);
|
||||
await service.SetNoteAsync(explorationOpportunity.OpportunityGuid, expected, CancellationToken.None);
|
||||
|
||||
// assert
|
||||
var dbContextUpdated = await framework.CreateDbContextAsync(CancellationToken.None);
|
||||
|
||||
var resultUV = dbContextUpdated.UtilizationVariationOpportunitiesData.SingleOrDefault(opp => opp.OpportunityGuid == variationOpportunity.OpportunityGuid);
|
||||
var resultFE = dbContextUpdated.ExplorationVariationOpportunitiesData.SingleOrDefault(opp => opp.OpportunityGuid == explorationOpportunity.OpportunityGuid);
|
||||
|
||||
|
||||
resultUV.Note.Should().NotBeNullOrEmpty()
|
||||
.And.NotBe(variationNote)
|
||||
.And.Be(expected);
|
||||
resultFE.Note.Should().NotBeNullOrEmpty()
|
||||
.And.NotBe(explorationNote)
|
||||
.And.Be(expected);
|
||||
}
|
||||
|
||||
[TestCaseSource(typeof(JazzEntityFrameworkFactory), nameof(JazzEntityFrameworkFactory.GetFrameworksWithCancellation))]
|
||||
public async Task TestSetNoteAsync_NoOpportunity(JazzEntityFrameworkFactory jazzEntityFrameworkFactory, CancellationToken cancellationToken)
|
||||
{
|
||||
// arrange
|
||||
var opportunity = jazzEntityFrameworkFactory.UVOpportunities.FirstOrDefault(o => o.Note == string.Empty);
|
||||
if (opportunity == null) return;
|
||||
var note = "new test note";
|
||||
var variationOpportunityService = new UVOpportunityService(jazzEntityFrameworkFactory, null, null, _initiativeService, _updateFactOpportunitySavingsService);
|
||||
|
||||
try
|
||||
{
|
||||
// act
|
||||
await variationOpportunityService.SetNoteAsync(Guid.Empty, note, cancellationToken);
|
||||
|
||||
// assert
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.Should().BeOfType<OperationCanceledException>();
|
||||
}
|
||||
}
|
||||
|
||||
#region JazzDbService Tests
|
||||
|
||||
[TestCaseSource(typeof(JazzEntityFrameworkFactory), nameof(JazzEntityFrameworkFactory.GetFrameworks))]
|
||||
public async Task TestGetAllAsync(JazzEntityFrameworkFactory jazzEntityFrameworkFactory)
|
||||
{
|
||||
// arrange
|
||||
var variationOpportunityService = new UVOpportunityService(jazzEntityFrameworkFactory, null, null, _initiativeService, _updateFactOpportunitySavingsService);
|
||||
|
||||
// act
|
||||
var taskResult = await variationOpportunityService.GetAllAsync(CancellationToken.None);
|
||||
|
||||
// assert
|
||||
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName))
|
||||
{
|
||||
taskResult.Should().BeNullOrEmpty();
|
||||
}
|
||||
else
|
||||
{
|
||||
taskResult.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestGetAllAsync_Filtered()
|
||||
{
|
||||
// arrange
|
||||
var factory = new JazzEntityFrameworkFactory();
|
||||
var filters = factory.UVOpportunities;
|
||||
var variationOpportunityService = new UVOpportunityService(factory, null, null, _initiativeService, _updateFactOpportunitySavingsService);
|
||||
|
||||
// act
|
||||
var taskResult = await variationOpportunityService.GetAllAsync(CancellationToken.None);
|
||||
|
||||
// assert
|
||||
taskResult.Should().NotBeNullOrEmpty()
|
||||
.And.AllBeOfType<UVOpportunity>()
|
||||
.And.HaveCountGreaterThan(0)
|
||||
.And.NotContain(o => string.IsNullOrEmpty(o.ToString()))
|
||||
.And.Contain(o => filters.Select(f => f.OpportunityGuid).Contains(o.OpportunityGuid))
|
||||
.And.Contain(o => filters.Select(f => f.CostDriver).Contains(o.CostDriver))
|
||||
.And.Contain(o => filters.Select(f => f.ServiceLineName).Contains(o.ServiceLineName))
|
||||
.And.Contain(o => filters.Select(f => f.ConfigurationGuid).Contains(o.ConfigurationGuid));
|
||||
}
|
||||
|
||||
[TestCaseSource(typeof(JazzEntityFrameworkFactory), nameof(JazzEntityFrameworkFactory.GetFrameworks))]
|
||||
public async Task TestGetById(JazzEntityFrameworkFactory jazzEntityFrameworkFactory)
|
||||
{
|
||||
// arrange
|
||||
var variationOpportunityService = new UVOpportunityService(jazzEntityFrameworkFactory, null, null, _initiativeService, _updateFactOpportunitySavingsService);
|
||||
|
||||
// act
|
||||
var tempResult = await variationOpportunityService.GetAllAsync(CancellationToken.None);
|
||||
var taskResult =
|
||||
await variationOpportunityService.GetById(tempResult.FirstOrDefault()?.OpportunityGuid ?? Guid.Empty, CancellationToken.None);
|
||||
|
||||
// assert
|
||||
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName))
|
||||
{
|
||||
taskResult.Should().BeNull();
|
||||
}
|
||||
else
|
||||
{
|
||||
taskResult.Should().NotBeNull()
|
||||
.And.BeOfType<UVOpportunity>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[TestCaseSource(typeof(JazzEntityFrameworkFactory), nameof(JazzEntityFrameworkFactory.GetFrameworks))]
|
||||
public async Task TestGetByIds(JazzEntityFrameworkFactory jazzEntityFrameworkFactory)
|
||||
{
|
||||
// arrange
|
||||
var variationOpportunityService = new UVOpportunityService(jazzEntityFrameworkFactory, null, null, _initiativeService, _updateFactOpportunitySavingsService);
|
||||
|
||||
// act
|
||||
var tempResult = await variationOpportunityService.GetAllAsync(CancellationToken.None);
|
||||
var ids = tempResult.Select(o => o.OpportunityGuid);
|
||||
var taskResult = await variationOpportunityService.GetByIds(ids, CancellationToken.None);
|
||||
|
||||
// assert
|
||||
if (string.IsNullOrEmpty(jazzEntityFrameworkFactory.TestName))
|
||||
{
|
||||
taskResult.Should().BeNullOrEmpty();
|
||||
}
|
||||
else
|
||||
{
|
||||
taskResult.Should().NotBeNullOrEmpty()
|
||||
.And.AllBeOfType<UVOpportunity>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[TearDown]
|
||||
public void TestTearDown()
|
||||
{
|
||||
// Method intentionally left empty.
|
||||
}
|
||||
|
||||
#region TestCaseData
|
||||
|
||||
public static IEnumerable<TestCaseData> GetFilterData()
|
||||
{
|
||||
yield return new TestCaseData(new UVFilters { ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") }).SetName("No Filters");
|
||||
yield return new TestCaseData(new UVFilters { ViewVisible = true, ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") }).SetName("View Visible");
|
||||
yield return new TestCaseData(new UVFilters { ViewVisible = false, ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") }).SetName("Not View Visible");
|
||||
yield return new TestCaseData(new UVFilters
|
||||
{ CaseTypeGuids = new[] { new Guid("c7838982-b2c6-4e93-a571-c1fd5cedc961") }, ViewVisible = true, ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") })
|
||||
.SetName("By Case Type GUID");
|
||||
yield return new TestCaseData(new UVFilters { CostDrivers = new[] { "Cost Driver" }, ViewVisible = true, ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") })
|
||||
.SetName("By Cost Driver");
|
||||
yield return new TestCaseData(new UVFilters { EntityIds = new[] { "1" }, ViewVisible = true, ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") }).SetName(
|
||||
"By Entity ID");
|
||||
yield return new TestCaseData(new UVFilters { IdentifiedSavings = 1999, ViewVisible = true, ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") }).SetName(
|
||||
"By Identified Savings");
|
||||
yield return new TestCaseData(new UVFilters { ServiceLineIds = new[] { "1" }, ViewVisible = true, ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") })
|
||||
.SetName("By Service Line");
|
||||
yield return new TestCaseData(new UVFilters
|
||||
{ CaseTypeGuids = new[] { new Guid("c7838982-b2c6-4e93-a571-c1fd5cedc961") }, ViewVisible = false, ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") })
|
||||
.SetName("By Case Type GUID Not ViewVisible");
|
||||
yield return new TestCaseData(
|
||||
new UVFilters { CostDrivers = new[] { "Cost Driver" }, ViewVisible = false, ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") })
|
||||
.SetName("By Cost Driver Not ViewVisible");
|
||||
yield return new TestCaseData(new UVFilters { EntityIds = new[] { "1" }, ViewVisible = false, ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") }).SetName(
|
||||
"By Entity ID Not ViewVisible");
|
||||
yield return new TestCaseData(new UVFilters { IdentifiedSavings = 999, ViewVisible = false, ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") }).SetName(
|
||||
"By Identified Savings Not ViewVisible");
|
||||
yield return new TestCaseData(new UVFilters { ServiceLineIds = new[] { "2" }, ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345"), ViewVisible = false })
|
||||
.SetName("By Service Line Not ViewVisible");
|
||||
yield return new TestCaseData(new UVFilters { OpportunitySearch = "UV - 123", ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") }).SetName("Search By Id");
|
||||
yield return new TestCaseData(new UVFilters { ExcludeInitiatives = true, ConfigurationGuid = new Guid("e96abe3e-1526-43ca-815e-ee30c5b34345") }).SetName("Exclude Opportunities with Initiatives");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
var serviceLineId = jeff.UVOpportunities.FirstOrDefault(o => !o.IsHidden)?.ServiceLineId ?? 0;
|
||||
if (string.IsNullOrEmpty(jeff.TestName))
|
||||
{
|
||||
yield return new TestCaseData(jeff,
|
||||
new UVFilters { ServiceLineIds = new[] { serviceLineId.ToString() }, ViewVisible = false }, ct)
|
||||
.SetName("By Service Line Not ViewVisible w/o Jeff");
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return new TestCaseData(jeff,
|
||||
new UVFilters { ServiceLineIds = new[] { serviceLineId.ToString() }, ViewVisible = false }, ct)
|
||||
.SetName("By Service Line Not ViewVisible w/Jeff")
|
||||
.Ignore("This test is broken");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user