Skip to content

Commit be98ee0

Browse files
Create UdpClientWrapper.cs
1 parent 9691974 commit be98ee0

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.Net;
4+
using NetSdrClientApp.Networking;
5+
6+
namespace NetSdrClientApp.Tests
7+
{
8+
[TestFixture]
9+
public class UdpClientWrapperTests
10+
{
11+
private UdpClientWrapper _client1;
12+
private UdpClientWrapper _client2;
13+
14+
[SetUp]
15+
public void Setup()
16+
{
17+
_client1 = new UdpClientWrapper(5000);
18+
_client2 = new UdpClientWrapper(5000);
19+
}
20+
21+
[TearDown]
22+
public void TearDown()
23+
{
24+
_client1.Dispose();
25+
_client2.Dispose();
26+
}
27+
28+
[Test]
29+
public void GetHashCode_ReturnsConsistentValue()
30+
{
31+
int hash1 = _client1.GetHashCode();
32+
int hash2 = _client1.GetHashCode();
33+
Assert.That(hash1, Is.EqualTo(hash2));
34+
}
35+
36+
[Test]
37+
public void GetHashCode_DifferentClientsWithSamePort_ReturnsSameHash()
38+
{
39+
int hash1 = _client1.GetHashCode();
40+
int hash2 = _client2.GetHashCode();
41+
Assert.That(hash1, Is.EqualTo(hash2));
42+
}
43+
44+
[Test]
45+
public void Equals_ReturnsTrue_ForSamePortAndAddress()
46+
{
47+
Assert.That(_client1.Equals(_client2), Is.True);
48+
}
49+
50+
[Test]
51+
public void Equals_ReturnsFalse_ForDifferentPort()
52+
{
53+
var clientDifferentPort = new UdpClientWrapper(6000);
54+
Assert.That(_client1.Equals(clientDifferentPort), Is.False);
55+
clientDifferentPort.Dispose();
56+
}
57+
58+
[Test]
59+
public void Equals_ReturnsFalse_ForDifferentType()
60+
{
61+
Assert.That(_client1.Equals("some string"), Is.False);
62+
Assert.That(_client1.Equals(null), Is.False);
63+
}
64+
65+
[Test]
66+
public void Dispose_CanBeCalledMultipleTimes_WithoutException()
67+
{
68+
_client1.Dispose();
69+
Assert.DoesNotThrow(() => _client1.Dispose());
70+
}
71+
72+
[Test]
73+
public void Dispose_SetsDisposedFlag()
74+
{
75+
_client1.Dispose();
76+
// використати рефлексію для перевірки приватного поля _disposed
77+
var disposedField = typeof(UdpClientWrapper)
78+
.GetField("_disposed", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
79+
bool disposedValue = (bool)disposedField!.GetValue(_client1)!;
80+
Assert.That(disposedValue, Is.True);
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)