public async Task FahClientConnection_WritesCommandsAndReadsMessageAsynchronously() { using (var connection = new FahClientConnection(Host, Port)) { await connection.OpenAsync(); var command = connection.CreateCommand(); command.CommandText = "info"; await command.ExecuteAsync(); var reader = connection.CreateReader(); if (await reader.ReadAsync()) { Console.WriteLine(reader.Message); } command.CommandText = "log-updates restart"; await command.ExecuteAsync(); if (await reader.ReadAsync()) { Console.WriteLine(reader.Message); } } }
public async Task FahClientConnection_CloseConnectionWhileExecutingReaderAsynchronously() { using (var connection = new FahClientConnection(Host, Port)) { await connection.OpenAsync(); CloseConnectionAfter(3000, connection); var command = connection.CreateCommand(); command.CommandText = "info"; await command.ExecuteAsync(); command.CommandText = "log-updates restart"; await command.ExecuteAsync(); var reader = connection.CreateReader(); try { while (await reader.ReadAsync()) { Console.WriteLine(reader.Message); } } catch (Exception ex) { Assert.IsFalse(connection.Connected); Console.WriteLine(ex); } } }
public async Task FahClientConnection_CloseConnectionWhileExecutingCommandAsynchronously() { using (var connection = new FahClientConnection(Host, Port)) { await connection.OpenAsync(); CloseConnectionAfter(1000, connection); var command = connection.CreateCommand(); command.CommandText = "info"; try { // continually execute the command while (await command.ExecuteAsync() > 0) { } } catch (Exception ex) { Assert.IsFalse(connection.Connected); Console.WriteLine(ex); } } }
public void FahClientConnection_SimulateHFMUpdateCommandsSynchronously() { using (var connection = new FahClientConnection(Host, Port)) { connection.Open(); connection.CreateCommand("log-updates restart").Execute(); connection.CreateCommand("updates add 0 60 $heartbeat").Execute(); connection.CreateCommand("updates add 1 1 $info").Execute(); connection.CreateCommand("updates add 2 1 $(options -a)").Execute(); connection.CreateCommand("updates add 3 1 $slot-info").Execute(); var reader = connection.CreateReader(); for (int i = 0; i < 10 && reader.Read(); i++) { Console.WriteLine(reader.Message); } } }
public void FahClientConnection_CreateCommandReturnsCommandWhenNotConnected() { // Arrange using (var connection = new FahClientConnection("foo", 2000)) { // Act var command = connection.CreateCommand(); // Assert Assert.IsNotNull(command); } }
public void FahClientConnection_CreateCommandReturnsCommandWithCommandText() { // Arrange using (var connection = new FahClientConnection("foo", 2000)) { // Act var command = connection.CreateCommand("bar"); // Assert Assert.IsNotNull(command); Assert.AreEqual("bar", command.CommandText); } }
public void FahClientConnection_WritesCommandsAndReadsMessageSynchronously() { using (var connection = new FahClientConnection(Host, Port)) { connection.Open(); var command = connection.CreateCommand(); command.CommandText = "info"; command.Execute(); var reader = connection.CreateReader(); if (reader.Read()) { Console.WriteLine(reader.Message); } command.CommandText = "log-updates restart"; command.Execute(); if (reader.Read()) { Console.WriteLine(reader.Message); } } }