Skip to content

Commit 11ba35c

Browse files
authored
Merge branch 'main' into feat/DTOSS-7872-HealthCheck-CreateException
2 parents 1817090 + 6375999 commit 11ba35c

3 files changed

Lines changed: 116 additions & 5 deletions

File tree

application/CohortManager/src/Functions/screeningDataServices/ExcludedSMULookupDataService/ExcludedSMULookupDataServices.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ namespace ExcludedSMULookupDataService;
22

33
using Microsoft.Azure.Functions.Worker;
44
using Microsoft.Extensions.Logging;
5-
using DataServices.Database;
6-
using System.Text.Json;
75
using Microsoft.Azure.Functions.Worker.Http;
86
using System.Net;
97
using Common;

tests/UnitTests/DataServiceTests/DataServiceTests.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
</ItemGroup>
2424

2525
<ItemGroup>
26-
<ProjectReference Include="../../../application/CohortManager/src/Functions/screeningDataServices/ScreeningLkpDataService/ScreeningLkpDataService.csproj" />
27-
<ProjectReference Include="../../../application/CohortManager/src/Functions/screeningDataServices/CohortDistributionDataService/CohortDistributionDataService.csproj" />
28-
<ProjectReference Include="../../../application/CohortManager/src/Functions/screeningDataServices/ExceptionManagementDataService/ExceptionManagementDataService.csproj" />
26+
<ProjectReference Include="..\..\..\application\CohortManager\src\Functions\screeningDataServices\ScreeningLkpDataService\ScreeningLkpDataService.csproj" />
27+
<ProjectReference Include="..\..\..\application\CohortManager\src\Functions\screeningDataServices\CohortDistributionDataService\CohortDistributionDataService.csproj" />
28+
<ProjectReference Include="..\..\..\application\CohortManager\src\Functions\screeningDataServices\ExceptionManagementDataService\ExceptionManagementDataService.csproj" />
29+
<ProjectReference Include="..\..\..\application\CohortManager\src\Functions\screeningDataServices\ExcludedSMULookupDataService\ExcludedSMULookupDataServices.csproj" />
2930
<ProjectReference Include="..\..\..\application\CohortManager\src\Functions\screeningDataServices\BsSelectOutCode\BsSelectOutCode.csproj" />
3031
<ProjectReference Include="..\..\..\application\CohortManager\src\Functions\screeningDataServices\BsSelectGpPractice\BsSelectGpPractice.csproj" />
3132
<ProjectReference Include="..\..\..\application\CohortManager\src\Functions\screeningDataServices\CurrentPostingDataService\CurrentPosting.csproj" />
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
namespace DataServiceTests;
2+
3+
using ExcludedSMULookupDataService;
4+
using Common;
5+
using DataServices.Core;
6+
using Microsoft.Extensions.Logging;
7+
using Model;
8+
using Moq;
9+
using NHS.CohortManager.Tests.TestUtils;
10+
using System.Net;
11+
using Microsoft.Azure.Functions.Worker;
12+
using FluentAssertions;
13+
14+
[TestClass]
15+
public class ExcludedSMULookupDataServiceTests
16+
{
17+
private readonly Mock<ILogger<ExcludedSMULookupDataService>> _mockFunctionLogger = new();
18+
private readonly Mock<ILogger<RequestHandler<ExcludedSMULookup>>> _mockRequestHandlerLogger = new();
19+
private readonly CreateResponse _createResponse = new();
20+
private readonly Mock<FunctionContext> _context = new();
21+
private readonly MockDataServiceAccessor<ExcludedSMULookup> _dataServiceAccessor;
22+
private readonly List<ExcludedSMULookup> _mockData;
23+
private AuthenticationConfiguration _authenticationConfiguration;
24+
25+
public ExcludedSMULookupDataServiceTests()
26+
{
27+
_mockData = new List<ExcludedSMULookup>{
28+
new ExcludedSMULookup{
29+
GpPracticeCode = "ABC"
30+
},
31+
new ExcludedSMULookup{
32+
GpPracticeCode = "DEF"
33+
}
34+
};
35+
_dataServiceAccessor = new MockDataServiceAccessor<ExcludedSMULookup>(_mockData);
36+
_authenticationConfiguration = DataServiceTestHelper.AllowAllAccessConfig;
37+
}
38+
39+
#region Get By Id
40+
[DataRow("ABC")]
41+
[DataRow("DEF")]
42+
[TestMethod]
43+
public async Task RunAsync_GetItemById_ReturnsCorrectItems(string gpPracticeCode)
44+
{
45+
// Arrange
46+
var _requestHandler = new RequestHandler<ExcludedSMULookup>(_dataServiceAccessor, _mockRequestHandlerLogger.Object, _authenticationConfiguration);
47+
ExcludedSMULookupDataService function = new ExcludedSMULookupDataService(_mockFunctionLogger.Object, _requestHandler, _createResponse);
48+
var req = new MockHttpRequestData(_context.Object, "", "GET");
49+
50+
// Act
51+
var result = await function.Run(req, gpPracticeCode);
52+
53+
// Assert
54+
var expectedPractice = _mockData.Single(i => i.GpPracticeCode == gpPracticeCode);
55+
var resultObject = await MockHelpers.GetResponseBodyAsObject<ExcludedSMULookup>(result);
56+
57+
Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
58+
resultObject.Should().BeEquivalentTo(expectedPractice);
59+
}
60+
61+
[DataRow("ABC")]
62+
[TestMethod]
63+
public async Task RunAsync_GetItemByIdNotAllowed_Returns401(string gpPracticeCode)
64+
{
65+
// Arrange
66+
_authenticationConfiguration = DataServiceTestHelper.DenyAllAccessConfig;
67+
var _requestHandler = new RequestHandler<ExcludedSMULookup>(_dataServiceAccessor, _mockRequestHandlerLogger.Object, _authenticationConfiguration);
68+
ExcludedSMULookupDataService function = new ExcludedSMULookupDataService(_mockFunctionLogger.Object, _requestHandler, _createResponse);
69+
var req = new MockHttpRequestData(_context.Object, "", "GET");
70+
71+
// Act
72+
var result = await function.Run(req, gpPracticeCode);
73+
74+
// Assert
75+
Assert.AreEqual(HttpStatusCode.Unauthorized, result.StatusCode);
76+
}
77+
78+
[DataRow("GHI")]
79+
[TestMethod]
80+
public async Task RunAsync_GetItemByIdNonExistent_ReturnsNotFound(string gpPracticeCode)
81+
{
82+
// Arrange
83+
var _requestHandler = new RequestHandler<ExcludedSMULookup>(_dataServiceAccessor, _mockRequestHandlerLogger.Object, _authenticationConfiguration);
84+
ExcludedSMULookupDataService function = new ExcludedSMULookupDataService(_mockFunctionLogger.Object, _requestHandler, _createResponse);
85+
var req = new MockHttpRequestData(_context.Object, "", "GET");
86+
87+
// Act
88+
var result = await function.Run(req, gpPracticeCode);
89+
90+
// Assert
91+
Assert.AreEqual(HttpStatusCode.NotFound, result.StatusCode);
92+
}
93+
#endregion
94+
95+
#region Exception
96+
[TestMethod]
97+
public async Task RunAsync_GetItemByIdWithInvalidMethod_ReturnsInternalServerError()
98+
{
99+
// Arrange
100+
var invalidMethod = string.Empty;
101+
var _requestHandler = new RequestHandler<ExcludedSMULookup>(_dataServiceAccessor, _mockRequestHandlerLogger.Object, _authenticationConfiguration);
102+
ExcludedSMULookupDataService function = new ExcludedSMULookupDataService(_mockFunctionLogger.Object, _requestHandler, _createResponse);
103+
var req = new MockHttpRequestData(_context.Object, "", invalidMethod);
104+
105+
// Act
106+
var result = await function.Run(req, null);
107+
108+
// Assert
109+
Assert.AreEqual(HttpStatusCode.InternalServerError, result.StatusCode);
110+
}
111+
#endregion
112+
}

0 commit comments

Comments
 (0)