Skip to content

Commit 65dcf8b

Browse files
authored
Fix malformed XML docs in builder interfaces (#22)
1 parent 3685522 commit 65dcf8b

2 files changed

Lines changed: 88 additions & 1 deletion

File tree

FluentAAS/FluentAAS.Builder.Tests/AasBuilderTests.cs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,93 @@ public void AddSubmodelFragment_WithoutBaseSubmodel_ShouldThrowInvalidOperationE
266266
ex.Message.ShouldContain("No base submodel");
267267
}
268268

269+
[Fact]
270+
public void Build_WithShellReferencingKnownSubmodelId_ShouldSucceed()
271+
{
272+
// Arrange
273+
var builder = CreateSut();
274+
var submodelId = _fixture.Create<string>()!;
275+
builder.AddSubmodel(new Submodel(id: submodelId, idShort: "known-submodel"));
276+
277+
var shell = new AssetAdministrationShell(
278+
id: _fixture.Create<string>()!,
279+
assetInformation: new AssetInformation(AssetKind.Instance))
280+
{
281+
IdShort = "shell-with-known-ref",
282+
Submodels =
283+
[
284+
new Reference(
285+
ReferenceTypes.ModelReference,
286+
[new Key(KeyTypes.Submodel, submodelId)])
287+
]
288+
};
289+
290+
builder.AddShellInternal(shell);
291+
292+
// Act
293+
var environment = builder.Build();
294+
295+
// Assert
296+
var builtShell = environment.AssetAdministrationShells!.OfType<AssetAdministrationShell>().Single();
297+
builtShell.Submodels.ShouldNotBeNull();
298+
builtShell.Submodels.Count.ShouldBe(1);
299+
builtShell.Submodels.Single().Keys.Single().Value.ShouldBe(submodelId);
300+
}
301+
302+
[Fact]
303+
public void Build_WithShellReferencingUnknownSubmodelId_ShouldThrowInvalidOperationException()
304+
{
305+
// Arrange
306+
var builder = CreateSut();
307+
var unknownSubmodelId = _fixture.Create<string>()!;
308+
309+
var shell = new AssetAdministrationShell(
310+
id: _fixture.Create<string>()!,
311+
assetInformation: new AssetInformation(AssetKind.Instance))
312+
{
313+
IdShort = "shell-with-unknown-ref",
314+
Submodels =
315+
[
316+
new Reference(
317+
ReferenceTypes.ModelReference,
318+
[new Key(KeyTypes.Submodel, unknownSubmodelId)])
319+
]
320+
};
321+
322+
builder.AddShellInternal(shell);
323+
324+
// Act
325+
var act = () => builder.Build();
326+
327+
// Assert
328+
var ex = Should.Throw<InvalidOperationException>(act);
329+
ex.Message.ShouldContain($"references unknown submodel id '{unknownSubmodelId}'");
330+
}
331+
332+
[Fact]
333+
public void Build_WhenFragmentBatchFails_ShouldRollbackAppliedFragmentsBeforeRetry()
334+
{
335+
// Arrange
336+
var builder = CreateSut();
337+
var existingSubmodelId = _fixture.Create<string>();
338+
var missingSubmodelId = _fixture.Create<string>();
339+
340+
builder.AddSubmodel(new Submodel(id: existingSubmodelId, idShort: "existing"));
341+
builder.AddSubmodelFragment(existingSubmodelId, fragment => fragment.AddProperty("temperature", "21.5"));
342+
builder.AddSubmodelFragment(missingSubmodelId, fragment => fragment.AddProperty("pressure", "1.0"));
343+
344+
// Act
345+
Should.Throw<InvalidOperationException>(() => builder.Build());
346+
347+
builder.AddSubmodel(new Submodel(id: missingSubmodelId, idShort: "missing-now-added"));
348+
var env = builder.Build();
349+
350+
// Assert
351+
var existingSubmodel = env.Submodels!.OfType<Submodel>().Single(s => s.Id == existingSubmodelId);
352+
existingSubmodel.SubmodelElements.ShouldNotBeNull();
353+
existingSubmodel.SubmodelElements.Count(e => e.IdShort == "temperature").ShouldBe(1);
354+
}
355+
269356
[Fact]
270357
public void Build_WhenCalledMultipleTimes_ShouldReturnNewEnvironmentInstancesWithSameContent()
271358
{

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ var environment = builder.Build();
208208
- Fragment targets must exist.
209209
- Shell submodel references must resolve to known submodels.
210210

211-
> Backward compatibility note: `AddExistingSubmodel(...)` still works and delegates to `AddSubmodel(...)`.
211+
> Backward compatibility note: `AddExistingSubmodel(...)` still works, but it delegates to `AddSubmodelInternal(...)` (not `AddSubmodel(...)`) and therefore skips the additional public `IdShort` validation performed by `AddSubmodel(...)`.
212212
213213
---
214214

0 commit comments

Comments
 (0)