Skip to content

Commit df429d6

Browse files
committed
Add tests for query parameters in GetAllSubmodelElementsAsync method
1 parent a45f121 commit df429d6

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

example/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ services:
3232
context: ../source
3333
dockerfile: ./AAS.TwinEngine.DataEngine/Dockerfile
3434
container_name: twinengine-dataengine
35+
ports:
36+
- "8087:8080"
3537
depends_on:
3638
dpp-plugin:
3739
condition: service_started

source/AAS.TwinEngine.DataEngine.ModuleTests/Api/Services/SubmodelRepository/GetAllSubmodelElementsControllerTests.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,34 @@ public async Task GetAllSubmodelElementsAsync_WithExtentQueryParam_ReturnsOkAsyn
215215
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
216216
}
217217

218+
[Fact]
219+
public async Task GetAllSubmodelElementsAsync_WithLevelAndExtentQueryParams_PassesQueryOptionsToServiceAsync()
220+
{
221+
// Arrange
222+
var elementList = new SubmodelElementsPage
223+
{
224+
PagingMetaData = new PagingMetaData { Cursor = null },
225+
Result = []
226+
};
227+
228+
_ = _mockSubmodelRepositoryService
229+
.GetAllSubmodelElementsAsync(SubmodelId, Arg.Any<SubmodelQueryOptions?>(), null, null, Arg.Any<CancellationToken>())
230+
.Returns(elementList);
231+
232+
// Act
233+
var response = await _client.GetAsync(GetUrl() + "?level=deep&extent=withBlobValue");
234+
235+
// Assert
236+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
237+
await _mockSubmodelRepositoryService.Received(1)
238+
.GetAllSubmodelElementsAsync(
239+
SubmodelId,
240+
Arg.Is<SubmodelQueryOptions?>(q => q is not null && q.Level == "deep" && q.Extent == "withBlobValue"),
241+
null,
242+
null,
243+
Arg.Any<CancellationToken>());
244+
}
245+
218246
[Fact]
219247
public async Task GetAllSubmodelElementsAsync_ResponseBodyContainsResultAndPagingMetadata_Async()
220248
{
@@ -252,6 +280,43 @@ public async Task GetAllSubmodelElementsAsync_WithInvalidLimit_Returns400Async(i
252280
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
253281
}
254282

283+
[Fact]
284+
public async Task GetAllSubmodelElementsAsync_WithInvalidCursorEncoding_Returns400Async()
285+
{
286+
// Arrange
287+
const string InvalidCursor = "not!!valid!!base64";
288+
289+
// Act
290+
var response = await _client.GetAsync(GetUrl() + $"?cursor={InvalidCursor}");
291+
292+
// Assert
293+
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
294+
}
295+
296+
[Theory]
297+
[InlineData("notALevel")]
298+
[InlineData("123")]
299+
public async Task GetAllSubmodelElementsAsync_WithInvalidLevelEnum_Returns400Async(string invalidLevel)
300+
{
301+
// Act
302+
var response = await _client.GetAsync(GetUrl() + $"?level={invalidLevel}");
303+
304+
// Assert
305+
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
306+
}
307+
308+
[Theory]
309+
[InlineData("invalid")]
310+
[InlineData("noBlobValue")]
311+
public async Task GetAllSubmodelElementsAsync_WithInvalidExtentEnum_Returns400Async(string invalidExtent)
312+
{
313+
// Act
314+
var response = await _client.GetAsync(GetUrl() + $"?extent={invalidExtent}");
315+
316+
// Assert
317+
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
318+
}
319+
255320
[Fact]
256321
public async Task GetAllSubmodelElementsAsync_WithInvalidBase64SubmodelId_Returns400Async()
257322
{

0 commit comments

Comments
 (0)