Add ExtendedAttributes config toggle for system+user attributes
When GalaxyRepository.ExtendedAttributes is true, uses the extended attributes query that includes both primitive (system) and dynamic (user-defined) attributes. Default is false (dynamic only, preserving existing behavior). Extended mode returns ~564 attributes vs ~48. Adds PrimitiveName and AttributeSource fields to GalaxyAttributeInfo. Includes 5 new unit tests and 6 new integration tests covering both standard and extended attribute modes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.LmxOpcUa.Host.Configuration;
|
||||
using ZB.MOM.WW.LmxOpcUa.Host.GalaxyRepository;
|
||||
|
||||
namespace ZB.MOM.WW.LmxOpcUa.IntegrationTests
|
||||
{
|
||||
public class GalaxyRepositoryServiceTests
|
||||
{
|
||||
private static GalaxyRepositoryConfiguration LoadConfig(bool extendedAttributes = false)
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddJsonFile("appsettings.test.json", optional: false)
|
||||
.Build();
|
||||
|
||||
var config = new GalaxyRepositoryConfiguration();
|
||||
configuration.GetSection("GalaxyRepository").Bind(config);
|
||||
config.ExtendedAttributes = extendedAttributes;
|
||||
return config;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAttributesAsync_StandardMode_ReturnsRows()
|
||||
{
|
||||
var config = LoadConfig(extendedAttributes: false);
|
||||
var service = new GalaxyRepositoryService(config);
|
||||
|
||||
var results = await service.GetAttributesAsync();
|
||||
|
||||
results.ShouldNotBeEmpty();
|
||||
// Standard mode: PrimitiveName and AttributeSource should be empty
|
||||
results.ShouldAllBe(r => r.PrimitiveName == "" && r.AttributeSource == "");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAttributesAsync_ExtendedMode_ReturnsMoreRows()
|
||||
{
|
||||
var standardConfig = LoadConfig(extendedAttributes: false);
|
||||
var extendedConfig = LoadConfig(extendedAttributes: true);
|
||||
var standardService = new GalaxyRepositoryService(standardConfig);
|
||||
var extendedService = new GalaxyRepositoryService(extendedConfig);
|
||||
|
||||
var standardResults = await standardService.GetAttributesAsync();
|
||||
var extendedResults = await extendedService.GetAttributesAsync();
|
||||
|
||||
extendedResults.Count.ShouldBeGreaterThan(standardResults.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAttributesAsync_ExtendedMode_IncludesPrimitiveAttributes()
|
||||
{
|
||||
var config = LoadConfig(extendedAttributes: true);
|
||||
var service = new GalaxyRepositoryService(config);
|
||||
|
||||
var results = await service.GetAttributesAsync();
|
||||
|
||||
results.ShouldContain(r => r.AttributeSource == "primitive");
|
||||
results.ShouldContain(r => r.AttributeSource == "dynamic");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAttributesAsync_ExtendedMode_PrimitiveNamePopulated()
|
||||
{
|
||||
var config = LoadConfig(extendedAttributes: true);
|
||||
var service = new GalaxyRepositoryService(config);
|
||||
|
||||
var results = await service.GetAttributesAsync();
|
||||
|
||||
// Some primitive attributes have non-empty primitive names
|
||||
// (though many have empty primitive_name for the root UDO)
|
||||
results.ShouldNotBeEmpty();
|
||||
// All should have an attribute source
|
||||
results.ShouldAllBe(r => r.AttributeSource == "primitive" || r.AttributeSource == "dynamic");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAttributesAsync_StandardMode_AllHaveFullTagReference()
|
||||
{
|
||||
var config = LoadConfig(extendedAttributes: false);
|
||||
var service = new GalaxyRepositoryService(config);
|
||||
|
||||
var results = await service.GetAttributesAsync();
|
||||
|
||||
results.ShouldAllBe(r => !string.IsNullOrEmpty(r.FullTagReference));
|
||||
results.ShouldAllBe(r => r.FullTagReference.Contains("."));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAttributesAsync_ExtendedMode_AllHaveFullTagReference()
|
||||
{
|
||||
var config = LoadConfig(extendedAttributes: true);
|
||||
var service = new GalaxyRepositoryService(config);
|
||||
|
||||
var results = await service.GetAttributesAsync();
|
||||
|
||||
results.ShouldAllBe(r => !string.IsNullOrEmpty(r.FullTagReference));
|
||||
results.ShouldAllBe(r => r.FullTagReference.Contains("."));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user