Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

459419 Transpose pom and org data #74

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7dbbce8
Adding CalculationResultModels - UD
udaydefra Oct 30, 2024
5da5e89
Adding CalcResultParameterCommunicationCost - 463833
udaydefra Oct 30, 2024
22a5b46
Results
udaydefra Oct 30, 2024
451461c
Results structure
udaydefra Oct 30, 2024
4c07728
Registering Builder / Exporter
udaydefra Oct 31, 2024
6857354
Removing DBContext and renaming action method
udaydefra Oct 31, 2024
18db078
Adding CalcResult - 463833
udaydefra Oct 31, 2024
cde4a5a
Calculation Results Model
udaydefra Oct 31, 2024
3374b7b
459419 Transpose pom and org data
johnbenjamin-defra Oct 31, 2024
f4132fb
Merge remote-tracking branch 'origin/main' into feature/459240-part3-…
Mazar-Shaik Nov 4, 2024
d8f8a85
Calculator Results Model structure Changes - 463833
udaydefra Nov 4, 2024
729d5cf
459419 Transpose pom and org data
johnbenjamin-defra Nov 4, 2024
d98c492
Merge branch 'feature/463833-Results-Model-Structure-Ud' into feature…
johnbenjamin-defra Nov 4, 2024
6adae67
459419 Transpose pom and org data
johnbenjamin-defra Nov 4, 2024
37b8d27
Update CalculatorInternalController.cs
johnbenjamin-defra Nov 5, 2024
5216260
Moving TransposePomAndOrgDataService to a concrete instance and Some …
udaydefra Nov 5, 2024
48a3bf6
Checkin for Part 3 Write initial results file - Run information - 2
Mazar-Shaik Nov 5, 2024
9952ca4
459419 Transpose pom and org data
johnbenjamin-defra Nov 5, 2024
a6954f9
Merge branch 'main' into feature/459419-Transpose-pom-and-org-data
johnbenjamin-defra Nov 5, 2024
872c721
459419 Transpose pom and org data
johnbenjamin-defra Nov 5, 2024
f6cd2bf
Update CalculatorController.cs
johnbenjamin-defra Nov 5, 2024
49a3f2e
Sonar issues
johnbenjamin-defra Nov 5, 2024
6e592e4
Merge conflict resolved after merge from main
Mazar-Shaik Nov 5, 2024
bfb9951
Update TransposePomAndOrgDataService.cs
johnbenjamin-defra Nov 5, 2024
2cb28fe
Refactored the code
Mazar-Shaik Nov 5, 2024
ef8dd92
Merge from main
Mazar-Shaik Nov 5, 2024
018d322
Refactored code for more readability
Mazar-Shaik Nov 5, 2024
095d955
Used Async and await.
Mazar-Shaik Nov 5, 2024
dcd884b
Added file extension as csv
Mazar-Shaik Nov 5, 2024
a30d18b
Test cases failure checkin
Mazar-Shaik Nov 5, 2024
adf34c8
Merge branch 'main' into feature/459419-Transpose-pom-and-org-data
johnbenjamin-defra Nov 6, 2024
766d533
459419 Transpose pom and org data
johnbenjamin-defra Nov 6, 2024
31fe93b
Update TransposePomAndOrgDataService.cs
johnbenjamin-defra Nov 6, 2024
e1a994e
Updated Lapcapfile name
Mazar-Shaik Nov 6, 2024
9140ff1
Update TransposePomAndOrgDataService.cs
johnbenjamin-defra Nov 6, 2024
5becc8d
Merge branch 'main' into feature/459240-part3-writing-initial-result-…
udaydefra Nov 7, 2024
0826950
Merge from 459240 - UD
udaydefra Nov 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 156 additions & 3 deletions src/EPR.Calculator.API.UnitTests/BaseControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using EPR.Calculator.API.Builder;
using EPR.Calculator.API.Models;
using EPR.Calculator.API.Exporter;
using EPR.Calculator.API.Services;

namespace EPR.Calculator.API.Tests.Controllers
{
Expand Down Expand Up @@ -54,7 +55,8 @@ public void SetUp()
new RpdStatusDataValidator(wrapper),
wrapper,
new Mock<ICalcResultBuilder>().Object,
new Mock<ICalcResultsExporter<CalcResult>>().Object
new Mock<ICalcResultsExporter<CalcResult>>().Object,
new Mock<ITransposePomAndOrgDataService>().Object
);

var mockFactory = new Mock<IAzureClientFactory<ServiceBusClient>>();
Expand All @@ -65,11 +67,12 @@ public void SetUp()

mockFactory.Setup(m => m.CreateClient(It.IsAny<string>())).Returns(mockClient.Object);



dbContext.CalculatorRuns.AddRange(GetCalculatorRuns());
dbContext.SaveChanges();
calculatorController = new CalculatorController(dbContext, ConfigurationItems.GetConfigurationValues(), mockFactory.Object);

dbContext.Material.AddRange(GetMaterials());
dbContext.SaveChanges();
}

public void CheckDbContext()
Expand Down Expand Up @@ -709,6 +712,156 @@ protected static IEnumerable<CalculatorRun> GetCalculatorRuns()
CreatedAt = new DateTime(2024, 8, 21, 14, 16, 27, DateTimeKind.Utc),
CreatedBy = "Test User"
});
list.Add(new CalculatorRun
{
Id = 3,
CalculatorRunClassificationId = (int)RunClassification.RUNNING,
Name = "Test Run",
Financial_Year = "2024-25",
CreatedAt = new DateTime(2024, 8, 28, 10, 12, 30, DateTimeKind.Utc),
CreatedBy = "Test User",
CalculatorRunOrganisationDataMasterId = 1,
CalculatorRunPomDataMasterId = 1,
});
list.Add(new CalculatorRun
{
Id = 4,
CalculatorRunClassificationId = (int)RunClassification.RUNNING,
Name = "Test Calculated Result",
Financial_Year = "2024-25",
CreatedAt = new DateTime(2024, 8, 21, 14, 16, 27, DateTimeKind.Utc),
CreatedBy = "Test User",
CalculatorRunOrganisationDataMasterId = 2,
CalculatorRunPomDataMasterId = 2,
});
return list;
}

protected static IEnumerable<Material> GetMaterials()
{
var list = new List<Material>();
list.Add(new Material
{
Id = 1,
Code = "AL",
Name = "Aluminium",
Description = "Aluminium"
});
list.Add(new Material
{
Id = 2,
Code = "FC",
Name = "Fibre composite",
Description = "Fibre composite"
});
list.Add(new Material
{
Id = 3,
Code = "GL",
Name = "Glass",
Description = "Glass"
});
list.Add(new Material
{
Id = 4,
Code = "PC",
Name = "Paper or card",
Description = "Paper or card"
});
list.Add(new Material
{
Id = 5,
Code = "PL",
Name = "Plastic",
Description = "Plastic"
});
list.Add(new Material
{
Id = 6,
Code = "ST",
Name = "Steel",
Description = "Steel"
});
list.Add(new Material
{
Id = 7,
Code = "WD",
Name = "Wood",
Description = "Wood"
});
list.Add(new Material
{
Id = 8,
Code = "OT",
Name = "Other materials",
Description = "Other materials"
});
return list;
}

protected static IEnumerable<CalculatorRunPomDataMaster> GetCalculatorRunPomDataMaster()
{
var list = new List<CalculatorRunPomDataMaster>();
list.Add(new CalculatorRunPomDataMaster
{
Id = 1,
CalendarYear = "2024-25",
EffectiveFrom = DateTime.Now,
CreatedBy = "Test user",
CreatedAt = DateTime.Now
});
return list;
}

protected static IEnumerable<CalculatorRunPomDataDetail> GetCalculatorRunPomDataDetails()
{
var list = new List<CalculatorRunPomDataDetail>();
list.Add(new CalculatorRunPomDataDetail
{
Id= 1,
OrganisationId = 1,
SubsidaryId = "SUBSID1",
SubmissionPeriod = "2023-P3",
PackagingActivity = null,
PackagingType = "CW",
PackagingClass = "O1",
PackagingMaterial = "PC",
PackagingMaterialWeight = 1000,
LoadTimeStamp = DateTime.Now,
CalculatorRunPomDataMasterId = 1,
SubmissionPeriodDesc = "July to December 2023",
CalculatorRunPomDataMaster = BaseControllerTest.GetCalculatorRunPomDataMaster().ToList()[0]
});
return list;
}

protected static IEnumerable<CalculatorRunOrganisationDataMaster> GetCalculatorRunOrganisationDataMaster()
{
var list = new List<CalculatorRunOrganisationDataMaster>();
list.Add(new CalculatorRunOrganisationDataMaster
{
CalendarYear = "2024-25",
EffectiveFrom = DateTime.Now,
CreatedBy = "Test user",
CreatedAt = DateTime.Now
});
return list;
}

protected static IEnumerable<CalculatorRunOrganisationDataDetail> GetCalculatorRunOrganisationDataDetails()
{
var list = new List<CalculatorRunOrganisationDataDetail>();
list.Add(new CalculatorRunOrganisationDataDetail
{
Id = 1,
OrganisationId = 1,
SubsidaryId = "SUBSID1",
OrganisationName = "UPU LIMITED",
LoadTimeStamp= DateTime.Now,
CalculatorRunOrganisationDataMasterId = 1,
SubmissionPeriodDesc = "January to June 2023",
CalculatorRunOrganisationDataMaster = BaseControllerTest.GetCalculatorRunOrganisationDataMaster().ToList()[0]
});
return list;
}
}
Expand Down
85 changes: 85 additions & 0 deletions src/EPR.Calculator.API.UnitTests/CalResultsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using EPR.Calculator.API.Builder;
using EPR.Calculator.API.Controllers;
using EPR.Calculator.API.Data;
using EPR.Calculator.API.Dtos;
using EPR.Calculator.API.Exporter;
using EPR.Calculator.API.Models;
using EPR.Calculator.API.Services;
using EPR.Calculator.API.Validators;
using EPR.Calculator.API.Wrapper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace EPR.Calculator.API.UnitTests
{
[TestClass]
public class CalcResultServiceTests
{
private Mock<ICalcResultBuilder> mockCalcResultBuilder;
private Mock<ICalcResultsExporter<CalcResult>> mockExporter;
private Mock<ICalcResultDetailBuilder> mockDetailBuilder;
private Mock<ICalcResultLapcapDataBuilder> mockLapcapBuilder;

private Mock<ApplicationDBContext> mockContext;
private CalculatorInternalController controller;
private CalcResultBuilder calcResultBuilder;
private CalcResultDetailBuilder detailBuilder;
private CalcResultsExporter exporter;
protected ApplicationDBContext? dbContext;
protected IOrgAndPomWrapper? wrapper;

[TestInitialize]
public void Setup()
{
mockCalcResultBuilder = new Mock<ICalcResultBuilder>();
mockExporter = new Mock<ICalcResultsExporter<CalcResult>>();
wrapper = new Mock<IOrgAndPomWrapper>().Object;
var transposePomAndOrgDataService = new Mock<ITransposePomAndOrgDataService>();
controller = new CalculatorInternalController(
dbContext,
new RpdStatusDataValidator(wrapper),
wrapper,
mockCalcResultBuilder.Object,
mockExporter.Object,
transposePomAndOrgDataService.Object
);

mockDetailBuilder = new Mock<ICalcResultDetailBuilder>();
mockLapcapBuilder = new Mock<ICalcResultLapcapDataBuilder>();
calcResultBuilder = new CalcResultBuilder(mockDetailBuilder.Object, mockLapcapBuilder.Object);

mockContext = new Mock<ApplicationDBContext>();
detailBuilder = new CalcResultDetailBuilder(mockContext.Object);

}

[TestMethod]
public void PrepareCalcResults_ShouldReturnCreatedStatus()
{
var requestDto = new CalcResultsRequestDto();
var calcResult = new CalcResult();
mockCalcResultBuilder.Setup(b => b.Build(requestDto)).Returns(calcResult);

var result = controller.PrepareCalcResults(requestDto) as ObjectResult;

Assert.IsNotNull(result);
Assert.AreEqual(201, result.StatusCode);
mockExporter.Verify(e => e.Export(calcResult), Times.Once);
}

[TestMethod]
public void Build_ShouldReturnCalcResultWithDetail()
{
var requestDto = new CalcResultsRequestDto();
var detail = new CalcResultDetail();
mockDetailBuilder.Setup(d => d.Construct(requestDto)).Returns(detail);

var result = calcResultBuilder.Build(requestDto);

Assert.IsNotNull(result);
Assert.AreEqual(detail, result.CalcResultDetail);
}
}
}

Loading