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 18 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using EPR.Calculator.API.Data.DataModels;
using EPR.Calculator.API.Exporter;
using EPR.Calculator.API.Models;
using EPR.Calculator.API.Services;
using EPR.Calculator.API.Tests.Controllers;
using EPR.Calculator.API.Validators;
using EPR.Calculator.API.Wrapper;
Expand Down Expand Up @@ -179,7 +180,8 @@ public void UpdateRpdStatus_With_RunId_When_Successful()
new RpdStatusDataValidator(mock.Object),
mock.Object,
new Mock<ICalcResultBuilder>().Object,
new Mock<ICalcResultsExporter<CalcResult>>().Object
new Mock<ICalcResultsExporter<CalcResult>>().Object,
new Mock<ITransposePomAndOrgDataService>().Object
);

var request = new Dtos.UpdateRpdStatus { isSuccessful = true, RunId = 1, UpdatedBy = "User1" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace EPR.Calculator.API.UnitTests.Controllers
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.VisualStudio.TestTools.UnitTesting;
Expand All @@ -22,6 +23,7 @@ public class CalculatorInternalControllerTests
private Mock<IOrgAndPomWrapper> _wrapper;
private Mock<ICalcResultBuilder> _builder;
private Mock<ICalcResultsExporter<CalcResult>> _exporter;
private Mock<ITransposePomAndOrgDataService> _transposePomAndOrgDataService;

[TestInitialize]
public void SetUp()
Expand All @@ -31,7 +33,8 @@ public void SetUp()
_wrapper = new Mock<IOrgAndPomWrapper>();
_builder = new Mock<ICalcResultBuilder>();
_exporter = new Mock<ICalcResultsExporter<CalcResult>>();
_testClass = new CalculatorInternalController(_context, _rpdStatusDataValidator.Object, _wrapper.Object, _builder.Object, _exporter.Object);
_transposePomAndOrgDataService = new Mock<ITransposePomAndOrgDataService>();
_testClass = new CalculatorInternalController(_context, _rpdStatusDataValidator.Object, _wrapper.Object, _builder.Object, _exporter.Object, _transposePomAndOrgDataService.Object);
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using EPR.Calculator.API.Data.DataModels;
using EPR.Calculator.API.Services;
using EPR.Calculator.API.Tests.Controllers;
using EPR.Calculator.API.Wrapper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace EPR.Calculator.API.UnitTests.Services
{
[TestClass]
public class TransposePomAndOrgDataServiceTests : BaseControllerTest
{
[TestInitialize]
public void Setup()
{
#pragma warning disable CS8602 // Dereference of a possibly null reference.
dbContext.CalculatorRunPomDataDetails.AddRange(GetCalculatorRunPomDataDetails());
dbContext.SaveChanges();

dbContext.CalculatorRunOrganisationDataDetails.AddRange(GetCalculatorRunOrganisationDataDetails());
dbContext.SaveChanges();
#pragma warning restore CS8602 // Dereference of a possibly null reference.
}

[TestMethod]
public void Transpose_Should_Return_Correct_Producer_Detail()
{
var expectedResult = new ProducerDetail
{
Id = 1,
ProducerId = 1,
SubsidiaryId = "SUBSID1",
ProducerName = "UPU LIMITED",
CalculatorRunId = 1,
CalculatorRun = new CalculatorRun()
};

#pragma warning disable CS8604 // Possible null reference argument.
var service = new TransposePomAndOrgDataService(dbContext);
#pragma warning restore CS8604 // Possible null reference argument.
service.Transpose(3);

var producerDetail = dbContext.ProducerDetail.FirstOrDefault();
Assert.IsNotNull(producerDetail);
Assert.AreEqual(expectedResult.ProducerId, producerDetail.ProducerId);
Assert.AreEqual(expectedResult.ProducerName, producerDetail.ProducerName);
Assert.AreEqual(expectedResult.SubsidiaryId, producerDetail.SubsidiaryId);
}

[TestMethod]
public void Transpose_Should_Return_Correct_Producer_Reported_Material()
{
var expectedResult = new ProducerReportedMaterial
{
Id = 1,
MaterialId = 4,
ProducerDetailId = 1,
PackagingType = "CW",
PackagingTonnage = 1,
Material = new Material
{
Id = 4,
Code = "PC",
Name = "Paper or card",
Description = "Paper or card"
},
ProducerDetail = new ProducerDetail
{
Id = 1,
ProducerId = 1,
SubsidiaryId = "SUBSID1",
ProducerName = "UPU LIMITED",
CalculatorRunId = 1,
CalculatorRun = new CalculatorRun()
}
};

#pragma warning disable CS8604 // Possible null reference argument.
var service = new TransposePomAndOrgDataService(dbContext);
#pragma warning restore CS8604 // Possible null reference argument.
service.Transpose(3);

var producerReportedMaterial = dbContext.ProducerReportedMaterial.FirstOrDefault();
Assert.IsNotNull(producerReportedMaterial);
Assert.AreEqual(expectedResult.ProducerDetailId, producerReportedMaterial.ProducerDetailId);
Assert.AreEqual(expectedResult.Material.Code, producerReportedMaterial.Material.Code);
Assert.AreEqual(expectedResult.Material.Name, producerReportedMaterial.Material.Name);
Assert.AreEqual(expectedResult.ProducerDetail.ProducerId, producerReportedMaterial.ProducerDetail.ProducerId);
Assert.AreEqual(expectedResult.ProducerDetail.ProducerName, producerReportedMaterial.ProducerDetail.ProducerName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using EPR.Calculator.API.Enums;
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;
Expand All @@ -20,18 +21,21 @@ public class CalculatorInternalController : ControllerBase
private readonly IOrgAndPomWrapper wrapper;
private readonly ICalcResultBuilder builder;
private readonly ICalcResultsExporter<CalcResult> exporter;
private readonly ITransposePomAndOrgDataService transposePomAndOrgDataService;

public CalculatorInternalController(ApplicationDBContext context,
IRpdStatusDataValidator rpdStatusDataValidator,
IOrgAndPomWrapper wrapper,
ICalcResultBuilder builder,
ICalcResultsExporter<CalcResult> exporter)
ICalcResultsExporter<CalcResult> exporter,
ITransposePomAndOrgDataService transposePomAndOrgDataService)
{
this.context = context;
this.rpdStatusDataValidator = rpdStatusDataValidator;
this.wrapper = wrapper;
this.builder = builder;
this.exporter = exporter;
this.transposePomAndOrgDataService = transposePomAndOrgDataService;
}

[HttpPost]
Expand Down Expand Up @@ -146,6 +150,7 @@ public IActionResult UpdateRpdStatus([FromBody] UpdateRpdStatus request)
[Route("prepareCalcResults")]
public IActionResult PrepareCalcResults([FromBody] CalcResultsRequestDto resultsRequestDto)
{
this.transposePomAndOrgDataService.Transpose(resultsRequestDto.RunId);
udaydefra marked this conversation as resolved.
Show resolved Hide resolved
var results = this.builder.Build(resultsRequestDto);
this.exporter.Export(results);
return new ObjectResult(null) { StatusCode = StatusCodes.Status201Created };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public class CalcResultParameterOtherCost
public IEnumerable<CalcResultParameterOtherCostDetail5> CalcResultParameterCommunicationCostDetails5 { get; set; } =
new List<CalcResultParameterOtherCostDetail5>();
}
}
}
2 changes: 2 additions & 0 deletions src/EPR.Calculator.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using EPR.Calculator.API.Exceptions;
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 FluentValidation;
Expand All @@ -29,6 +30,7 @@
builder.Services.AddScoped<ICalcResultBuilder, CalcResultBuilder>();
builder.Services.AddScoped<ICalcResultsExporter<CalcResult>, CalcResultsExporter>();
builder.Services.AddScoped<ICalcResultLapcapDataBuilder, CalcResultLapcapDataBuilder>();
builder.Services.AddScoped<ITransposePomAndOrgDataService, TransposePomAndOrgDataService>();

builder.Services.AddValidatorsFromAssemblyContaining<CreateDefaultParameterSettingValidator>();
builder.Services.AddDbContext<ApplicationDBContext>(options =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace EPR.Calculator.API.Services
{
public interface ITransposePomAndOrgDataService
{
public void Transpose(int runId);
}
}
Loading