public void NetworkManagerProtocolErrorTest() { // arrange // SensorValueRawDataModel string sendMessage = NetworkProtocol.CreateMessage("Das ist kein Json objekt"); NetworkManager host = new NetworkManager(5000); host.DataFormat = DataFormat.JsonObject; string receivedResult = string.Empty; host.NetworkMessageEvent += delegate(object sender, NetworkMessageEventArgs args) { receivedResult = args.Message; }; NetworkManagerClient client = new NetworkManagerClient(); // act bool resultStart = host.Start(); NetworkManagerState resultState = host.State; string connectResult = client.Connect(5000); client.Send(Encoding.UTF8.GetBytes(sendMessage)); // assert Assert.IsTrue(resultStart, "Start result must be 'True'"); Assert.IsTrue(resultState == NetworkManagerState.Running, "The state must be 'Running'"); Assert.IsTrue(connectResult == "Success", "The connect methode must return 'Success'"); Assert.IsTrue(receivedResult == "ERROR", "The result of received message must be 'ERROR'"); }
public async Task NetworkManagerProtocolTest() { // arrange // SensorValueRawDataModel string sendMessage = NetworkProtocol.CreateMessage("{\"UID\":123,\"IsValid\":true,\"TimeStamp\":\"0001-01-01T00:00:00\",\"SensorType\":1,\"RawValue\":1234}"); NetworkManager host = new NetworkManager(5000); host.DataFormat = DataFormat.JsonObject; string resultReceived = string.Empty; host.NetworkMessageEvent += delegate(object sender, NetworkMessageEventArgs args) { resultReceived = args.Message; }; string resultShutdown = string.Empty; host.NetworkMessageShutdownEvent += delegate(object sender, NetworkMessageEventArgs args) { resultShutdown = args.Message; throw new Exception(resultShutdown); }; Stopwatch sw = new Stopwatch(); sw.Start(); StringBuilder sbStateMessages = new StringBuilder(); host.NetworkLogEvent += delegate(string stateMessage) { sbStateMessages.AppendLine($"{stateMessage}, Time: {sw.ElapsedMilliseconds}ms"); }; NetworkManagerClient client = new NetworkManagerClient(); // act bool resultStart = host.Start(); NetworkManagerState resultState = host.State; string connectResult = client.Connect(5000); client.Send(Encoding.UTF8.GetBytes(sendMessage)); await Task.Delay(1000); // assert sw.Stop(); Assert.IsTrue(resultStart, "Start result must be 'True': " + sbStateMessages.ToString()); Assert.IsTrue(resultState == NetworkManagerState.Running, "The state must be 'Running'"); Assert.IsTrue(connectResult == "Success", "The connect methode must return 'Success'"); Assert.IsTrue(resultReceived == sendMessage, "Received message must the same of sended message."); }