using Heimdall.Application.DTOs; namespace Heimdall.Application.Tests.DTOs; public class AgentTelemetryFieldsTests { [Fact] public void DefaultConstructor_ShouldHaveAllNulls() { var fields = new AgentTelemetryFields(); fields.CpuUsagePercent.ShouldBeNull(); fields.MemoryUsageBytes.ShouldBeNull(); fields.DiskUsagePercent.ShouldBeNull(); fields.UptimeSeconds.ShouldBeNull(); fields.CpuVendor.ShouldBeNull(); fields.CpuModel.ShouldBeNull(); fields.CpuArchitecture.ShouldBeNull(); fields.PhysicalCores.ShouldBeNull(); fields.LogicalCores.ShouldBeNull(); fields.ThreadsPerCore.ShouldBeNull(); fields.CpuFrequencyMhz.ShouldBeNull(); fields.CpuFlags.ShouldBeNull(); fields.CpuCacheBytes.ShouldBeNull(); fields.ContainerCpuLimit.ShouldBeNull(); fields.MemTotalBytes.ShouldBeNull(); fields.MemAvailableBytes.ShouldBeNull(); fields.SwapTotalBytes.ShouldBeNull(); fields.SwapFreeBytes.ShouldBeNull(); fields.ContainerMemoryLimitBytes.ShouldBeNull(); fields.DiskInventoryJson.ShouldBeNull(); fields.GpuInventoryJson.ShouldBeNull(); fields.OsName.ShouldBeNull(); fields.KernelVersion.ShouldBeNull(); fields.Arch.ShouldBeNull(); fields.UptimeMachineSeconds.ShouldBeNull(); fields.ContainerId.ShouldBeNull(); fields.ContainerImage.ShouldBeNull(); fields.NetworkInterfacesJson.ShouldBeNull(); fields.TemperatureJson.ShouldBeNull(); } [Fact] public void WithAllValues_ShouldStoreCorrectly() { var fields = new AgentTelemetryFields( CpuUsagePercent: 42.5, MemoryUsageBytes: 4_294_967_296, DiskUsagePercent: 73.1, UptimeSeconds: 86400, CpuVendor: "GenuineIntel", CpuModel: "Intel Core i7-12700K", CpuArchitecture: "x86_64", PhysicalCores: 12, LogicalCores: 20, ThreadsPerCore: 2, CpuFrequencyMhz: 3600.0, CpuFlags: "avx,avx2,fma", CpuCacheBytes: 25_165_824, ContainerCpuLimit: 200, MemTotalBytes: 17_179_869_184, MemAvailableBytes: 8_589_934_592, SwapTotalBytes: 2_147_483_648, SwapFreeBytes: 1_073_741_824, ContainerMemoryLimitBytes: 4_294_967_296, DiskInventoryJson: """[{"Mount":"/"}]""", GpuInventoryJson: """[{"Name":"RTX 4090"}]""", OsName: "Ubuntu 22.04 LTS", KernelVersion: "5.15.0-76-generic", Arch: "x86_64", UptimeMachineSeconds: 100000, ContainerId: "abc123", ContainerImage: "heimdall/agent:latest", NetworkInterfacesJson: """[{"Name":"eth0"}]""", TemperatureJson: """[{"Zone":"coretemp"}]""" ); fields.CpuUsagePercent.ShouldBe(42.5); fields.MemoryUsageBytes.ShouldBe(4_294_967_296); fields.DiskUsagePercent.ShouldBe(73.1); fields.UptimeSeconds.ShouldBe(86400); fields.CpuVendor.ShouldBe("GenuineIntel"); fields.CpuModel.ShouldBe("Intel Core i7-12700K"); fields.CpuArchitecture.ShouldBe("x86_64"); fields.PhysicalCores.ShouldBe(12); fields.LogicalCores.ShouldBe(20); fields.ThreadsPerCore.ShouldBe(2); fields.CpuFrequencyMhz.ShouldBe(3600.0); fields.CpuFlags.ShouldBe("avx,avx2,fma"); fields.CpuCacheBytes.ShouldBe(25_165_824); fields.ContainerCpuLimit.ShouldBe(200); fields.MemTotalBytes.ShouldBe(17_179_869_184); fields.MemAvailableBytes.ShouldBe(8_589_934_592); fields.SwapTotalBytes.ShouldBe(2_147_483_648); fields.SwapFreeBytes.ShouldBe(1_073_741_824); fields.ContainerMemoryLimitBytes.ShouldBe(4_294_967_296); fields.DiskInventoryJson.ShouldBe("""[{"Mount":"/"}]"""); fields.GpuInventoryJson.ShouldBe("""[{"Name":"RTX 4090"}]"""); fields.OsName.ShouldBe("Ubuntu 22.04 LTS"); fields.KernelVersion.ShouldBe("5.15.0-76-generic"); fields.Arch.ShouldBe("x86_64"); fields.UptimeMachineSeconds.ShouldBe(100000); fields.ContainerId.ShouldBe("abc123"); fields.ContainerImage.ShouldBe("heimdall/agent:latest"); fields.NetworkInterfacesJson.ShouldBe("""[{"Name":"eth0"}]"""); fields.TemperatureJson.ShouldBe("""[{"Zone":"coretemp"}]"""); } [Fact] public void WithPartialValues_ShouldStoreOnlyProvidedFields() { var fields = new AgentTelemetryFields( CpuUsagePercent: 50.0, CpuVendor: "AMD" ); fields.CpuUsagePercent.ShouldBe(50.0); fields.CpuVendor.ShouldBe("AMD"); fields.MemoryUsageBytes.ShouldBeNull(); fields.CpuModel.ShouldBeNull(); } [Fact] public void RecordEquality_SameValues_ShouldBeEqual() { var f1 = new AgentTelemetryFields(CpuUsagePercent: 42.5, CpuVendor: "Intel"); var f2 = new AgentTelemetryFields(CpuUsagePercent: 42.5, CpuVendor: "Intel"); f1.ShouldBe(f2); } [Fact] public void RecordEquality_DifferentValues_ShouldNotBeEqual() { var f1 = new AgentTelemetryFields(CpuUsagePercent: 42.5); var f2 = new AgentTelemetryFields(CpuUsagePercent: 50.0); f1.ShouldNotBe(f2); } [Fact] public void RecordWith_ShouldCreateModifiedCopy() { var original = new AgentTelemetryFields(CpuUsagePercent: 42.5, CpuVendor: "Intel"); var modified = original with { CpuUsagePercent = 99.0 }; modified.CpuUsagePercent.ShouldBe(99.0); modified.CpuVendor.ShouldBe("Intel"); original.CpuUsagePercent.ShouldBe(42.5); } }