45 lines
2.1 KiB
C#
45 lines
2.1 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
|
|
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Configuration.Tests.DataConnections;
|
|
|
|
[Trait("Category", "Unit")]
|
|
[Trait("Feature", "GrpcData")]
|
|
[Trait("Phase", "P02")]
|
|
public sealed class GrpcDataSchemaModelTests
|
|
{
|
|
[Fact]
|
|
public void Rollback_preserves_acl_scope_storage_for_retained_mapping_grants()
|
|
{
|
|
using var db = new OtOpcUaConfigDbContext(new DbContextOptionsBuilder<OtOpcUaConfigDbContext>()
|
|
.UseSqlServer("Server=127.0.0.1,1;Database=design;Integrated Security=true;TrustServerCertificate=true").Options);
|
|
var migrations = db.Database.GetMigrations().ToArray();
|
|
migrations[^1].ShouldEndWith("_AddGrpcDataConnections");
|
|
var rollback = db.GetService<IMigrator>().GenerateScript(migrations[^1], migrations[^2]);
|
|
rollback.ShouldNotContain("ALTER COLUMN [ScopeKind]");
|
|
}
|
|
|
|
[Fact]
|
|
public void New_rows_have_keys_and_unique_logical_ids_without_database_access()
|
|
{
|
|
using var db = new OtOpcUaConfigDbContext(new DbContextOptionsBuilder<OtOpcUaConfigDbContext>()
|
|
.UseSqlServer("Server=localhost;Database=design;Integrated Security=true;TrustServerCertificate=true").Options);
|
|
foreach (var type in new[] { typeof(DataConnection), typeof(DataExport), typeof(RemoteNamespaceMapping) })
|
|
{
|
|
var entity = db.Model.FindEntityType(type).ShouldNotBeNull();
|
|
entity.FindPrimaryKey().ShouldNotBeNull();
|
|
entity.GetIndexes().ShouldContain(i => i.IsUnique);
|
|
}
|
|
((int)NodeAclScopeKind.RawTagGroup).ShouldBe(10);
|
|
((int)NodeAclScopeKind.RemoteNamespaceMapping).ShouldBe(11);
|
|
db.Model.FindEntityType(typeof(NodeAcl))!.FindProperty(nameof(NodeAcl.ScopeKind))!
|
|
.GetMaxLength().GetValueOrDefault().ShouldBeGreaterThanOrEqualTo(nameof(NodeAclScopeKind.RemoteNamespaceMapping).Length);
|
|
db.Database.HasPendingModelChanges().ShouldBeFalse();
|
|
}
|
|
}
|