Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit fec852b

Browse files
test: Added test for StagingPersister
1 parent 8aee7b6 commit fec852b

2 files changed

Lines changed: 79 additions & 2 deletions

File tree

src/ServiceLayer.Mesh/FileTypes/NbssAppointmentEvents/StagingPersister.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ private static List<NbssAppointmentEvent> MapFileDataRecordsToNbssAppointmentEve
3333
AttendedNotScreened = record.Fields["Attended Not Scr"],
3434
AppointmenId = record.Fields["Appointment ID"],
3535
NhsNumber = record.Fields["NHS Num"],
36-
EpisodeType = record.Fields["Epsiode Type"],
36+
EpisodeType = record.Fields["Episode Type"],
3737
EpisodeStart = DateOnly.ParseExact(record.Fields["Episode Start"], "yyyyMMdd"),
38-
BatchId = record.Fields["BatchID"],
38+
BatchId = record.Fields["Batch ID"],
3939
AppointmentType = record.Fields["Screen or Asses"],
4040
ScreeningAppointmentNumber = byte.Parse(record.Fields["Screen Appt num"]),
4141
BookedBy = record.Fields["Booked By"],
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using ServiceLayer.Data;
3+
using ServiceLayer.Data.Models;
4+
using ServiceLayer.Mesh.FileTypes.NbssAppointmentEvents;
5+
6+
namespace ServiceLayer.Mesh.Tests.FileTypes.NbssAppointmentEvents;
7+
8+
public class NbssAppointmentEventsTests
9+
{
10+
private readonly ServiceLayerDbContext _dbContext;
11+
private readonly StagingPersister _stagingPersister;
12+
13+
public NbssAppointmentEventsTests()
14+
{
15+
var options = new DbContextOptionsBuilder<ServiceLayerDbContext>()
16+
.UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
17+
.ConfigureWarnings(warnings =>
18+
warnings.Ignore(Microsoft.EntityFrameworkCore.Diagnostics.InMemoryEventId.TransactionIgnoredWarning))
19+
.Options;
20+
21+
_dbContext = new ServiceLayerDbContext(options);
22+
23+
_stagingPersister = new StagingPersister(_dbContext);
24+
}
25+
26+
[Fact]
27+
public async Task WriteStagedData_WhenMappingSuceeds_SavesToDb()
28+
{
29+
// Arrange
30+
var parsedFile = TestDataBuilder.BuildValidParsedFile();
31+
var meshFile = new MeshFile()
32+
{
33+
FileId = "1",
34+
FileType = MeshFileType.NbssAppointmentEvents,
35+
MailboxId = "ABC",
36+
Status = MeshFileStatus.Transforming
37+
};
38+
39+
// Act
40+
await _stagingPersister.WriteStagedData(parsedFile, meshFile);
41+
42+
// Assert
43+
Assert.Equal(3, await _dbContext.NbssAppointmentEvents.CountAsync());
44+
45+
var nbssAppointmentEvent = await _dbContext.NbssAppointmentEvents.FirstAsync();
46+
var dataRecord = parsedFile.DataRecords.First();
47+
Assert.Equal(meshFile.FileId, nbssAppointmentEvent.MeshFileId);
48+
Assert.Equal(dataRecord["BSO"], nbssAppointmentEvent.BSO);
49+
Assert.Equal(parsedFile.FileTrailer!.ExtractId, nbssAppointmentEvent.ExtractId);
50+
Assert.Equal(dataRecord["Sequence"], nbssAppointmentEvent.Sequence);
51+
Assert.Equal(dataRecord["Action"], nbssAppointmentEvent.Action);
52+
Assert.Equal(dataRecord["Clinic Code"], nbssAppointmentEvent.ClinicCode);
53+
Assert.Equal(dataRecord["Holding Clinic"], nbssAppointmentEvent.HoldingClinic);
54+
Assert.Equal(dataRecord["Status"], nbssAppointmentEvent.Status);
55+
Assert.Equal(dataRecord["Attended Not Scr"], nbssAppointmentEvent.AttendedNotScreened);
56+
Assert.Equal(dataRecord["Appointment ID"], nbssAppointmentEvent.AppointmenId);
57+
Assert.Equal(dataRecord["NHS Num"], nbssAppointmentEvent.NhsNumber);
58+
Assert.Equal(dataRecord["Episode Type"], nbssAppointmentEvent.EpisodeType);
59+
Assert.Equal(DateOnly.ParseExact(dataRecord.Fields["Episode Start"], "yyyyMMdd"), nbssAppointmentEvent.EpisodeStart);
60+
Assert.Equal(dataRecord["Batch ID"], nbssAppointmentEvent.BatchId);
61+
Assert.Equal(dataRecord["Screen or Asses"], nbssAppointmentEvent.AppointmentType);
62+
Assert.Equal(byte.Parse(dataRecord.Fields["Screen Appt num"]), nbssAppointmentEvent.ScreeningAppointmentNumber);
63+
Assert.Equal(dataRecord["Booked By"], nbssAppointmentEvent.BookedBy);
64+
Assert.Equal(dataRecord["Cancelled By"], nbssAppointmentEvent.CancelledBy);
65+
Assert.Equal(DateTime.ParseExact(dataRecord.Fields["Appt Date"] + dataRecord.Fields["Appt Time"], "yyyyMMddHHmm", null), nbssAppointmentEvent.AppointmentDateTime);
66+
Assert.Equal(dataRecord["Location"], nbssAppointmentEvent.Location);
67+
Assert.Equal(dataRecord["Clinic Name"], nbssAppointmentEvent.ClinicName);
68+
Assert.Equal(dataRecord["Clinic Name (Let)"], nbssAppointmentEvent.ClinicNameOnLetters);
69+
Assert.Equal(dataRecord["Clinic Address 1"], nbssAppointmentEvent.ClinicAddressLine1);
70+
Assert.Equal(dataRecord["Clinic Address 2"], nbssAppointmentEvent.ClinicAddressLine2);
71+
Assert.Equal(dataRecord["Clinic Address 3"], nbssAppointmentEvent.ClinicAddressLine3);
72+
Assert.Equal(dataRecord["Clinic Address 4"], nbssAppointmentEvent.ClinicAddressLine4);
73+
Assert.Equal(dataRecord["Clinic Address 5"], nbssAppointmentEvent.ClinicAddressLine5);
74+
Assert.Equal(dataRecord["Postcode"], nbssAppointmentEvent.ClinicPostcode);
75+
Assert.Equal(DateTime.ParseExact(dataRecord.Fields["Action Timestamp"], "yyyyMMdd-HHmmss", null), nbssAppointmentEvent.ActionTimestamp);
76+
}
77+
}

0 commit comments

Comments
 (0)