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

Commit 8b319ef

Browse files
test: Added more tests
1 parent fec852b commit 8b319ef

1 file changed

Lines changed: 75 additions & 4 deletions

File tree

tests/ServiceLayer.Mesh.Tests/FileTypes/NbssAppointmentEvents/StagingPersisterTests.cs

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ public class NbssAppointmentEventsTests
1313
public NbssAppointmentEventsTests()
1414
{
1515
var options = new DbContextOptionsBuilder<ServiceLayerDbContext>()
16-
.UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
17-
.ConfigureWarnings(warnings =>
18-
warnings.Ignore(Microsoft.EntityFrameworkCore.Diagnostics.InMemoryEventId.TransactionIgnoredWarning))
16+
.UseInMemoryDatabase(Guid.NewGuid().ToString())
1917
.Options;
2018

2119
_dbContext = new ServiceLayerDbContext(options);
@@ -24,7 +22,7 @@ public NbssAppointmentEventsTests()
2422
}
2523

2624
[Fact]
27-
public async Task WriteStagedData_WhenMappingSuceeds_SavesToDb()
25+
public async Task WriteStagedData_WhenFileValid_SavesToDb()
2826
{
2927
// Arrange
3028
var parsedFile = TestDataBuilder.BuildValidParsedFile();
@@ -44,6 +42,7 @@ public async Task WriteStagedData_WhenMappingSuceeds_SavesToDb()
4442

4543
var nbssAppointmentEvent = await _dbContext.NbssAppointmentEvents.FirstAsync();
4644
var dataRecord = parsedFile.DataRecords.First();
45+
Assert.NotEqual(Guid.Empty, nbssAppointmentEvent.Id);
4746
Assert.Equal(meshFile.FileId, nbssAppointmentEvent.MeshFileId);
4847
Assert.Equal(dataRecord["BSO"], nbssAppointmentEvent.BSO);
4948
Assert.Equal(parsedFile.FileTrailer!.ExtractId, nbssAppointmentEvent.ExtractId);
@@ -74,4 +73,76 @@ public async Task WriteStagedData_WhenMappingSuceeds_SavesToDb()
7473
Assert.Equal(dataRecord["Postcode"], nbssAppointmentEvent.ClinicPostcode);
7574
Assert.Equal(DateTime.ParseExact(dataRecord.Fields["Action Timestamp"], "yyyyMMdd-HHmmss", null), nbssAppointmentEvent.ActionTimestamp);
7675
}
76+
77+
[Theory]
78+
[InlineData("BSO")]
79+
[InlineData("Sequence")]
80+
[InlineData("Action")]
81+
[InlineData("Clinic Code")]
82+
[InlineData("Holding Clinic")]
83+
[InlineData("Status")]
84+
[InlineData("Attended Not Scr")]
85+
[InlineData("Appointment ID")]
86+
[InlineData("NHS Num")]
87+
[InlineData("Episode Type")]
88+
[InlineData("Episode Start")]
89+
[InlineData("Batch ID")]
90+
[InlineData("Screen or Asses")]
91+
[InlineData("Screen Appt num")]
92+
[InlineData("Booked By")]
93+
[InlineData("Cancelled By")]
94+
[InlineData("Appt Date")]
95+
[InlineData("Appt Time")]
96+
[InlineData("Location")]
97+
[InlineData("Clinic Name")]
98+
[InlineData("Clinic Name (Let)")]
99+
[InlineData("Clinic Address 1")]
100+
[InlineData("Clinic Address 2")]
101+
[InlineData("Clinic Address 3")]
102+
[InlineData("Clinic Address 4")]
103+
[InlineData("Clinic Address 5")]
104+
[InlineData("Postcode")]
105+
[InlineData("Action Timestamp")]
106+
public async Task WriteStagedData_WhenFieldMissing_DoesNotSaveToDb(string fieldName)
107+
{
108+
// Arrange
109+
var parsedFile = TestDataBuilder.BuildValidParsedFile();
110+
var recordWithoutBSO = TestDataBuilder.BuildFileDataRecordWithField(fieldName, null, 1);
111+
parsedFile.DataRecords.Add(recordWithoutBSO);
112+
var meshFile = new MeshFile()
113+
{
114+
FileId = "1",
115+
FileType = MeshFileType.NbssAppointmentEvents,
116+
MailboxId = "ABC",
117+
Status = MeshFileStatus.Transforming
118+
};
119+
120+
// Act & Assert
121+
var exception = await Assert.ThrowsAsync<KeyNotFoundException>(async () => await _stagingPersister.WriteStagedData(parsedFile, meshFile));
122+
Assert.Equal(0, await _dbContext.NbssAppointmentEvents.CountAsync());
123+
}
124+
125+
[Theory]
126+
[InlineData("Episode Start")]
127+
[InlineData("Screen Appt num")]
128+
[InlineData("Appt Date")]
129+
[InlineData("Appt Time")]
130+
public async Task WriteStagedData_WhenFieldHoldsInvalidValue_DoesNotSaveToDb(string fieldName)
131+
{
132+
// Arrange
133+
var parsedFile = TestDataBuilder.BuildValidParsedFile();
134+
var recordWithoutBSO = TestDataBuilder.BuildFileDataRecordWithField(fieldName, "Invalid value", 1);
135+
parsedFile.DataRecords.Add(recordWithoutBSO);
136+
var meshFile = new MeshFile()
137+
{
138+
FileId = "1",
139+
FileType = MeshFileType.NbssAppointmentEvents,
140+
MailboxId = "ABC",
141+
Status = MeshFileStatus.Transforming
142+
};
143+
144+
// Act & Assert
145+
var exception = await Assert.ThrowsAsync<FormatException>(async () => await _stagingPersister.WriteStagedData(parsedFile, meshFile));
146+
Assert.Equal(0, await _dbContext.NbssAppointmentEvents.CountAsync());
147+
}
77148
}

0 commit comments

Comments
 (0)