mishima-nexus-client-csharp/tests/Robotico.Nexus.Client.Tests/Time/TimeWireMappingTests.cs

102 lines
2.9 KiB
C#
Raw Permalink Normal View History

using Mishima.Nexus.Wire.V1;
using Robotico.Nexus.Client.Time;
using Robotico.Time;
using Xunit;
namespace Robotico.Nexus.Client.Tests.Time;
public class TimeWireMappingTests
{
[Fact]
public void ToWire_ThenFromWire_RoundTrips_Int64()
{
TimeCell cell = new("Int64", I64: 42);
TimeCellWire wire = TimeWireMapping.ToWire(cell);
TimeCell roundTripped = TimeWireMapping.FromWire(wire);
Assert.Equal(42, wire.I64);
Assert.Equal(cell, roundTripped);
}
[Fact]
public void ToWire_ThenFromWire_RoundTrips_UInt64()
{
TimeCell cell = new("UInt64", U64: 7);
TimeCellWire wire = TimeWireMapping.ToWire(cell);
Assert.Equal(7ul, wire.U64);
Assert.Equal(cell, TimeWireMapping.FromWire(wire));
}
[Fact]
public void ToWire_ThenFromWire_RoundTrips_Double()
{
TimeCell cell = new("Double", F64: 3.5);
TimeCellWire wire = TimeWireMapping.ToWire(cell);
Assert.Equal(3.5, wire.F64);
Assert.Equal(cell, TimeWireMapping.FromWire(wire));
}
[Fact]
public void ToWire_ThenFromWire_RoundTrips_Boolean()
{
TimeCell cell = new("Boolean", Boolean: true);
TimeCellWire wire = TimeWireMapping.ToWire(cell);
Assert.True(wire.Boolean);
Assert.Equal(cell, TimeWireMapping.FromWire(wire));
}
[Fact]
public void ToWire_ThenFromWire_RoundTrips_Utf8Default()
{
TimeCell cell = new("Utf8", Utf8: "hello");
TimeCellWire wire = TimeWireMapping.ToWire(cell);
Assert.Equal("hello", wire.Utf8);
Assert.Equal(cell, TimeWireMapping.FromWire(wire));
}
[Fact]
public void ToWire_Null_DoesNotPopulateAnyValue()
{
TimeCell cell = new("Int64", IsNull: true);
TimeCellWire wire = TimeWireMapping.ToWire(cell);
Assert.True(wire.IsNull);
Assert.Equal(0, wire.I64);
}
[Fact]
public void FromWire_Null_ReturnsNullCell()
{
TimeCellWire wire = new() { WireTypeName = "Int64", IsNull = true };
TimeCell cell = TimeWireMapping.FromWire(wire);
Assert.True(cell.IsNull);
}
[Theory]
[InlineData(Robotico.Time.TimeEventFieldIndexKind.None, Mishima.Nexus.Wire.V1.TimeEventFieldIndexKind.None)]
[InlineData(Robotico.Time.TimeEventFieldIndexKind.Inverted, Mishima.Nexus.Wire.V1.TimeEventFieldIndexKind.Inverted)]
[InlineData(Robotico.Time.TimeEventFieldIndexKind.FullText, Mishima.Nexus.Wire.V1.TimeEventFieldIndexKind.FullText)]
public void ToWire_MapsFieldIndexKind(Robotico.Time.TimeEventFieldIndexKind kind, Mishima.Nexus.Wire.V1.TimeEventFieldIndexKind expected)
{
Assert.Equal(expected, TimeWireMapping.ToWire(kind));
}
[Fact]
public void ToWire_UnknownFieldIndexKind_DefaultsToNone()
{
Assert.Equal(Mishima.Nexus.Wire.V1.TimeEventFieldIndexKind.None, TimeWireMapping.ToWire((Robotico.Time.TimeEventFieldIndexKind)99));
}
}