using Nonemm.Core; namespace Nonemm.Network.Tests; /// N1MM reads a contact by position, with `SetNewContact`, and it throws on a /// flag written as `True`. public class QsoRecordTests { private static readonly Qso Worked = new() { Id = Qso.NewId(), TimestampUtc = new DateTime(2026, 10, 24, 2, 29, 21, DateTimeKind.Utc), Call = Callsign.Parse("G3XYZ"), Frequency = Frequency.FromKilohertz(14_025), Mode = Modes.Cw, ContestName = "CQWW", Points = 3, IsMultiplier1 = true, IsMultiplier3 = true, Continent = "EU", ContactType = "D", StationName = "RUN-PC", NetworkedComputerNumber = 2, }; [Fact] public void AContactIsFortyThreeFields() { Assert.Equal(QsoRecord.FieldCount, QsoRecord.Write(Worked).Count); } /// The fields N1MM converts with `ToShort` are 20, 21, 30, 36, 40 and 42. [Fact] public void TheFlagsN1MmConvertToNumbersAreNumbers() { List fields = QsoRecord.Write(Worked); foreach (int at in new[] { 20, 21, 30, 36, 40, 42 }) { Assert.True(short.TryParse(fields[at], out _), $"field {at} is '{fields[at]}'"); } Assert.Equal("1", fields[20]); Assert.Equal("0", fields[21]); } [Fact] public void TheContinentComesBeforeTheContactType() { List fields = QsoRecord.Write(Worked); Assert.Equal("EU", fields[32]); Assert.Equal("D", fields[33]); } [Fact] public void TheIdIsSentAsAGuidAndKept() { List fields = QsoRecord.Write(Worked); StationRecord record = new(2, "RUN-PC", "QSO", [fields[0], .. fields]); Qso read = QsoRecord.Read(record, 1, "RUN-PC"); Assert.Equal(Worked.Id, read.Id); Assert.Equal(Worked.Call.Text, read.Call.Text); Assert.Equal("EU", read.Continent); Assert.Equal("D", read.ContactType); Assert.Equal(2, read.NetworkedComputerNumber); } /// N1MM parses the id as a GUID, so one that is not goes out empty. [Fact] public void AnIdThatIsNotAGuidIsLeftOut() { Assert.Equal("", QsoRecord.Write(Worked with { Id = "not-a-guid" })[41]); } }