Skip to content

Commit 787713d

Browse files
author
PortaSFTPServer
committed
test: add unit tests for wrapper classes and bump to v1.0.0.8-beta.1
1 parent 8252162 commit 787713d

14 files changed

Lines changed: 2352 additions & 10 deletions
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using ApacheMinaSSHD.NET.Wrapper.Abstractions;
2+
using ApacheMinaSSHD.NET.Wrapper.Abstractions.Models;
3+
using System.Net;
4+
5+
namespace ApacheMinaSSHD.NET.Wrapper.Tests;
6+
7+
public class IoServiceEventListenerTests
8+
{
9+
private class MockConnection : ISshServiceConnection
10+
{
11+
public IPEndPoint LocalEndPoint { get; set; } = new(IPAddress.Any, 22);
12+
public IPEndPoint RemoteEndPoint { get; set; } = new(IPAddress.Loopback, 12345);
13+
public IPEndPoint ServiceEndPoint { get; set; } = new(IPAddress.Any, 22);
14+
public IReadOnlyDictionary<string, object> Attributes { get; set; } = new Dictionary<string, object>();
15+
public ISshIoService IoService { get; set; } = new MockIoService();
16+
public Exception Exception { get; set; } = null!;
17+
}
18+
19+
private class MockIoService : ISshIoService
20+
{
21+
public bool IsAcceptor { get; set; } = true;
22+
public bool IsClosed => false;
23+
public bool IsClosing => false;
24+
public IEnumerable<IPEndPoint> BoundAddresses { get; set; } = [new IPEndPoint(IPAddress.Any, 22)];
25+
}
26+
27+
[Fact]
28+
public void Constructor_does_not_throw() => _ = new AMNetIoServiceEventListener();
29+
30+
[Fact]
31+
public void OnConnectionAborted_does_not_throw()
32+
{
33+
new AMNetIoServiceEventListener().OnConnectionAborted(
34+
new MockConnection { Exception = new InvalidOperationException("test") });
35+
}
36+
37+
[Fact]
38+
public void OnConnectionAccepted_returns_true()
39+
{
40+
Assert.True(new AMNetIoServiceEventListener().OnConnectionAccepted(new MockConnection()));
41+
}
42+
43+
[Fact]
44+
public void OnConnectionAccepted_with_non_acceptor()
45+
{
46+
Assert.True(new AMNetIoServiceEventListener().OnConnectionAccepted(
47+
new MockConnection
48+
{
49+
IoService = new MockIoService { IsAcceptor = false, BoundAddresses = [] }
50+
}));
51+
}
52+
53+
[Fact]
54+
public void OnOutboundConnectionAborted_does_not_throw()
55+
{
56+
new AMNetIoServiceEventListener().OnOutboundConnectionAborted(
57+
new MockConnection { Exception = new TimeoutException("timeout") });
58+
}
59+
60+
[Fact]
61+
public void OnOutboundConnectionEstablished_does_not_throw()
62+
{
63+
new AMNetIoServiceEventListener().OnOutboundConnectionEstablished(new MockConnection());
64+
}
65+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using ApacheMinaSSHD.NET.Wrapper.Abstractions;
2+
using ApacheMinaSSHD.NET.Wrapper.Factories;
3+
4+
namespace ApacheMinaSSHD.NET.Wrapper.Tests;
5+
6+
public class ScpCommandFactoryTests
7+
{
8+
[Fact]
9+
public void Constructor_default()
10+
{
11+
var factory = new AMNetScpCommandFactory();
12+
Assert.NotNull(factory);
13+
}
14+
15+
[Fact]
16+
public void Constructor_with_fileOpener()
17+
{
18+
var factory = new AMNetScpCommandFactory(new AMNetScpFileOpener());
19+
Assert.NotNull(factory);
20+
}
21+
22+
[Fact]
23+
public void Constructor_null_fileOpener_throws()
24+
{
25+
Assert.Throws<ArgumentNullException>(() => new AMNetScpCommandFactory(null!));
26+
}
27+
28+
[Fact]
29+
public void SendBufferSize_default_not_zero()
30+
{
31+
var factory = new AMNetScpCommandFactory();
32+
Assert.True(factory.SendBufferSize > 0);
33+
}
34+
35+
[Fact]
36+
public void SendBufferSize_roundtrip()
37+
{
38+
var factory = new AMNetScpCommandFactory();
39+
factory.SendBufferSize = 65536;
40+
Assert.Equal(65536, factory.SendBufferSize);
41+
}
42+
43+
[Fact]
44+
public void ReceiveBufferSize_default_not_zero()
45+
{
46+
var factory = new AMNetScpCommandFactory();
47+
Assert.True(factory.ReceiveBufferSize > 0);
48+
}
49+
50+
[Fact]
51+
public void ReceiveBufferSize_roundtrip()
52+
{
53+
var factory = new AMNetScpCommandFactory();
54+
factory.ReceiveBufferSize = 32768;
55+
Assert.Equal(32768, factory.ReceiveBufferSize);
56+
}
57+
58+
[Fact]
59+
public void addEventListener_returns_true()
60+
{
61+
var factory = new AMNetScpCommandFactory();
62+
var listener = new AMNetScpTransferEventListener();
63+
Assert.True(factory.addEventListener(listener));
64+
}
65+
66+
[Fact]
67+
public void addEventListener_null_throws()
68+
{
69+
var factory = new AMNetScpCommandFactory();
70+
Assert.Throws<ArgumentNullException>(() => factory.addEventListener(null!));
71+
}
72+
73+
[Fact]
74+
public void addEventListener_duplicate_returns_false()
75+
{
76+
var factory = new AMNetScpCommandFactory();
77+
var listener = new AMNetScpTransferEventListener();
78+
Assert.True(factory.addEventListener(listener));
79+
Assert.False(factory.addEventListener(listener));
80+
}
81+
82+
[Fact]
83+
public void removeEventListener_returns_true()
84+
{
85+
var factory = new AMNetScpCommandFactory();
86+
var listener = new AMNetScpTransferEventListener();
87+
factory.addEventListener(listener);
88+
Assert.True(factory.removeEventListener(listener));
89+
}
90+
91+
[Fact]
92+
public void removeEventListener_not_registered_returns_false()
93+
{
94+
var factory = new AMNetScpCommandFactory();
95+
var listener = new AMNetScpTransferEventListener();
96+
Assert.False(factory.removeEventListener(listener));
97+
}
98+
99+
[Fact]
100+
public void removeEventListener_null_throws()
101+
{
102+
var factory = new AMNetScpCommandFactory();
103+
Assert.Throws<ArgumentNullException>(() => factory.removeEventListener(null!));
104+
}
105+
106+
[Fact]
107+
public void setFileOpener_accepts_opener()
108+
{
109+
var factory = new AMNetScpCommandFactory();
110+
factory.setFileOpener(new AMNetScpFileOpener("/root"));
111+
}
112+
113+
[Fact]
114+
public void setFileOpener_null_throws()
115+
{
116+
var factory = new AMNetScpCommandFactory();
117+
Assert.Throws<ArgumentNullException>(() => factory.setFileOpener(null!));
118+
}
119+
}

0 commit comments

Comments
 (0)