fix(tagconfig): close the four #551 residuals — accept-gate-first Inspect, three authoring rules, CSV/service gate, doc sweep
Gitea #551. 1. CSV import ran no driver-typed config gate. Its typed columns were always strictly parsed, but the free-form TagConfigJson column reached the database unread, so a CSV could author a tag the driver rejects — one that deploys green and reads BadNodeIdUnknown forever. RawTagCsvMapper.Parse now names the offending row in the staged review grid, and RawTreeService enforces the same gate on CreateTag/UpdateTag/ImportTags: a form cannot be the guarantee (the API and any future caller reach none of them, and this repo has no bUnit). A rejected import row is an ERROR — the batch inserts nothing and the row is named — never a skip. Note the brief's premise that manual entry rides ImportTagsAsync is wrong: RawManualTagEntryModal commits row-by-row via CreateTagAsync, which is why the gate had to land on all three write paths. 2/3. The seven pre-#549 Inspect methods ran a hand-list of DescribeInvalidEnum checks, so every rejection cause not on the list was invisible. They are now ACCEPT-GATE-FIRST (the MTConnect/Sql/OpcUaClient/Calculation shape): ask the driver's own reader for the verdict, then explain the refusal, with a catch-all so "the parse rejects but Inspect said nothing" is unreachable. That closes S7's absent dataType, AbCip members[], Modbus stringByteOrder and the type-dependent guards, plus causes the issue did not name (absent region/address/tagPath/symbolPath/topic, TwinCAT Structure, MQTT's Sparkplug tuple). FOCAS and MQTT keep advisories about ACCEPTED blobs, so they diagnose rather than return empty. Authoring half: ModbusTagConfigModel gains stringByteOrder; AbCipTagConfigModel asks the new AbCipTagDefinitionFactory.DescribeInvalidMember; S7TagConfigModel captures whether the SOURCE blob declared dataType and asks S7TagDefinitionFactory.DataTypeKey/DeclaresDataType. One authority per rule. 4. Doc sweep: the six factory Inspect summaries, EquipmentTagConfigInspector's class remarks and AdminOperationsActor's comment all claimed invalid enums are "silently defaulted by the lenient runtime" — false since R2-11 Phase C made the runtime reads strict. They describe rejections now.
This commit is contained in:
@@ -0,0 +1,350 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Uns;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Uns.TagEditors;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;
|
||||
using ZB.MOM.WW.OtOpcUa.ControlPlane.AdminOperations;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.AbCip;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.Modbus;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.S7;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.TwinCAT;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Uns;
|
||||
|
||||
/// <summary>
|
||||
/// Gitea #551 — the authoring half of the four residuals, and the seam that makes it a guarantee.
|
||||
/// <list type="number">
|
||||
/// <item>
|
||||
/// <b>The CSV import runs the driver-typed gate.</b> Its typed columns were always strictly
|
||||
/// parsed, but the free-form <c>TagConfigJson</c> column reached the database unread. It is
|
||||
/// checked twice on purpose: in <see cref="RawTagCsvMapper.Parse"/> so the staged review grid
|
||||
/// NAMES the offending row before commit, and in <see cref="RawTreeService.ImportTagsAsync"/>
|
||||
/// because a grid cannot cover the API or a future caller — and this repo has no bUnit, so a
|
||||
/// rule only a page enforces is a rule no test can reach. Deleting the service check leaves the
|
||||
/// mapper tests green and turns the service tests red; that asymmetry is the point.
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <b>A rejected row is an ERROR, not a skip.</b> The import is all-or-nothing: nothing is
|
||||
/// inserted and the row is named. "Skipped" would claim the tag is already present.
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <b>Modbus <c>stringByteOrder</c>, AbCip <c>members[].dataType</c> and the S7 absent
|
||||
/// <c>dataType</c></b> — three rules the runtime has always enforced that no authoring surface
|
||||
/// checked.
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// Every rejection below is paired with an acceptance control, so a gate that simply refuses everything
|
||||
/// cannot pass this suite.
|
||||
/// </summary>
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class RawTagConfigGateTests
|
||||
{
|
||||
// A blob the S7 driver actually reads — RootDeviceId hangs off the seed's S7 driver.
|
||||
private const string GoodS7 = """{"address":"DB1.DBW0","dataType":"Int16"}""";
|
||||
|
||||
private static (RawTreeService Service, string DbName) Seeded()
|
||||
{
|
||||
var name = RawTreeTestDb.SeedFresh();
|
||||
return (new RawTreeService(RawTreeTestDb.Factory(name)), name);
|
||||
}
|
||||
|
||||
private static RawTagInput Tag(string name, string tagConfig) =>
|
||||
new(name, "Float", TagAccessLevel.Read, WriteIdempotent: false, PollGroupId: null, tagConfig);
|
||||
|
||||
// ------------------------------------------------------------------ 1. the AdminUI models (item 2/3)
|
||||
|
||||
/// <summary>Gitea #551 item 3: the runtime reads it strictly; nothing on the authoring side did.</summary>
|
||||
[Fact]
|
||||
public void Modbus_rejects_a_typo_in_stringByteOrder()
|
||||
=> ModbusTagConfigModel
|
||||
.FromJson("""{"region":"HoldingRegisters","address":1,"dataType":"Int16","stringByteOrder":"HighByteFrist"}""")
|
||||
.Validate()
|
||||
.ShouldNotBeNullOrEmpty();
|
||||
|
||||
[Fact]
|
||||
public void Modbus_accepts_a_correctly_spelled_stringByteOrder()
|
||||
=> ModbusTagConfigModel
|
||||
.FromJson("""{"region":"HoldingRegisters","address":1,"dataType":"Int16","stringByteOrder":"LowByteFirst"}""")
|
||||
.Validate()
|
||||
.ShouldBeNull();
|
||||
|
||||
/// <summary>Gitea #551 item 3: members ride the model's preserved key bag, unread until now.</summary>
|
||||
[Fact]
|
||||
public void AbCip_rejects_a_typo_in_a_member_dataType()
|
||||
=> AbCipTagConfigModel
|
||||
.FromJson("""{"tagPath":"Motor","members":[{"name":"Run","dataType":"Booll"}]}""")
|
||||
.Validate()
|
||||
.ShouldNotBeNullOrEmpty();
|
||||
|
||||
[Fact]
|
||||
public void AbCip_rejects_a_member_with_no_name()
|
||||
=> AbCipTagConfigModel
|
||||
.FromJson("""{"tagPath":"Motor","members":[{"dataType":"Bool"}]}""")
|
||||
.Validate()
|
||||
.ShouldNotBeNullOrEmpty();
|
||||
|
||||
[Fact]
|
||||
public void AbCip_accepts_well_formed_members()
|
||||
=> AbCipTagConfigModel
|
||||
.FromJson("""{"tagPath":"Motor","members":[{"name":"Run","dataType":"Bool"},{"name":"Speed","dataType":"Real"}]}""")
|
||||
.Validate()
|
||||
.ShouldBeNull();
|
||||
|
||||
/// <summary>Gitea #551 item 2: S7 is the only driver whose reader requires the key to be PRESENT.</summary>
|
||||
[Fact]
|
||||
public void S7_rejects_a_config_carrying_no_dataType_key()
|
||||
=> S7TagConfigModel.FromJson("""{"address":"DB1.DBW0"}""").Validate().ShouldNotBeNullOrEmpty();
|
||||
|
||||
[Fact]
|
||||
public void S7_accepts_a_config_carrying_a_dataType_key()
|
||||
=> S7TagConfigModel.FromJson(GoodS7).Validate().ShouldBeNull();
|
||||
|
||||
/// <summary>
|
||||
/// The absent-key rule records a property of the SOURCE blob, so a model built by object initialiser
|
||||
/// — which is what <see cref="RawBrowseCommitMapper"/> does — must validate clean: its
|
||||
/// <c>ToJson()</c> writes the key from the typed field. Getting this backwards would refuse every
|
||||
/// browse-committed S7 tag.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void S7_accepts_a_model_that_was_built_rather_than_loaded()
|
||||
=> new S7TagConfigModel { Address = "DB1.DBW0" }.Validate().ShouldBeNull();
|
||||
|
||||
/// <summary>A load→save through the editor always emits the key, so the round-trip stays authorable.</summary>
|
||||
[Fact]
|
||||
public void S7_round_trip_through_the_model_repairs_a_key_less_blob()
|
||||
{
|
||||
var model = S7TagConfigModel.FromJson("""{"address":"DB1.DBW0"}""");
|
||||
model.Validate().ShouldNotBeNullOrEmpty();
|
||||
|
||||
S7TagConfigModel.FromJson(model.ToJson()).Validate().ShouldBeNull();
|
||||
}
|
||||
|
||||
// ------------------------------- 2. authoring ⇔ deploy-gate parity for the three new rules (item 2/3)
|
||||
|
||||
/// <summary>
|
||||
/// The pairing that matters: a blob the authoring gate refuses must draw a deploy warning, and a blob
|
||||
/// it accepts must draw none. Either direction alone is satisfiable by a broken gate — refuse
|
||||
/// everything, or refuse nothing.
|
||||
/// </summary>
|
||||
/// <param name="driverType">The driver type to dispatch both gates on.</param>
|
||||
/// <param name="tagConfig">The blob under test.</param>
|
||||
/// <param name="expectRejected">Whether both gates should refuse it.</param>
|
||||
[Theory]
|
||||
[InlineData(DriverTypeNames.Modbus, """{"region":"HoldingRegisters","address":1,"dataType":"Int16","stringByteOrder":"Nope"}""", true)]
|
||||
[InlineData(DriverTypeNames.Modbus, """{"region":"HoldingRegisters","address":1,"dataType":"Int16","stringByteOrder":"LowByteFirst"}""", false)]
|
||||
[InlineData(DriverTypeNames.AbCip, """{"tagPath":"Motor","members":[{"name":"Run","dataType":"Booll"}]}""", true)]
|
||||
[InlineData(DriverTypeNames.AbCip, """{"tagPath":"Motor","members":[{"name":"Run","dataType":"Bool"}]}""", false)]
|
||||
[InlineData(DriverTypeNames.S7, """{"address":"DB1.DBW0"}""", true)]
|
||||
[InlineData(DriverTypeNames.S7, """{"address":"DB1.DBW0","dataType":"Int16"}""", false)]
|
||||
public void Authoring_and_the_deploy_gate_agree(string driverType, string tagConfig, bool expectRejected)
|
||||
{
|
||||
var authoringError = TagConfigValidator.Validate(driverType, tagConfig);
|
||||
var deployWarnings = EquipmentTagConfigInspector.Inspect(driverType, tagConfig);
|
||||
|
||||
(authoringError is not null).ShouldBe(expectRejected, $"authoring verdict for {driverType}");
|
||||
(deployWarnings.Count > 0).ShouldBe(expectRejected, $"deploy verdict for {driverType}");
|
||||
}
|
||||
|
||||
// ---------------------------------------------- 3. the CSV review grid names the row (item 1, surface)
|
||||
|
||||
/// <summary>
|
||||
/// The gate runs on the FINAL assembled blob — the bytes that reach the database — so the fixture
|
||||
/// puts the offending value in a key the Modbus typed map does NOT own (<c>stringByteOrder</c>,
|
||||
/// #551 item 3). A key the map DOES own is round-tripped through
|
||||
/// <c>ModbusTagConfigModel.FromJson/ToJson</c> by <c>ApplyTypedColumns</c> and silently normalised
|
||||
/// to the model default before it can ever be judged — a separate, pre-existing defect noted with
|
||||
/// this work, not one this gate can see.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Csv_parse_marks_a_row_whose_TagConfigJson_the_driver_would_reject()
|
||||
{
|
||||
const string Csv = """
|
||||
Name,DataType,TagConfigJson
|
||||
good,Float,"{""region"":""HoldingRegisters"",""address"":1,""stringByteOrder"":""LowByteFirst""}"
|
||||
bad,Float,"{""region"":""HoldingRegisters"",""address"":1,""stringByteOrder"":""Nope""}"
|
||||
""";
|
||||
|
||||
var result = RawTagCsvMapper.Parse(DriverTypeNames.Modbus, Csv);
|
||||
|
||||
result.FatalError.ShouldBeNull();
|
||||
result.Rows.Count.ShouldBe(2);
|
||||
result.Rows[0].Ok.ShouldBeTrue("the clean row must still import");
|
||||
result.Rows[1].Ok.ShouldBeFalse();
|
||||
result.Rows[1].Error.ShouldNotBeNull();
|
||||
result.Rows[1].Error!.ShouldContain("Nope");
|
||||
result.CanCommit.ShouldBeFalse("the commit is blocked while any row is invalid");
|
||||
result.ToImportRows().Count.ShouldBe(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The acceptance control for the driver that has NO typed CSV map, where the fallback cell reaches
|
||||
/// the database verbatim — the shape the gate most needed to cover.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Csv_parse_judges_a_map_less_drivers_fallback_cell_verbatim()
|
||||
{
|
||||
const string Good = """
|
||||
Name,DataType,TagConfigJson
|
||||
ok,Double,"{""nodeId"":""ns=2;s=Line3.Temp""}"
|
||||
""";
|
||||
const string Bad = """
|
||||
Name,DataType,TagConfigJson
|
||||
broken,Double,"{""node_id"":""ns=2;s=Line3.Temp""}"
|
||||
""";
|
||||
|
||||
RawTagCsvMapper.Parse(DriverTypeNames.OpcUaClient, Good).CanCommit.ShouldBeTrue();
|
||||
|
||||
var bad = RawTagCsvMapper.Parse(DriverTypeNames.OpcUaClient, Bad);
|
||||
bad.CanCommit.ShouldBeFalse();
|
||||
bad.Rows[0].Error.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Positive control for the half that already worked: a typed column's value has always been
|
||||
/// strictly parsed (a bad enum throws <c>FormatException</c> into the row's error), so this row was
|
||||
/// rejected before #551 too. It is here so a reader can tell which half of the CSV path was the gap.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Csv_parse_still_marks_a_row_whose_TYPED_column_is_unparseable()
|
||||
{
|
||||
const string Csv = """
|
||||
Name,DataType,Region,Address,ModbusDataType
|
||||
bad,Float,HoldingRegisters,1,Intt16
|
||||
""";
|
||||
|
||||
var result = RawTagCsvMapper.Parse(DriverTypeNames.Modbus, Csv);
|
||||
|
||||
result.Rows.Count.ShouldBe(1);
|
||||
result.Rows[0].Ok.ShouldBeFalse();
|
||||
}
|
||||
|
||||
// ------------------------------------- 4. the SERVICE is the guarantee (item 1, the enforcement point)
|
||||
|
||||
/// <summary>
|
||||
/// Called with rows the CSV mapper never saw — which is exactly the shape of an API caller. Delete
|
||||
/// the check in <c>ImportTagsAsync</c> and this goes red while every mapper test above stays green.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ImportTags_fails_the_whole_batch_and_names_the_row_with_a_rejected_config()
|
||||
{
|
||||
var (service, dbName) = Seeded();
|
||||
|
||||
var rows = new[]
|
||||
{
|
||||
new RawTagImportRow(null, Tag("good1", GoodS7)),
|
||||
new RawTagImportRow(null, Tag("bad", """{"address":"DB1.DBW0"}""")), // no dataType key ⇒ S7 rejects
|
||||
new RawTagImportRow(null, Tag("good2", GoodS7)),
|
||||
};
|
||||
|
||||
var result = await service.ImportTagsAsync(RawTreeTestDb.RootDeviceId, rows);
|
||||
|
||||
result.Inserted.ShouldBe(0);
|
||||
result.Errors.ShouldContain(e => e.Contains("Row 2") && e.Contains("TagConfig"));
|
||||
|
||||
// All-or-nothing: the two good rows are not quietly kept either.
|
||||
using var db = RawTreeTestDb.CreateNamed(dbName);
|
||||
db.Tags.Any(t => t.Name == "good1" || t.Name == "good2").ShouldBeFalse();
|
||||
}
|
||||
|
||||
/// <summary>The acceptance control — without it, a gate that refuses every import would pass.</summary>
|
||||
[Fact]
|
||||
public async Task ImportTags_still_imports_a_batch_the_driver_can_read()
|
||||
{
|
||||
var (service, _) = Seeded();
|
||||
|
||||
var result = await service.ImportTagsAsync(
|
||||
RawTreeTestDb.RootDeviceId,
|
||||
new[] { new RawTagImportRow(null, Tag("ok1", GoodS7)), new RawTagImportRow(null, Tag("ok2", GoodS7)) });
|
||||
|
||||
result.Errors.ShouldBeEmpty();
|
||||
result.Inserted.ShouldBe(2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Manual entry commits row-by-row through <c>CreateTagAsync</c>, NOT through
|
||||
/// <c>ImportTagsAsync</c> — so the gate has to live on that path too, or the "enforce in the
|
||||
/// service" claim covers only the CSV modal.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task CreateTag_refuses_a_config_the_driver_would_reject()
|
||||
{
|
||||
var (service, _) = Seeded();
|
||||
|
||||
var bad = await service.CreateTagAsync(
|
||||
RawTreeTestDb.RootDeviceId, null, Tag("newTag", """{"address":"DB1.DBW0"}"""));
|
||||
|
||||
bad.Ok.ShouldBeFalse();
|
||||
bad.Error.ShouldNotBeNull();
|
||||
bad.Error.ShouldContain("TagConfig");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateTag_accepts_a_config_the_driver_can_read()
|
||||
{
|
||||
var (service, _) = Seeded();
|
||||
|
||||
(await service.CreateTagAsync(RawTreeTestDb.RootDeviceId, null, Tag("newTag", GoodS7)))
|
||||
.Ok.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateTag_refuses_a_config_the_driver_would_reject()
|
||||
{
|
||||
var (service, dbName) = Seeded();
|
||||
byte[] rowVersion;
|
||||
using (var db = RawTreeTestDb.CreateNamed(dbName))
|
||||
{
|
||||
rowVersion = db.Tags.Single(t => t.TagId == RawTreeTestDb.ReferencedTagId).RowVersion;
|
||||
}
|
||||
|
||||
var bad = await service.UpdateTagAsync(
|
||||
RawTreeTestDb.ReferencedTagId, Tag("temperature", """{"address":"DB1.DBW0"}"""), rowVersion);
|
||||
|
||||
bad.Ok.ShouldBeFalse();
|
||||
bad.Error.ShouldNotBeNull();
|
||||
bad.Error.ShouldContain("TagConfig");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A driver type with no typed model (Galaxy) validates to null in the modals, so the service must
|
||||
/// not invent a rule for it either — otherwise adding this gate would make Galaxy tags unauthorable.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void An_unmapped_driver_type_is_left_alone()
|
||||
{
|
||||
TagConfigValidator.Validate(DriverTypeNames.Galaxy, """{"FullName":"Reactor_001.Temp"}""").ShouldBeNull();
|
||||
TagConfigValidator.Validate(DriverTypeNames.Galaxy, "{}").ShouldBeNull();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Every blob <see cref="RawBrowseCommitMapper.BuildTagConfig"/> emits for a browsable driver must
|
||||
/// survive the gate the commit now passes through — otherwise browse-commit would author rows the
|
||||
/// import refuses.
|
||||
/// </summary>
|
||||
/// <param name="driverType">The browsable driver type.</param>
|
||||
[Theory]
|
||||
[InlineData(DriverTypeNames.S7)]
|
||||
[InlineData(DriverTypeNames.AbCip)]
|
||||
[InlineData(DriverTypeNames.AbLegacy)]
|
||||
[InlineData(DriverTypeNames.TwinCAT)]
|
||||
[InlineData(DriverTypeNames.OpcUaClient)]
|
||||
[InlineData(DriverTypeNames.Galaxy)]
|
||||
public void A_browse_committed_config_passes_the_gate(string driverType)
|
||||
{
|
||||
var tagConfig = RawBrowseCommitMapper.BuildTagConfig(driverType, "SomeAddress");
|
||||
|
||||
TagConfigValidator.Validate(driverType, tagConfig).ShouldBeNull(
|
||||
$"browse-commit for {driverType} must not author a config the import refuses");
|
||||
}
|
||||
|
||||
/// <summary>Sanity: the enums the three new rules read are the driver's own, not a local copy.</summary>
|
||||
[Fact]
|
||||
public void The_new_rules_read_the_drivers_own_enums()
|
||||
{
|
||||
Enum.GetNames<ModbusStringByteOrder>().ShouldContain("LowByteFirst");
|
||||
Enum.GetNames<AbCipDataType>().ShouldContain("Bool");
|
||||
Enum.GetNames<S7DataType>().ShouldContain("Int16");
|
||||
Enum.GetNames<TwinCATDataType>().ShouldContain("Structure");
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,19 @@ public sealed class RawTreeServiceWaveBTests
|
||||
private static RawTagInput Tag(string name, string dataType = "Float", string tagConfig = "{}") =>
|
||||
new(name, dataType, TagAccessLevel.ReadWrite, WriteIdempotent: false, PollGroupId: null, tagConfig);
|
||||
|
||||
/// <summary>
|
||||
/// A tag input whose <c>TagConfig</c> the <b>S7</b> driver would actually read — <c>RootDeviceId</c>
|
||||
/// hangs off the seed's S7 driver, and since Gitea #551 the service runs the driver-typed
|
||||
/// <c>TagConfigValidator</c> on every tag it writes. S7 requires BOTH an <c>address</c> and a
|
||||
/// present <c>dataType</c> key, so the bare <c>{}</c> the sibling helper defaults to is a config the
|
||||
/// driver rejects and the service now refuses. The Modbus-device tests keep <c>{}</c>: Modbus reads
|
||||
/// only enums out of the blob and accepts an empty one.
|
||||
/// </summary>
|
||||
/// <param name="name">The tag name.</param>
|
||||
/// <returns>The import-ready tag input.</returns>
|
||||
private static RawTagInput S7Tag(string name) =>
|
||||
Tag(name, tagConfig: """{"address":"DB1.DBW0","dataType":"Int16"}""");
|
||||
|
||||
// -------------------------------------------------------------------------------- CreateTag (WP4)
|
||||
|
||||
[Fact]
|
||||
@@ -181,9 +194,9 @@ public sealed class RawTreeServiceWaveBTests
|
||||
|
||||
var rows = new[]
|
||||
{
|
||||
new RawTagImportRow("Line/A", Tag("t1")),
|
||||
new RawTagImportRow("Line/A", Tag("t2")), // reuses Line + Line/A
|
||||
new RawTagImportRow("Line/B", Tag("t3")), // reuses Line, new B
|
||||
new RawTagImportRow("Line/A", S7Tag("t1")),
|
||||
new RawTagImportRow("Line/A", S7Tag("t2")), // reuses Line + Line/A
|
||||
new RawTagImportRow("Line/B", S7Tag("t3")), // reuses Line, new B
|
||||
};
|
||||
|
||||
var result = await service.ImportTagsAsync(RawTreeTestDb.RootDeviceId, rows);
|
||||
@@ -207,7 +220,7 @@ public sealed class RawTreeServiceWaveBTests
|
||||
var (service, dbName) = Seeded();
|
||||
|
||||
var result = await service.ImportTagsAsync(
|
||||
RawTreeTestDb.RootDeviceId, new[] { new RawTagImportRow(null, Tag("rootTag")) });
|
||||
RawTreeTestDb.RootDeviceId, new[] { new RawTagImportRow(null, S7Tag("rootTag")) });
|
||||
|
||||
result.Inserted.ShouldBe(1);
|
||||
using var db = RawTreeTestDb.CreateNamed(dbName);
|
||||
@@ -221,9 +234,9 @@ public sealed class RawTreeServiceWaveBTests
|
||||
|
||||
var rows = new[]
|
||||
{
|
||||
new RawTagImportRow("Grp", Tag("good1")),
|
||||
new RawTagImportRow("Grp", S7Tag("good1")),
|
||||
new RawTagImportRow("Grp", Tag("bad", tagConfig: "{oops")), // malformed JSON ⇒ error
|
||||
new RawTagImportRow("Grp", Tag("good2")),
|
||||
new RawTagImportRow("Grp", S7Tag("good2")),
|
||||
};
|
||||
|
||||
var result = await service.ImportTagsAsync(RawTreeTestDb.RootDeviceId, rows);
|
||||
@@ -245,8 +258,8 @@ public sealed class RawTreeServiceWaveBTests
|
||||
|
||||
var rows = new[]
|
||||
{
|
||||
new RawTagImportRow("Grp", Tag("dup")),
|
||||
new RawTagImportRow("Grp", Tag("dup")), // same path + name within the batch
|
||||
new RawTagImportRow("Grp", S7Tag("dup")),
|
||||
new RawTagImportRow("Grp", S7Tag("dup")), // same path + name within the batch
|
||||
};
|
||||
|
||||
var result = await service.ImportTagsAsync(RawTreeTestDb.RootDeviceId, rows);
|
||||
@@ -262,7 +275,7 @@ public sealed class RawTreeServiceWaveBTests
|
||||
|
||||
// "temperature" already sits at the device root of RootDevice.
|
||||
var result = await service.ImportTagsAsync(
|
||||
RawTreeTestDb.RootDeviceId, new[] { new RawTagImportRow(null, Tag("temperature")) });
|
||||
RawTreeTestDb.RootDeviceId, new[] { new RawTagImportRow(null, S7Tag("temperature")) });
|
||||
|
||||
result.Inserted.ShouldBe(0);
|
||||
result.Errors.ShouldContain(e => e.Contains("already exists"));
|
||||
|
||||
@@ -42,9 +42,15 @@ public sealed class TagConfigValidatorTests
|
||||
public void OpcUaClient_with_node_id_is_valid()
|
||||
=> TagConfigValidator.Validate("OpcUaClient", """{"nodeId":"ns=2;s=Line3.Temp"}""").ShouldBeNull();
|
||||
|
||||
// Gitea #551 item 2: S7 is the one driver whose reader REQUIRES the dataType key to be present, so a
|
||||
// blob carrying only an address is one the driver skips — this used to assert it was valid.
|
||||
[Fact]
|
||||
public void S7_with_address_is_valid()
|
||||
=> TagConfigValidator.Validate("S7", """{"address":"DB1.DBW0"}""").ShouldBeNull();
|
||||
public void S7_with_address_and_data_type_is_valid()
|
||||
=> TagConfigValidator.Validate("S7", """{"address":"DB1.DBW0","dataType":"Int16"}""").ShouldBeNull();
|
||||
|
||||
[Fact]
|
||||
public void S7_with_address_but_no_data_type_is_rejected()
|
||||
=> TagConfigValidator.Validate("S7", """{"address":"DB1.DBW0"}""").ShouldNotBeNullOrEmpty();
|
||||
|
||||
[Fact]
|
||||
public void AbCip_with_tag_path_is_valid()
|
||||
|
||||
Reference in New Issue
Block a user