DescribeSwitchUseCaseTests.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using NSubstitute;
  2. using RackPeek.Domain.Resources.Hardware;
  3. using RackPeek.Domain.Resources.Hardware.Models;
  4. using RackPeek.Domain.Resources.Hardware.Switches;
  5. namespace Tests.Hardware.Switches;
  6. public class DescribeSwitchUseCaseTests
  7. {
  8. [Fact]
  9. public async Task ExecuteAsync_Returns_null_when_switch_not_found()
  10. {
  11. // Arrange
  12. var repo = Substitute.For<IHardwareRepository>();
  13. repo.GetByNameAsync("sw01").Returns((RackPeek.Domain.Resources.Hardware.Models.Hardware?)null);
  14. var sut = new DescribeSwitchUseCase(repo);
  15. // Act
  16. var result = await sut.ExecuteAsync("sw01");
  17. // Assert
  18. Assert.Null(result);
  19. }
  20. [Fact]
  21. public async Task ExecuteAsync_Returns_defaults_when_switch_has_no_ports()
  22. {
  23. // Arrange
  24. var repo = Substitute.For<IHardwareRepository>();
  25. repo.GetByNameAsync("sw01").Returns(new Switch
  26. {
  27. Name = "sw01",
  28. Model = "TestModel",
  29. Managed = true,
  30. Poe = false,
  31. Ports = null
  32. });
  33. var sut = new DescribeSwitchUseCase(repo);
  34. // Act
  35. var result = await sut.ExecuteAsync("sw01");
  36. // Assert
  37. Assert.NotNull(result);
  38. Assert.Equal("sw01", result.Name);
  39. Assert.Equal("TestModel", result.Model);
  40. Assert.True(result.Managed);
  41. Assert.False(result.Poe);
  42. Assert.Equal(0, result.TotalPorts);
  43. Assert.Equal(0, result.TotalSpeedGb);
  44. Assert.Equal(string.Empty, result.PortSummary);
  45. }
  46. [Fact]
  47. public async Task ExecuteAsync_Calculates_totals_and_summary_from_ports()
  48. {
  49. // Arrange
  50. var repo = Substitute.For<IHardwareRepository>();
  51. repo.GetByNameAsync("sw01").Returns(new Switch
  52. {
  53. Name = "sw01",
  54. Model = "CoreSwitch",
  55. Managed = true,
  56. Poe = true,
  57. Ports = new List<Port>
  58. {
  59. new() { Type = "RJ45", Speed = 1, Count = 24 },
  60. new() { Type = "SFP+", Speed = 10, Count = 4 }
  61. }
  62. });
  63. var sut = new DescribeSwitchUseCase(repo);
  64. // Act
  65. var result = await sut.ExecuteAsync("sw01");
  66. // Assert
  67. Assert.NotNull(result);
  68. Assert.Equal("sw01", result.Name);
  69. Assert.Equal("CoreSwitch", result.Model);
  70. Assert.True(result.Managed);
  71. Assert.True(result.Poe);
  72. Assert.Equal(28, result.TotalPorts); // 24 + 4
  73. Assert.Equal(64, result.TotalSpeedGb); // (24 * 1) + (4 * 10)
  74. Assert.Equal(
  75. "RJ45: 24 ports (24 Gb total), SFP+: 4 ports (40 Gb total)",
  76. result.PortSummary
  77. );
  78. }
  79. }