|
| 1 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 2 | +using NetSdrClient.Models; |
| 3 | +using NetSdrClient.Services; |
| 4 | +using System.Linq; |
| 5 | + |
| 6 | +namespace NetSdrClient.Tests |
| 7 | +{ |
| 8 | + [TestClass] |
| 9 | + public class SDRClientTests |
| 10 | + { |
| 11 | + [TestMethod] |
| 12 | + public void SDRClient_Constructor_ShouldInitializeDevicesList() |
| 13 | + { |
| 14 | + // Arrange & Act |
| 15 | + var client = new SDRClient(); |
| 16 | + |
| 17 | + // Assert |
| 18 | + Assert.IsNotNull(client.Devices); |
| 19 | + Assert.AreEqual(0, client.Devices.Count); |
| 20 | + } |
| 21 | + |
| 22 | + [TestMethod] |
| 23 | + public void AddDevice_ShouldAddDeviceToList() |
| 24 | + { |
| 25 | + // Arrange |
| 26 | + var client = new SDRClient(); |
| 27 | + var device = new SDRDevice { Id = 1, Name = "Test Device" }; |
| 28 | + |
| 29 | + // Act |
| 30 | + client.AddDevice(device); |
| 31 | + |
| 32 | + // Assert |
| 33 | + Assert.AreEqual(1, client.Devices.Count); |
| 34 | + Assert.AreEqual(device, client.Devices[0]); |
| 35 | + } |
| 36 | + |
| 37 | + [TestMethod] |
| 38 | + public void RemoveDevice_ShouldRemoveDeviceFromList() |
| 39 | + { |
| 40 | + // Arrange |
| 41 | + var client = new SDRClient(); |
| 42 | + var device = new SDRDevice { Id = 1, Name = "Test Device" }; |
| 43 | + client.AddDevice(device); |
| 44 | + |
| 45 | + // Act |
| 46 | + var result = client.RemoveDevice(1); |
| 47 | + |
| 48 | + // Assert |
| 49 | + Assert.IsTrue(result); |
| 50 | + Assert.AreEqual(0, client.Devices.Count); |
| 51 | + } |
| 52 | + |
| 53 | + [TestMethod] |
| 54 | + public void RemoveDevice_WithInvalidId_ShouldReturnFalse() |
| 55 | + { |
| 56 | + // Arrange |
| 57 | + var client = new SDRClient(); |
| 58 | + |
| 59 | + // Act |
| 60 | + var result = client.RemoveDevice(999); |
| 61 | + |
| 62 | + // Assert |
| 63 | + Assert.IsFalse(result); |
| 64 | + } |
| 65 | + |
| 66 | + [TestMethod] |
| 67 | + public void GetDevice_ShouldReturnCorrectDevice() |
| 68 | + { |
| 69 | + // Arrange |
| 70 | + var client = new SDRClient(); |
| 71 | + var device1 = new SDRDevice { Id = 1, Name = "Device 1" }; |
| 72 | + var device2 = new SDRDevice { Id = 2, Name = "Device 2" }; |
| 73 | + client.AddDevice(device1); |
| 74 | + client.AddDevice(device2); |
| 75 | + |
| 76 | + // Act |
| 77 | + var result = client.GetDevice(2); |
| 78 | + |
| 79 | + // Assert |
| 80 | + Assert.IsNotNull(result); |
| 81 | + Assert.AreEqual("Device 2", result.Name); |
| 82 | + } |
| 83 | + |
| 84 | + [TestMethod] |
| 85 | + public void GetDevice_WithInvalidId_ShouldReturnNull() |
| 86 | + { |
| 87 | + // Arrange |
| 88 | + var client = new SDRClient(); |
| 89 | + |
| 90 | + // Act |
| 91 | + var result = client.GetDevice(999); |
| 92 | + |
| 93 | + // Assert |
| 94 | + Assert.IsNull(result); |
| 95 | + } |
| 96 | + } |
| 97 | +} |
0 commit comments