Untitled
unknown
plain_text
11 days ago
23 kB
6
Indexable
using SGS.Application.Commands.AnalysisReports; using SGS.Application.Common.Helpers; using SGS.Application.Queries.AnalysisReports; using SGS.Application.Queries.WarehouseSetups; using SGS.Application.Services.Dtos; using SGS.Domain.Common.Enums; using SGS.Domain.Entities.Partners; using SGS.Domain.Entities.Roles.ReadModels; using SGS.Domain.Entities.ScreeningTests; using SGS.Domain.Entities.TestingLabs; using SGS.Test.Integration.Common; using SGS.Test.Integration.Helpers; using Xunit; namespace SGS.Test.Integration.SicpaJobTests; public class SicpaJobTest : BaseTest { private Partner _partner; private TestingLab _testingLab; private ScreeningTest _screeningTest; public SicpaJobTest(Fixture fixture) : base(fixture) { } private async Task SetUp() { SetupHelper setupHelper = new SetupHelper(); _partner = await setupHelper.SetupPartner(HttpClient); _testingLab = await setupHelper.SetupTestingLab(HttpClient); _screeningTest = await setupHelper.SetupScreeningTest(HttpClient); } [Fact] public async Task SicpaJob_Success() { // Arrange await SetUp(); var warehouseSetupResponseMessage = await HttpClient.GetSingleWarehouseSetup(); var warehouseSetup = await ApiCallerHelper.ParseResponse<GetSingleWarehouseSetup.Response>(warehouseSetupResponseMessage); var commandResultVisibilities = PrepareCommandResultVisibilities(); var commandResultSigns = PrepareCommandResultSigns(); var commandResultValues = PrepareCommandResultValues(); var anReport1 = await CreateAnalysisReport(warehouseSetup, commandResultVisibilities, commandResultSigns, commandResultValues, "Sample1", SampleStatus.Nominal); var anReport2 = await CreateAnalysisReport(warehouseSetup, commandResultVisibilities, commandResultSigns, commandResultValues, "Sample2", SampleStatus.Suspect); var anReport3 = await CreateAnalysisReport(warehouseSetup, commandResultVisibilities, commandResultSigns, commandResultValues, "Sample3", SampleStatus.Final); var tooLongString = new string('*', 451); var failedPartner = "Partner123"; var reportsToSync = PrepareReportsToSync(anReport1, anReport2, anReport3, failedPartner, tooLongString); // Act var sicpaUpdateRequest = await Fixture.AnalysisReportsService.SyncAnalysisReport(reportsToSync, warehouseSetup.SicpaWorkerId.Value); // Assert var responseMessage = await HttpClient.BrowseAnalysisReports(); var response = await ApiCallerHelper .ParseResponse<PaginatedListReadModel<BrowseAnalysisReports.Response>>(responseMessage); var analysisReports = response.Items; var softDeletedReport = analysisReports.FirstOrDefault(e => e.AnalyseReportNo == anReport2.AnalyseReportNo && e.SampleId == anReport2.SampleId); Assert.Equal(true, softDeletedReport?.IsDeleted); Assert.Equal(4, sicpaUpdateRequest.AnalysisReports.Count); Assert.Equal(2, sicpaUpdateRequest.failedEntries.Count); AssertSuccessfulAndFailedEntries(sicpaUpdateRequest, analysisReports, warehouseSetup, anReport1, anReport3, failedPartner, tooLongString); } private void AssertSuccessfulAndFailedEntries(SicpaUpdateRequestDto sicpaUpdateRequestDto, IReadOnlyList<BrowseAnalysisReports.Response> analysisReports, GetSingleWarehouseSetup.Response warehouseSetup, CreateAnalysisReport.Response anReport1, CreateAnalysisReport.Response anReport3, string failedPartner, string tooLongString) { var expectedDate = new DateTime(2024, 06, 06); foreach (var successfulEntry in sicpaUpdateRequestDto.AnalysisReports) { var report = analysisReports.FirstOrDefault(e => e.AnalyseReportNo == successfulEntry.AnalyseReportNo && e.SampleId == successfulEntry.SampleId); switch (report.SampleId) { case "Sample1": Assert.Equal(anReport1.AnalyseReportNo, report?.AnalyseReportNo); Assert.Equal(anReport1.SampleId, report?.SampleId); Assert.Equal(expectedDate, report?.DateOfSampleAnalysis); Assert.Equal(expectedDate, report?.DateOfSampleCollection); Assert.Equal(expectedDate, report?.DateOfSampleReceiving); Assert.Equal("Location A", report?.SamplingLocationName); Assert.Equal(_testingLab.Location, report?.TestingLaboratoryLocationName); Assert.Equal("Source A", report?.SampleSourceName); Assert.Equal("Oil", report?.NatureOfSampleName); Assert.Equal("Device A", report?.DeviceName); Assert.Equal(TestingLaboratory.Mobile, report?.TestingLaboratory); Assert.Equal((decimal)1.1, report?.DieselPercentInTheSample); Assert.Equal("Remark A", report?.SampleRemark); Assert.Equal("name", report?.PartnerName); Assert.Equal(false, report?.IsDeleted); Assert.Equal(warehouseSetup.SicpaWorkerId, report?.IssuedById); Assert.Equal(SampleStatus.Nominal, report?.SampleStatus); break; case "Sample2": Assert.Equal("ST23-000004", report?.AnalyseReportNo); Assert.Equal("Sample2", report?.SampleId); Assert.Equal(expectedDate, report?.DateOfSampleAnalysis); Assert.Equal(expectedDate, report?.DateOfSampleCollection); Assert.Equal(expectedDate, report?.DateOfSampleReceiving); Assert.Equal("Location A", report?.SamplingLocationName); Assert.Equal(_testingLab.Location, report?.TestingLaboratoryLocationName); Assert.Equal("Source A", report?.SampleSourceName); Assert.Equal("Oil", report?.NatureOfSampleName); Assert.Equal("Device A", report?.DeviceName); Assert.Equal(TestingLaboratory.Mobile, report?.TestingLaboratory); Assert.Equal(10.5M, report?.DieselPercentInTheSample); Assert.Equal("Remark A", report?.SampleRemark); Assert.Equal("name", report?.PartnerName); Assert.Equal(true, report?.IsDeleted); Assert.Equal(warehouseSetup.SicpaWorkerId, report?.IssuedById); Assert.Equal(SampleStatus.Suspect, report?.SampleStatus); break; case "Sample3": Assert.Equal(anReport3.AnalyseReportNo, report?.AnalyseReportNo); Assert.Equal(anReport3.SampleId, report?.SampleId); Assert.Equal(expectedDate, report?.DateOfSampleAnalysis); Assert.Equal(expectedDate, report?.DateOfSampleCollection); Assert.Equal(expectedDate, report?.DateOfSampleReceiving); Assert.Equal("Location A1", report?.SamplingLocationName); Assert.Equal(_testingLab.Location, report?.TestingLaboratoryLocationName); Assert.Equal("Source A1", report?.SampleSourceName); Assert.Equal("Oil1", report?.NatureOfSampleName); Assert.Equal("Device A1", report?.DeviceName); Assert.Equal(TestingLaboratory.Mobile, report?.TestingLaboratory); Assert.Equal(10.5M, report?.DieselPercentInTheSample); Assert.Equal("Remark A1", report?.SampleRemark); Assert.Equal("name", report?.PartnerName); Assert.Equal(false, report?.IsDeleted); Assert.Equal(warehouseSetup.SicpaWorkerId, report?.IssuedById); Assert.Equal(SampleStatus.Final, report?.SampleStatus); break; } } foreach (var failedEntry in sicpaUpdateRequestDto.failedEntries) { switch (failedEntry.SampleId) { case "Sample103": Assert.Equal("ReportNo103", failedEntry?.AnalysisReportNo); Assert.Equal("Sample103", failedEntry?.SampleId); Assert.Contains($"Partner name \"{failedPartner}\" doesn't exist in database. ", failedEntry?.ErrorMessage); break; default: Assert.Equal(tooLongString, failedEntry?.AnalysisReportNo); Assert.Equal(tooLongString, failedEntry?.SampleId); Assert.Contains("Analysis report no length is over 450. ", failedEntry?.ErrorMessage); Assert.Contains("Sample id length is over 450. ", failedEntry?.ErrorMessage); Assert.Contains($"Partner name \"{tooLongString}\" doesn't exist in database. ", failedEntry?.ErrorMessage); Assert.Contains($"Partner name \"{tooLongString}\" length is over 100. ", failedEntry?.ErrorMessage); Assert.Contains("Testing laboratory value is \"5\" and it can not be greater than 4. ", failedEntry?.ErrorMessage); break; } } } [Fact] public async Task SicpaJob_SpacesBeforeAndAfterTestingLabAndScreeningTest() { // Arrange await SetUp(); var warehouseSetupResponseMessage = await HttpClient.GetSingleWarehouseSetup(); var warehouseSetup = await ApiCallerHelper.ParseResponse<GetSingleWarehouseSetup.Response>(warehouseSetupResponseMessage); var reportsToSync = PrepareReportsToSync(); // Act var sicpaUpdateRequest = await Fixture.AnalysisReportsService.SyncAnalysisReport(reportsToSync, warehouseSetup.SicpaWorkerId.Value); // Assert var responseMessage = await HttpClient.BrowseAnalysisReports(); var response = await ApiCallerHelper .ParseResponse<PaginatedListReadModel<BrowseAnalysisReports.Response>>(responseMessage); Assert.Equal("TEST1", response.Items.FirstOrDefault()?.AnalyseReportNo); Assert.Equal(2, sicpaUpdateRequest.failedEntries.Count); } private List<LabAnalysisTestFinalRun> PrepareReportsToSync() { return new List<LabAnalysisTestFinalRun>() { new() { AnalysisReportNo = "TEST1", SampleId = "TEST11", DateOfSampleCollection = "06/06/2024", DateOfSampleReceiving = "06/06/2024", DateOfSampleAnalysis = new DateTime(2024, 06, 06), SamplingLocationName = "Location A", TestingLaboratoryLocationName = _testingLab.Name, SampleSourceName = "Source A", NatureOfSampleName = "Oil", DeviceName = "Device A", TestingLaboratory = 2, DieselPercentInTheSample = (decimal)1.1, SampleRemark = "Remark A", PartnerName = "name", CreatedAt = DateTime.Now, LastModifiedAt = DateTime.Now, IsDeleted = false, SampleStatus = SampleStatus.Nominal, ScreeningSampleTestStatus = _screeningTest.Name }, new() { AnalysisReportNo = "TEST2", SampleId = "TEST22", DateOfSampleCollection = "06/06/2024", DateOfSampleReceiving = "06/06/2024", DateOfSampleAnalysis = new DateTime(2024, 06, 06), SamplingLocationName = "Location A", TestingLaboratoryLocationName = " " + _testingLab.Name + " ", SampleSourceName = "Source A", NatureOfSampleName = "Oil", DeviceName = "Device A", TestingLaboratory = 2, DieselPercentInTheSample = (decimal)1.1, SampleRemark = "Remark A", PartnerName = "name", CreatedAt = DateTime.Now, LastModifiedAt = DateTime.Now, IsDeleted = false, SampleStatus = SampleStatus.Nominal, ScreeningSampleTestStatus = " " + _screeningTest.Name + " " }, new() { AnalysisReportNo = "TEST3", SampleId = "TEST33", DateOfSampleCollection = "06/06/2024", DateOfSampleReceiving = "06/06/2024", DateOfSampleAnalysis = new DateTime(2024, 06, 06), SamplingLocationName = "Location A", TestingLaboratoryLocationName = " " + _testingLab.Name, SampleSourceName = "Source A", NatureOfSampleName = "Oil", DeviceName = "Device A", TestingLaboratory = 2, DieselPercentInTheSample = (decimal)1.1, SampleRemark = "Remark A", PartnerName = "name", CreatedAt = DateTime.Now, LastModifiedAt = DateTime.Now, IsDeleted = false, SampleStatus = SampleStatus.Nominal, ScreeningSampleTestStatus = " " + _screeningTest.Name }, }; } private List<LabAnalysisTestFinalRun> PrepareReportsToSync(CreateAnalysisReport.Response anReport1, CreateAnalysisReport.Response anReport2, CreateAnalysisReport.Response anReport3, string failedPartner, string tooLongString) { return new List<LabAnalysisTestFinalRun>() { new() { AnalysisReportNo = anReport1.AnalyseReportNo, SampleId = anReport1.SampleId, DateOfSampleCollection = "06/06/2024", DateOfSampleReceiving = "06/06/2024", DateOfSampleAnalysis = new DateTime(2024, 06, 06), SamplingLocationName = "Location A", TestingLaboratoryLocationName = _testingLab.Name, SampleSourceName = "Source A", NatureOfSampleName = "Oil", DeviceName = "Device A", TestingLaboratory = 2, DieselPercentInTheSample = (decimal)1.1, SampleRemark = "Remark A", PartnerName = "name", CreatedAt = DateTime.Now, LastModifiedAt = DateTime.Now, IsDeleted = false, SampleStatus = anReport1.SampleStatus, ScreeningSampleTestStatus = _screeningTest.Name }, new() { AnalysisReportNo = anReport2.AnalyseReportNo, SampleId = anReport2.SampleId, DateOfSampleCollection = "06/06/2024", DateOfSampleReceiving = "06/06/2024", DateOfSampleAnalysis = new DateTime(2024, 06, 06), SamplingLocationName = "Location A", TestingLaboratoryLocationName = _testingLab.Name, SampleSourceName = "Source A", NatureOfSampleName = "Oil", DeviceName = "Device A", TestingLaboratory = 2, DieselPercentInTheSample = 10.5M, SampleRemark = "Remark A", PartnerName = "name", CreatedAt = DateTime.Now, LastModifiedAt = DateTime.Now, IsDeleted = true, SampleStatus = anReport2.SampleStatus, ScreeningSampleTestStatus = _screeningTest.Name }, new() { AnalysisReportNo = anReport3.AnalyseReportNo, SampleId = anReport3.SampleId, DateOfSampleCollection = "06/06/2024", DateOfSampleReceiving = "06/06/2024", DateOfSampleAnalysis = new DateTime(2024, 06, 06), SamplingLocationName = "Location A1", TestingLaboratoryLocationName = _testingLab.Name, SampleSourceName = "Source A1", NatureOfSampleName = "Oil1", DeviceName = "Device A1", TestingLaboratory = 2, DieselPercentInTheSample = 10.5M, SampleRemark = "Remark A1", PartnerName = "name", CreatedAt = DateTime.Now, LastModifiedAt = DateTime.Now, IsDeleted = false, SampleStatus = anReport3.SampleStatus, ScreeningSampleTestStatus = _screeningTest.Name }, new() { AnalysisReportNo = "DuplicateSampleIdOf" + anReport1.AnalyseReportNo, SampleId = anReport1.SampleId + "BlaBla", DateOfSampleCollection = "06/06/2024", DateOfSampleReceiving = "06/06/2024", DateOfSampleAnalysis = new DateTime(2024, 06, 06), SamplingLocationName = "Location A", TestingLaboratoryLocationName = _testingLab.Name, SampleSourceName = "Source A", NatureOfSampleName = "Oil", DeviceName = "Device A", TestingLaboratory = 2, DieselPercentInTheSample = (decimal)1.2, SampleRemark = "Remark A", PartnerName = "name", CreatedAt = DateTime.Now, LastModifiedAt = DateTime.Now, IsDeleted = false, SampleStatus = SampleStatus.Final, ScreeningSampleTestStatus = _screeningTest.Name }, // failed samples because of failed partner and because of string that are too long new() { AnalysisReportNo = "ReportNo103", SampleId = "Sample103", DateOfSampleCollection = "06/06/2024", DateOfSampleReceiving = "06/06/2024", DateOfSampleAnalysis = new DateTime(2024, 06, 06), SamplingLocationName = "Location A", TestingLaboratoryLocationName = _testingLab.Name, SampleSourceName = "Source A", NatureOfSampleName = "Oil", DeviceName = "Device A", TestingLaboratory = 2, DieselPercentInTheSample = 10.5M, SampleRemark = "Remark A", PartnerName = failedPartner, CreatedAt = DateTime.Now, LastModifiedAt = DateTime.Now, IsDeleted = false, ScreeningSampleTestStatus = _screeningTest.Name }, new() { AnalysisReportNo = tooLongString, SampleId = tooLongString, DateOfSampleCollection = "06/06/2024", DateOfSampleReceiving = "06/06/2024", DateOfSampleAnalysis = new DateTime(2024, 06, 06), SamplingLocationName = "Location A", TestingLaboratoryLocationName = _testingLab.Name, SampleSourceName = "Source A", NatureOfSampleName = "Oil", DeviceName = "Device A", TestingLaboratory = 5, DieselPercentInTheSample = 10.5M, SampleRemark = "Remark A", PartnerName = tooLongString, CreatedAt = DateTime.Now, LastModifiedAt = DateTime.Now, IsDeleted = false, ScreeningSampleTestStatus = _screeningTest.Name }, }; } private async Task<CreateAnalysisReport.Response> CreateAnalysisReport( GetSingleWarehouseSetup.Response warehouseSetup, CreateAnalysisReport.CommandResultVisibilities commandResultVisibilities, CreateAnalysisReport.CommandResultSigns commandResultSigns, CreateAnalysisReport.CommandResultValues commandResultValues, string sampleId, SampleStatus sampleStatus) { var anReportResponseMessage = await HttpClient.CreateAnalysisReport(DateTime.UtcNow, sampleId, DateTime.UtcNow, DateTime.UtcNow, DateTime.UtcNow, "samplingLocationName", "testingLaboratoryLocationName", "sampleSourceName", "natureOfSampleName", "deviceName", TestingLaboratory.Stationary, 11, ResultSign.EqualTo, "sampleRemark", "otherRemark", _partner.Id, warehouseSetup.SicpaWorkerId, warehouseSetup.SicpaWorkerId, null, _testingLab.Id, [_screeningTest.Id], AnalysisStatus.CompleteNonAuthorized, commandResultVisibilities, commandResultSigns, commandResultValues, sampleStatus); return await ApiCallerHelper.ParseResponse<CreateAnalysisReport.Response>(anReportResponseMessage); } private static CreateAnalysisReport.CommandResultValues PrepareCommandResultValues() { return new CreateAnalysisReport.CommandResultValues(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); } private static CreateAnalysisReport.CommandResultSigns PrepareCommandResultSigns() { return new CreateAnalysisReport.CommandResultSigns(ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo, ResultSign.EqualTo); } private static CreateAnalysisReport.CommandResultVisibilities PrepareCommandResultVisibilities() { return new CreateAnalysisReport.CommandResultVisibilities(false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false); } }
Editor is loading...
Leave a Comment