refactor: rename ScadaLink → ZB.MOM.WW.ScadaBridge (code + projects + namespaces)
Solution + 23 src projects + 26 test projects renamed; folders, csproj, namespaces, and ScadaLinkDbContext/ScadaBridgeDbContext class updated. ActorSystem "scadalink" → "scadabridge", Akka seed-node URLs migrated. SQL roles/logins, LDAP domains, CLI command name, and CLI config dir (~/.scadalink → ~/.scadabridge) also renamed. Build green; 5 Host.Tests fail awaiting SQL login rename in next commit. Pre-existing StaleTagMonitor timing flakes unchanged. Rename script committed at tools/rename-to-scadabridge.sh.
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Commons.Tests.Entities;
|
||||
|
||||
public class EntityConventionTests
|
||||
{
|
||||
private static readonly Assembly CommonsAssembly = typeof(ZB.MOM.WW.ScadaBridge.Commons.Types.RetryPolicy).Assembly;
|
||||
|
||||
private static IEnumerable<Type> GetEntityTypes() =>
|
||||
CommonsAssembly.GetTypes()
|
||||
.Where(t => t.IsClass && !t.IsAbstract && t.Namespace != null
|
||||
&& t.Namespace.Contains(".Entities."));
|
||||
|
||||
[Fact]
|
||||
public void AllEntities_ShouldHaveNoEfAttributes()
|
||||
{
|
||||
var efAttributeNames = new HashSet<string>
|
||||
{
|
||||
"KeyAttribute", "ForeignKeyAttribute", "TableAttribute",
|
||||
"ColumnAttribute", "RequiredAttribute", "MaxLengthAttribute",
|
||||
"StringLengthAttribute", "DatabaseGeneratedAttribute",
|
||||
"NotMappedAttribute", "IndexAttribute", "InversePropertyAttribute"
|
||||
};
|
||||
|
||||
foreach (var entityType in GetEntityTypes())
|
||||
{
|
||||
// Check class-level attributes
|
||||
var classAttrs = entityType.GetCustomAttributes(true);
|
||||
foreach (var attr in classAttrs)
|
||||
{
|
||||
Assert.DoesNotContain(attr.GetType().Name, efAttributeNames);
|
||||
}
|
||||
|
||||
// Check property-level attributes
|
||||
foreach (var prop in entityType.GetProperties())
|
||||
{
|
||||
var propAttrs = prop.GetCustomAttributes(true);
|
||||
foreach (var attr in propAttrs)
|
||||
{
|
||||
Assert.False(efAttributeNames.Contains(attr.GetType().Name),
|
||||
$"Entity {entityType.Name}.{prop.Name} has EF attribute {attr.GetType().Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AllTimestampProperties_ShouldBeDateTimeOffset()
|
||||
{
|
||||
var timestampNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
"Timestamp", "DeployedAt", "CompletedAt", "GeneratedAt",
|
||||
"ReportTimestamp", "SnapshotTimestamp"
|
||||
};
|
||||
|
||||
foreach (var entityType in GetEntityTypes())
|
||||
{
|
||||
foreach (var prop in entityType.GetProperties())
|
||||
{
|
||||
if (timestampNames.Contains(prop.Name))
|
||||
{
|
||||
var underlyingType = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
|
||||
Assert.True(underlyingType == typeof(DateTimeOffset),
|
||||
$"{entityType.Name}.{prop.Name} should be DateTimeOffset but is {prop.PropertyType.Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NavigationProperties_ShouldBeICollection()
|
||||
{
|
||||
foreach (var entityType in GetEntityTypes())
|
||||
{
|
||||
foreach (var prop in entityType.GetProperties())
|
||||
{
|
||||
if (prop.PropertyType.IsGenericType &&
|
||||
typeof(IEnumerable).IsAssignableFrom(prop.PropertyType) &&
|
||||
prop.PropertyType != typeof(string))
|
||||
{
|
||||
Assert.True(
|
||||
prop.PropertyType.GetGenericTypeDefinition() == typeof(ICollection<>),
|
||||
$"{entityType.Name}.{prop.Name} should be ICollection<T> but is {prop.PropertyType.Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user