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>
91 lines
2.9 KiB
C#
91 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Junction.Domain.Models;
|
|
using Xunit;
|
|
|
|
namespace Junction.Tests.Unit
|
|
{
|
|
public class MachineSnapshotTests
|
|
{
|
|
private static DataItem Item(string id, string name = "n", string value = "v") =>
|
|
new DataItem(id, name, value, "Sample", DateTimeOffset.UtcNow);
|
|
|
|
[Fact]
|
|
public void Ctor_HoldsValues()
|
|
{
|
|
var machineId = Guid.NewGuid();
|
|
var at = DateTimeOffset.UtcNow;
|
|
var items = new[] { Item("a"), Item("b") };
|
|
|
|
var snap = new MachineSnapshot(machineId, at, ConnectionState.Connected, items);
|
|
|
|
Assert.Equal(machineId, snap.MachineId);
|
|
Assert.Equal(at, snap.CapturedAt);
|
|
Assert.Equal(ConnectionState.Connected, snap.ConnectionState);
|
|
Assert.Equal(2, snap.Items.Count);
|
|
}
|
|
|
|
[Fact]
|
|
public void Ctor_NullItems_DefaultsToEmptyNeverNull()
|
|
{
|
|
var snap = new MachineSnapshot(Guid.NewGuid(), DateTimeOffset.UtcNow, ConnectionState.Unknown, null);
|
|
|
|
Assert.NotNull(snap.Items);
|
|
Assert.Empty(snap.Items);
|
|
}
|
|
|
|
[Fact]
|
|
public void IsEmpty_TrueWhenZeroItems()
|
|
{
|
|
var snap = new MachineSnapshot(Guid.NewGuid(), DateTimeOffset.UtcNow, ConnectionState.Connected, null);
|
|
Assert.True(snap.IsEmpty);
|
|
}
|
|
|
|
[Fact]
|
|
public void IsEmpty_FalseWhenHasItems()
|
|
{
|
|
var snap = new MachineSnapshot(
|
|
Guid.NewGuid(), DateTimeOffset.UtcNow, ConnectionState.Connected, new[] { Item("a") });
|
|
Assert.False(snap.IsEmpty);
|
|
}
|
|
|
|
[Fact]
|
|
public void TryGetItem_ReturnsItem_WhenPresent()
|
|
{
|
|
var snap = new MachineSnapshot(
|
|
Guid.NewGuid(), DateTimeOffset.UtcNow, ConnectionState.Connected,
|
|
new[] { Item("temp", "Temperature", "42") });
|
|
|
|
var found = snap.TryGetItem("temp");
|
|
|
|
Assert.NotNull(found);
|
|
Assert.Equal("Temperature", found!.Name);
|
|
Assert.Equal("42", found.Value);
|
|
}
|
|
|
|
[Fact]
|
|
public void TryGetItem_ReturnsNull_WhenMissing()
|
|
{
|
|
var snap = new MachineSnapshot(
|
|
Guid.NewGuid(), DateTimeOffset.UtcNow, ConnectionState.Connected, new[] { Item("a") });
|
|
|
|
Assert.Null(snap.TryGetItem("nope"));
|
|
}
|
|
|
|
[Fact]
|
|
public void TryGetItem_ReturnsNull_WhenIdNull()
|
|
{
|
|
var snap = new MachineSnapshot(
|
|
Guid.NewGuid(), DateTimeOffset.UtcNow, ConnectionState.Connected, new[] { Item("a") });
|
|
|
|
Assert.Null(snap.TryGetItem(null!));
|
|
}
|
|
|
|
[Fact]
|
|
public void Properties_AreGetOnly()
|
|
{
|
|
var props = typeof(MachineSnapshot).GetProperties();
|
|
Assert.All(props, p => Assert.Null(p.SetMethod));
|
|
}
|
|
}
|
|
}
|