-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced the `Initialize` method for device initialization, ensuring proper setup for client devices.
- Loading branch information
Showing
6 changed files
with
118 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Asv.Cfg.Test; | ||
using Asv.IO; | ||
using Asv.IO.Device; | ||
using FluentAssertions; | ||
using JetBrains.Annotations; | ||
using TimeProviderExtensions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Asv.IO.Test.Devices.Explorer; | ||
|
||
[TestSubject(typeof(DeviceExplorer))] | ||
public class DeviceExplorerTest:IDisposable | ||
{ | ||
private readonly ManualTimeProvider _routerTime; | ||
private readonly IVirtualConnection _link; | ||
private readonly IDeviceExplorer _explorer; | ||
private readonly ClientDeviceBrowserConfig _explorerConfig; | ||
|
||
public DeviceExplorerTest(ITestOutputHelper log) | ||
{ | ||
_routerTime = new ManualTimeProvider(); | ||
var loggerFactory = new TestLoggerFactory(log, _routerTime, "ROUTER"); | ||
var protocol = Protocol.Create(builder => | ||
{ | ||
builder.SetLog(loggerFactory); | ||
builder.SetTimeProvider(_routerTime); | ||
builder.Protocols.RegisterExampleProtocol(); | ||
builder.Formatters.RegisterSimpleFormatter(); | ||
}); | ||
_link = protocol.CreateVirtualConnection(); | ||
|
||
_explorerConfig = new ClientDeviceBrowserConfig | ||
{ | ||
DeviceTimeoutMs = 100, | ||
DeviceCheckIntervalMs = 100 | ||
}; | ||
_explorer = DeviceExplorer.Create(_link.Client, builder => | ||
{ | ||
builder.SetTimeProvider(_routerTime); | ||
builder.SetLog(loggerFactory); | ||
builder.SetConfig(_explorerConfig); | ||
builder.Factories.RegisterExampleDevice(new ExampleDeviceConfig()); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public async Task DeviceList_CreateAndRemoveDevices_Success() | ||
{ | ||
Assert.Equal(0, _explorer.Devices.Count); | ||
|
||
await _link.Server.Send(new ExampleMessage1 { SenderId = 1 }); | ||
Assert.Equal(1, _explorer.Devices.Count); | ||
|
||
await _link.Server.Send(new ExampleMessage1 { SenderId = 1 }); | ||
Assert.Equal(1, _explorer.Devices.Count); | ||
|
||
await _link.Server.Send(new ExampleMessage1 { SenderId = 3 }); | ||
Assert.Equal(2, _explorer.Devices.Count); | ||
|
||
_routerTime.Advance(TimeSpan.FromMilliseconds(Math.Max(_explorerConfig.DeviceTimeoutMs, _explorerConfig.DeviceCheckIntervalMs))); | ||
Assert.Equal(0, _explorer.Devices.Count); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_explorer.Dispose(); | ||
_link.Dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters