Greenfield C# app reading industrial machine data over pluggable protocols. M1 walking skeleton: MTConnect plugin polls a machine, Avalonia dashboard shows live last datum. Build 0 warn/0 err on net48 + net8.0 (Linux), 115 unit tests + 2 docker-gated integration tests. Projects: - Junction.Domain (netstandard2.0): Result<T>, models, IProtocolDriver, IMachineRepository, plugin manifest. Zero package deps. - Junction.Core (netstandard2.0): PollingEngine, PluginLoader (Assembly.LoadFrom), MachineMonitor, DI extensions. - Junction.Persistence (netstandard2.0): SqliteMachineRepository (Dapper), schema, connection factory. Provider-swap seam to SQL Server. - Junction.Protocols.MTConnect (netstandard2.0): HTTP driver + namespace- version-agnostic parser (MTConnect 1.7 + 2.0). Runtime plugin. - Junction.App (net48;net8.0): Avalonia MVVM, live dashboard, NLog, DI root. - Junction.Tests (net8.0): xUnit + Moq, 117 tests. - mock/: docker-compose MTConnect agent (ladder99/agent). Target net48 for Windows 7/8 fleet compatibility. Avalonia pinned 11.3.x. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
72 lines
2.3 KiB
C#
72 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Junction.Domain.Models;
|
|
using Xunit;
|
|
|
|
namespace Junction.Tests.Unit
|
|
{
|
|
public class MachineTests
|
|
{
|
|
[Fact]
|
|
public void Ctor_HoldsGenericConfigBag()
|
|
{
|
|
var id = Guid.NewGuid();
|
|
var config = new Dictionary<string, string>
|
|
{
|
|
["url"] = "http://host:5000",
|
|
["deviceName"] = "M1"
|
|
};
|
|
|
|
var m = new Machine(id, "Mill", "mtconnect", config, TimeSpan.FromSeconds(2));
|
|
|
|
Assert.Equal(id, m.Id);
|
|
Assert.Equal("Mill", m.Name);
|
|
Assert.Equal("mtconnect", m.ProtocolId);
|
|
Assert.Equal("http://host:5000", m.ConnectionConfig["url"]);
|
|
Assert.Equal("M1", m.ConnectionConfig["deviceName"]);
|
|
Assert.Equal(TimeSpan.FromSeconds(2), m.PollInterval);
|
|
}
|
|
|
|
[Fact]
|
|
public void Ctor_NullConfig_DefaultsToEmptyNeverNull()
|
|
{
|
|
var m = new Machine(Guid.NewGuid(), "M", "p", null, TimeSpan.Zero);
|
|
|
|
Assert.NotNull(m.ConnectionConfig);
|
|
Assert.Empty(m.ConnectionConfig);
|
|
}
|
|
|
|
[Fact]
|
|
public void Ctor_NullStrings_DefaultToEmpty()
|
|
{
|
|
var m = new Machine(Guid.NewGuid(), null!, null!, null, TimeSpan.Zero);
|
|
|
|
Assert.Equal("", m.Name);
|
|
Assert.Equal("", m.ProtocolId);
|
|
}
|
|
|
|
[Fact]
|
|
public void Properties_AreGetOnly()
|
|
{
|
|
var props = typeof(Machine).GetProperties();
|
|
Assert.All(props, p => Assert.Null(p.SetMethod));
|
|
}
|
|
|
|
[Fact]
|
|
public void With_OverridesGivenFields_KeepsRest()
|
|
{
|
|
var id = Guid.NewGuid();
|
|
var m = new Machine(id, "Mill", "mtconnect", null, TimeSpan.FromSeconds(1));
|
|
|
|
var updated = m.With(name: "Lathe", pollInterval: TimeSpan.FromSeconds(5));
|
|
|
|
Assert.Equal(id, updated.Id);
|
|
Assert.Equal("Lathe", updated.Name);
|
|
Assert.Equal("mtconnect", updated.ProtocolId);
|
|
Assert.Equal(TimeSpan.FromSeconds(5), updated.PollInterval);
|
|
// original unchanged (immutable)
|
|
Assert.Equal("Mill", m.Name);
|
|
Assert.Equal(TimeSpan.FromSeconds(1), m.PollInterval);
|
|
}
|
|
}
|
|
}
|