public async Task CloseAsyncIsRanOnce() { // ARRANGE var mock = new HassWebSocketMock(); // Get the connected hass client await using IHassClient hassClient = await mock.GetHassConnectedClient().ConfigureAwait(false); await hassClient.CloseAsync().ConfigureAwait(false); // ASSERT mock.Verify( x => x.CloseOutputAsync(It.IsAny <WebSocketCloseStatus>(), It.IsAny <string>(), It.IsAny <CancellationToken>()), Times.Once); }
public async Task ConnectWithSslShouldStartWithWss() { // ARRANGE var mock = new HassWebSocketMock(); // Get the default state hass client and we add no response messages await using var hassClient = mock.GetHassClient(); // First message from Home Assistant is auth required mock.AddResponse(@"{""type"": ""auth_required""}"); // Next one we fake it is auth ok mock.AddResponse(@"{""type"": ""auth_ok""}"); // ACT and ASSERT // Connect with ssl await hassClient.ConnectAsync("localhost", 8123, true, "FAKETOKEN", false).ConfigureAwait(false); mock.Verify( n => n.ConnectAsync(new Uri("wss://localhost:8123/api/websocket"), It.IsAny <CancellationToken>()), Times.Once); }