public Task InitializeAsync() { Logger = new TestableLogger(); LoggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(c => { c.AddConsole(); c.ConfigureTestableLogger(Logger); }); LogoHardwareMock = new LogoHardwareMock(); Logo = CreateLogo(); Logo.Connect(); return(Task.CompletedTask); }
public async Task InitializeAsync() { Logger = new TestableLogger(); LoggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(c => c.ConfigureTestableLogger(Logger)); LogoHardwareMock = new LogoHardwareMock(); var brokerIpAddress = IPAddress.Loopback; var brokerPort = 1889; var mqttFactory = new MqttFactory(); mqttServer = mqttFactory.CreateMqttServer(); MqttClient = mqttFactory.CreateMqttClient(); MqttClient.ApplicationMessageReceivedHandler = new MqttApplicationMessageReceivedHandlerDelegate(args => MqttMessageReceived?.Invoke(this, args)); var mqttServerOptions = new MqttServerOptionsBuilder() .WithClientId(nameof(IntegrationTestEnvironment) + "Broker") .WithDefaultEndpointBoundIPAddress(brokerIpAddress) .WithDefaultEndpointPort(brokerPort) .Build(); var mqttClientOptions = new MqttClientOptionsBuilder() .WithClientId(nameof(IntegrationTestEnvironment) + "Client") .WithTcpServer(brokerIpAddress.ToString(), brokerPort) .Build(); await mqttServer .StartAsync(mqttServerOptions) .ConfigureAwait(false); await MqttClient .ConnectAsync(mqttClientOptions) .ConfigureAwait(false); var config = IntegrationTests.GetConfig(brokerIpAddress.ToString(), brokerPort); config.Validate(); appContext = Logic .Initialize(LoggerFactory, config); await appContext .Connect() .ConfigureAwait(false); }
public async Task DisposeAsync() { if (appContext != null) { await appContext .DisposeAsync() .ConfigureAwait(false); } await MqttClient .DisconnectAsync() .ConfigureAwait(false); if (mqttServer != null) { await mqttServer .StopAsync() .ConfigureAwait(false); } LogoHardwareMock?.Dispose(); }
public async Task DisposeAsync() { await Logo.DisposeAsync().ConfigureAwait(false); LogoHardwareMock.Dispose(); }