-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStaticValidationTests.cs
More file actions
749 lines (641 loc) · 25.8 KB
/
StaticValidationTests.cs
File metadata and controls
749 lines (641 loc) · 25.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
namespace NHS.CohortManager.Tests.UnitTests.ScreeningValidationServiceTests;
using System.Net;
using System.Text;
using System.Text.Json;
using Common;
using Common.Interfaces;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Model;
using Model.Enums;
using Moq;
using NHS.CohortManager.ScreeningValidationService;
using RulesEngine.Models;
using NHS.CohortManager.Tests.TestUtils;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Logging.Abstractions;
[TestClass]
public class StaticValidationTests
{
private readonly Mock<ILogger<StaticValidation>> _logger = new();
private readonly Mock<FunctionContext> _context = new();
private readonly Mock<HttpRequestData> _request;
private readonly CreateResponse _createResponse = new();
private readonly ServiceCollection _serviceCollection = new();
private readonly ParticipantCsvRecord _participantCsvRecord;
private readonly StaticValidation _function;
public StaticValidationTests()
{
_request = new Mock<HttpRequestData>(_context.Object);
var serviceProvider = _serviceCollection.BuildServiceProvider();
_context.SetupProperty(c => c.InstanceServices, serviceProvider);
_function = new StaticValidation(
_logger.Object,
_createResponse,
new ReadRules(new NullLogger<ReadRules>())
);
_request.Setup(r => r.CreateResponse()).Returns(() =>
{
var response = new Mock<HttpResponseData>(_context.Object);
response.SetupProperty(r => r.Headers, new HttpHeadersCollection());
response.SetupProperty(r => r.StatusCode);
response.SetupProperty(r => r.Body, new MemoryStream());
return response.Object;
});
_participantCsvRecord = new ParticipantCsvRecord()
{
FileName = "test",
Participant = new Participant()
{
ScreeningName = "Breast Screening",
NhsNumber = "1211111881",
RecordType = Actions.New,
AddressLine1 = "Address1",
AddressLine2 = "Address2",
AddressLine3 = "Address3",
AddressLine4 = "Address4",
AddressLine5 = "Address5",
PrimaryCareProvider = "E85121",
DateOfBirth = "20130112",
FirstName = "Test",
FamilyName = "Test",
InvalidFlag = "0",
IsInterpreterRequired = "0",
CurrentPosting = "ABC",
EligibilityFlag = "1",
ReferralFlag = "false"
}
};
}
[TestMethod]
public async Task Run_Should_Return_InternalServerError_When_Request_Body_Empty()
{
// Act
var response = await _function.RunAsync(_request.Object);
// Assert
Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
}
[TestMethod]
public async Task Run_Should_Return_InternalServerError_When_Request_Body_Invalid()
{
// Arrange
SetUpRequestBody("Invalid request body");
// Act
var response = await _function.RunAsync(_request.Object);
// Assert
Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
}
[TestMethod]
public async Task Run_ParticipantReferred_DoNotRunRoutineRules()
{
// Arrange
_participantCsvRecord.Participant.ReferralFlag = "true";
_participantCsvRecord.Participant.PrimaryCareProvider = "ABC";
_participantCsvRecord.Participant.ReasonForRemoval = "123";
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
[TestMethod]
public async Task Run_ParticipantReferred_RunCommonRules()
{
// Arrange
_participantCsvRecord.Participant.ReferralFlag = "true";
_participantCsvRecord.Participant.Postcode = "ZzZ99 LZ";
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
string body = await AssertionHelper.ReadResponseBodyAsync(response);
// Assert
StringAssert.Contains(body, "30.Postcode.NBO.NonFatal");
}
#region Record Type (Rule 8)
[TestMethod]
[DataRow(Actions.New, "1")]
[DataRow(Actions.Amended, "1")]
[DataRow(Actions.Removed, "0")]
public async Task Run_ValidRecordType_ReturnNoContent(string recordType, string eligibilityFlag)
{
// Arrange
_participantCsvRecord.Participant.RecordType = recordType;
_participantCsvRecord.Participant.EligibilityFlag = eligibilityFlag;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
[TestMethod]
[DataRow(null)]
[DataRow("")]
[DataRow("Newish")]
public async Task Run_InvalidRecordType_ReturnValidationException(string recordType)
{
// Arrange
_participantCsvRecord.Participant.RecordType = recordType;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
string body = await AssertionHelper.ReadResponseBodyAsync(response);
// Assert
StringAssert.Contains(body, "8.RecordType.CaaS.NonFatal");
}
#endregion
[TestMethod]
public async Task Run_DelRecord_DoNotRunCommonRules()
{
// Arrange
_participantCsvRecord.Participant.RecordType = Actions.Removed;
_participantCsvRecord.Participant.EligibilityFlag = "0";
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
#region Postcode (Rule 30)
[TestMethod]
[DataRow("ec1a1bb")]
[DataRow("EC1A1BB")]
[DataRow("ec1a 1bb")]
[DataRow("EC1A 1BB")]
[DataRow("W1A 0AX")]
[DataRow("M1 1AE")]
[DataRow("B33 8TH")]
[DataRow("CR2 6XH")]
[DataRow("LS10 1LT")]
[DataRow("GIR 0AA")]
[DataRow("GIR0AA")]
[DataRow("")]
[DataRow(null)]
// Dummy Postcodes
[DataRow("ZZ99 9FZ")]
[DataRow("ZZ999FZ")]
[DataRow("ZZ99 3WZ")]
[DataRow("ZZZSECUR")]
public async Task Run_ValidPostcode_ReturnNoContent(string postcode)
{
// Arrange
_participantCsvRecord.Participant.Postcode = postcode;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
[TestMethod]
[DataRow("ABC123")]
[DataRow("1234 AB")]
[DataRow("AA 12345")]
[DataRow("A1B 1CDE")]
[DataRow("A1A@1AA")]
[DataRow("ZZ9 4LZ")]
[DataRow("Z99 4")]
[DataRow("ZzZ99 LZ")]
public async Task Run_InvalidPostcode_ReturnValidationException(string postcode)
{
// Arrange
_participantCsvRecord.Participant.Postcode = postcode;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
string body = await AssertionHelper.ReadResponseBodyAsync(response);
// Assert
StringAssert.Contains(body, "30.Postcode.NBO.NonFatal");
}
#endregion
#region NewParticipantWithNoAddress (Rule 19)
[TestMethod]
public async Task Run_AddWithAdress_ReturnNoContent()
{
// Arrange
_participantCsvRecord.Participant.RecordType = Actions.New;
_participantCsvRecord.Participant.AddressLine1 = "SomeAddress";
_participantCsvRecord.Participant.AddressLine2 = "";
_participantCsvRecord.Participant.AddressLine3 = "";
_participantCsvRecord.Participant.AddressLine4 = "";
_participantCsvRecord.Participant.AddressLine5 = "";
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
[TestMethod]
public async Task Run_AddWithEmptyAddress_ReturnValidationException()
{
// Arrange
_participantCsvRecord.Participant.RecordType = Actions.New;
_participantCsvRecord.Participant.AddressLine1 = "";
_participantCsvRecord.Participant.AddressLine2 = "";
_participantCsvRecord.Participant.AddressLine3 = "";
_participantCsvRecord.Participant.AddressLine4 = "";
_participantCsvRecord.Participant.AddressLine5 = "";
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
string body = await AssertionHelper.ReadResponseBodyAsync(response);
// Assert
StringAssert.Contains(body, "71.NewParticipantWithNoAddress.NBO.NonFatal");
}
[TestMethod]
public async Task Run_AmendWithEmptyAddress_ReturnNoContent()
{
// Arrange
_participantCsvRecord.Participant.RecordType = Actions.Amended;
_participantCsvRecord.Participant.AddressLine1 = "";
_participantCsvRecord.Participant.AddressLine2 = "";
_participantCsvRecord.Participant.AddressLine3 = "";
_participantCsvRecord.Participant.AddressLine4 = "";
_participantCsvRecord.Participant.AddressLine5 = "";
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
#endregion
#region Primary Care Provider and Reason For Removal (Rule 3)
[TestMethod]
[DataRow("ABC", null)]
[DataRow(null, "123")]
public async Task Run_CompatiblePcpAndRfr_ReturnNoContent(string primaryCareProvider, string reasonForRemoval)
{
// Arrange
_participantCsvRecord.Participant.RecordType = Actions.Amended;
_participantCsvRecord.Participant.PrimaryCareProvider = primaryCareProvider;
_participantCsvRecord.Participant.ReasonForRemoval = reasonForRemoval;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
[TestMethod]
[DataRow(null, null)]
[DataRow("ABC", "123")]
public async Task Run_IncompatiblePcpAndRfr_ReturnValidationException(string primaryCareProvider, string reasonForRemoval)
{
// Arrange
_participantCsvRecord.Participant.PrimaryCareProvider = primaryCareProvider;
_participantCsvRecord.Participant.ReasonForRemoval = reasonForRemoval;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
string body = await AssertionHelper.ReadResponseBodyAsync(response);
// Assert
StringAssert.Contains(body, "3.PrimaryCareProviderAndReasonForRemoval.NBO.NonFatal");
}
#endregion
#region Date Of Birth (Rule 17)
[TestMethod]
[DataRow("19700101")] // ccyymmdd
[DataRow("197001")] // ccyymm
[DataRow("1970")] // ccyy
public async Task Run_ValidDateOfBirth_ReturnNoContent(string dateOfBirth)
{
// Arrange
_participantCsvRecord.Participant.DateOfBirth = dateOfBirth;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
[TestMethod]
[DataRow(null)]
[DataRow("")]
[DataRow("20700101")] // In the future
[DataRow("19700229")] // Not a real date (1970 was not a leap year)
[DataRow("1970023")] // Incorrect format
[DataRow("197013")] // Not a real date or incorrect format
public async Task Run_InvalidDateOfBirth_ReturnValidationException(string dateOfBirth)
{
// Arrange
_participantCsvRecord.Participant.DateOfBirth = dateOfBirth;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
string body = await AssertionHelper.ReadResponseBodyAsync(response);
// Assert
StringAssert.Contains(body, "17.DateOfBirth.NBO.NonFatal");
}
#endregion
#region Family Name (Rule 39)
[TestMethod]
[DataRow("Li")]
[DataRow("McDonald")]
[DataRow("O'Neill")]
[DataRow("Zeta-Jones")]
[DataRow("Bonham Carter")]
[DataRow("Venkatasubramanian")]
public async Task Run_ValidFamilyName_ReturnNoContent(string familyName)
{
// Arrange
_participantCsvRecord.Participant.RecordType = Actions.New;
_participantCsvRecord.Participant.FamilyName = familyName;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
[TestMethod]
[DataRow(null)]
[DataRow("")]
public async Task Run_InvalidFamilyName_ReturnValidationException(string familyName)
{
// Arrange
_participantCsvRecord.Participant.RecordType = Actions.New;
_participantCsvRecord.Participant.FamilyName = familyName;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
string body = await AssertionHelper.ReadResponseBodyAsync(response);
// Assert
StringAssert.Contains(body, "39.FamilyName.NBO.NonFatal");
}
#endregion
#region Given Name (Rule 40)
[TestMethod]
[DataRow("Jo")]
[DataRow("Jean-Luc")]
[DataRow("Sarah Jane")]
[DataRow("Bartholomew")]
public async Task Run_ValidFirstName_ReturnNoContent(string givenName)
{
// Arrange
_participantCsvRecord.Participant.RecordType = Actions.New;
_participantCsvRecord.Participant.FirstName = givenName;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
[TestMethod]
[DataRow(null)]
[DataRow("")]
public async Task Run_InvalidFirstName_ReturnValidationExceptions(string firstName)
{
// Arrange
_participantCsvRecord.Participant.RecordType = Actions.New;
_participantCsvRecord.Participant.FirstName = firstName;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
string body = await AssertionHelper.ReadResponseBodyAsync(response);
// Assert
StringAssert.Contains(body, "40.FirstName.NBO.NonFatal");
}
#endregion
#region Death Status (Rule 66)
[TestMethod]
[DataRow("AMENDED", Status.Formal, "DEA")]
public async Task Run_ValidDeathStatus_ReturnNoContent(string recordType, Status deathStatus, string reasonForRemoval)
{
// Arrange
_participantCsvRecord.Participant.RecordType = recordType;
_participantCsvRecord.Participant.DeathStatus = deathStatus;
_participantCsvRecord.Participant.ReasonForRemoval = reasonForRemoval;
_participantCsvRecord.Participant.PrimaryCareProvider = null;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
[TestMethod]
[DataRow("AMENDED", Status.Formal, null)]
[DataRow("AMENDED", Status.Formal, "")]
[DataRow("AMENDED", Status.Formal, "AFL")]
public async Task Run_InvalidDeathStatus_ReturnValidationException(string recordType, Status deathStatus, string reasonForRemoval)
{
// Arrange
_participantCsvRecord.Participant.RecordType = recordType;
_participantCsvRecord.Participant.DeathStatus = deathStatus;
_participantCsvRecord.Participant.ReasonForRemoval = reasonForRemoval;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
string body = await AssertionHelper.ReadResponseBodyAsync(response);
// Assert
StringAssert.Contains(body, "66.DeathStatus.NBO.NonFatal");
}
#endregion
#region Date Of Death (Rule 18)
[TestMethod]
[DataRow(null)]
[DataRow("")]
[DataRow("19700101")] // ccyymmdd
[DataRow("197001")] // ccyymm
[DataRow("1970")] // ccyy
public async Task Run_ValidDateOfDeath_ReturnNoContent(string date)
{
// Arrange
_participantCsvRecord.Participant.RecordType = Actions.Amended;
_participantCsvRecord.Participant.DateOfDeath = date;
_participantCsvRecord.Participant.EligibilityFlag = "0";
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
[TestMethod]
[DataRow("20700101")] // In the future
[DataRow("19700229")] // Not a real date (1970 was not a leap year)
[DataRow("1970023")] // Incorrect format
[DataRow("197013")] // Not a real date or incorrect format
public async Task Run_InvalidDateOfDeath_ReturnValidationException(string date)
{
// Arrange
_participantCsvRecord.Participant.RecordType = Actions.Amended;
_participantCsvRecord.Participant.DateOfDeath = date;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
string body = await AssertionHelper.ReadResponseBodyAsync(response);
// Assert
StringAssert.Contains(body, "18.DateOfDeath.NBO.NonFatal");
}
#endregion
#region IsInterpreterRequired (Rule 49)
[TestMethod]
[DataRow("1")]
[DataRow("0")]
public async Task Run_ValidInterpreterRequiredFlag_ReturnNoContent(string isInterpreterRequired)
{
// Arrange
_participantCsvRecord.Participant.IsInterpreterRequired = isInterpreterRequired;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
[TestMethod]
[DataRow(null)]
[DataRow("ABC")]
public async Task Run_InvalidInterpreterRequiredFlag_ReturnValidationExcpetion(string isInterpreterRequired)
{
// Arrange
_participantCsvRecord.Participant.IsInterpreterRequired = isInterpreterRequired;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
string body = await AssertionHelper.ReadResponseBodyAsync(response);
// Assert
StringAssert.Contains(body, "49.InterpreterCheck.NBO.NonFatal");
}
#endregion
#region Validate Reason For Removal (Rule 62)
[TestMethod]
[DataRow("123456", "LDN", null)]
[DataRow(null, "ABC", null)]
[DataRow(null, null, "EC12AB")]
public async Task Run_ValidRfr_ReturnNoContent(string? supersededByNhsNumber, string? ReasonForRemoval, string? pcp)
{
// Arrange
_participantCsvRecord.Participant.SupersededByNhsNumber = supersededByNhsNumber;
_participantCsvRecord.Participant.ReasonForRemoval = ReasonForRemoval;
_participantCsvRecord.Participant.PrimaryCareProvider = pcp;
_participantCsvRecord.Participant.RecordType = Actions.Amended;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
[TestMethod]
[DataRow(null, "LDN")]
public async Task Run_InvalidRfr_ReturnValidationException(string? supersededByNhsNumber, string ReasonForRemoval)
{
// Arrange
_participantCsvRecord.Participant.SupersededByNhsNumber = supersededByNhsNumber;
_participantCsvRecord.Participant.ReasonForRemoval = ReasonForRemoval;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
string body = await AssertionHelper.ReadResponseBodyAsync(response);
// Assert
StringAssert.Contains(body, "62.ValidateReasonForRemoval.NBO.NonFatal");
}
#endregion
private void SetUpRequestBody(string json)
{
var byteArray = Encoding.ASCII.GetBytes(json);
var bodyStream = new MemoryStream(byteArray);
_request.Setup(r => r.Body).Returns(bodyStream);
}
#region Supplied Posting is Null Validation (Rule 53)
[TestMethod]
[DataRow(null, "E85121")]
public async Task Run_IncompatibleCurrentPostingAndPrimaryCareProvider_ReturnValidationException(string? currentPosting, string? primaryCareProvider)
{
// Arrange
_participantCsvRecord.Participant.CurrentPosting = currentPosting;
_participantCsvRecord.Participant.PrimaryCareProvider = primaryCareProvider;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
string body = await AssertionHelper.ReadResponseBodyAsync(response);
// Assert
StringAssert.Contains(body, "53.CurrentPostingAndPrimaryCareProvider.NBO.NonFatal");
}
[TestMethod]
[DataRow("BAA", "E85121", null)]
[DataRow("BAA", null, "DEA")]
[DataRow(null, null, "DEA")]
public async Task Run_CompatibleCurrentPostingAndPrimaryCareProvider_ReturnNoContent(string? currentPosting, string? primaryCareProvider, string? rfr)
{
// Arrange
_participantCsvRecord.Participant.CurrentPosting = currentPosting;
_participantCsvRecord.Participant.PrimaryCareProvider = primaryCareProvider;
_participantCsvRecord.Participant.ReasonForRemoval = rfr;
_participantCsvRecord.Participant.RecordType = Actions.Amended;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
#endregion
#region Validate Eligibility Flag as per Record Type (Rule 94)
[TestMethod]
[DataRow(Actions.New, "0")]
[DataRow(Actions.Removed, "1")]
public async Task Run_InvalidEligibilityFlag_ReturnValidationException(string recordType, string eligibilityFlag)
{
// Arrange
_participantCsvRecord.Participant.RecordType = recordType;
_participantCsvRecord.Participant.EligibilityFlag = eligibilityFlag;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
string body = await AssertionHelper.ReadResponseBodyAsync(response);
// Assert
StringAssert.Contains(body, "94.EligibilityFlag.CaaS.NonFatal");
}
[TestMethod]
[DataRow(Actions.New, "1")]
[DataRow(Actions.Removed, "0")]
[DataRow(Actions.Amended, "1")]
public async Task Run_ValidEligibilityFlag_ReturnNoContent(string recordType, string eligibilityFlag)
{
// Arrange
_participantCsvRecord.Participant.RecordType = recordType;
_participantCsvRecord.Participant.EligibilityFlag = eligibilityFlag;
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
#endregion
[TestMethod]
public async Task Run_ValidParticipantFile_ReturnNoContent()
{
// Arrange
var json = JsonSerializer.Serialize(_participantCsvRecord);
SetUpRequestBody(json);
// Act
var response = await _function.RunAsync(_request.Object);
// Assert
Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
}
}