File tree Expand file tree Collapse file tree 6 files changed +47
-34
lines changed
nunit.engine.core/Communication
nunit.engine/Communication/Transports/Tcp Expand file tree Collapse file tree 6 files changed +47
-34
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ namespace NUnit.Engine.Communication.Messages
88 public class CommandMessage : TestEngineMessage
99 {
1010 public CommandMessage ( string commandName , params object [ ] arguments )
11+ : base ( MessageCode . FromCommand ( commandName ) , null )
1112 {
1213 CommandName = commandName ;
1314 Arguments = arguments ;
Original file line number Diff line number Diff line change 11// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt
22
3+ using System ;
4+
35namespace NUnit . Engine . Communication . Messages
46{
57 public class MessageCode
@@ -20,5 +22,32 @@ public class MessageCode
2022
2123 public const string ProgressReport = "PROG" ;
2224 public const string CommandResult = "RSLT" ;
25+
26+ public static string FromCommand ( string command )
27+ {
28+ switch ( command )
29+ {
30+ case "CreateRunner" :
31+ return CreateRunner ;
32+ case "Load" :
33+ return LoadCommand ;
34+ case "Reload" :
35+ return ReloadCommand ;
36+ case "Unload" :
37+ return UnloadCommand ;
38+ case "Explore" :
39+ return ExploreCommand ;
40+ case "CountTestCases" :
41+ return CountCasesCommand ;
42+ case "Run" :
43+ return RunCommand ;
44+ case "RunAsync" :
45+ return RunAsyncCommand ;
46+ case "Stop" :
47+ return RequestStopCommand ;
48+ default :
49+ throw new ArgumentException ( "Invalid command" , nameof ( command ) ) ;
50+ }
51+ }
2352 }
2453}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 55namespace NUnit . Engine . Communication . Messages
66{
77 [ Serializable ]
8- public abstract class TestEngineMessage
8+ public class TestEngineMessage
99 {
10- // public TestEngineMessage(string code, string data)
11- // {
12- // Code = code;
13- // Data = data;
14- // }
10+ public TestEngineMessage ( string code , string data )
11+ {
12+ Code = code ;
13+ Data = data ;
14+ }
1515
16- // protected TestEngineMessage() { }
16+ protected TestEngineMessage ( ) { }
1717
18- // public string Code { get; }
19- // public string Data { get; }
18+ public string Code { get ; }
19+ public string Data { get ; }
2020
21- // // Alias properties for convenience
22- // //public string CommandName => Code;
23- // //public string Argument => Data;
21+ // Alias properties for convenience
22+ //public string CommandName => Code;
23+ //public string Argument => Data;
2424 }
2525}
Original file line number Diff line number Diff line change @@ -129,7 +129,8 @@ private void SendResult(object result)
129129
130130 public void OnTestEvent ( string report )
131131 {
132- var progressMessage = new ProgressMessage ( report ) ;
132+ //var progressMessage = new ProgressMessage(report);
133+ var progressMessage = new TestEngineMessage ( MessageCode . ProgressReport , report ) ;
133134 var bytes = new BinarySerializationProtocol ( ) . Encode ( progressMessage ) ;
134135 _clientSocket . Send ( bytes ) ;
135136 }
Original file line number Diff line number Diff line change @@ -119,11 +119,10 @@ private TestEngineResult TestRunResult(ITestEventListener listener)
119119 if ( returnMessage != null )
120120 return ( TestEngineResult ) returnMessage . ReturnValue ;
121121
122- var progressMessage = receivedMessage as ProgressMessage ;
123- if ( progressMessage == null )
122+ if ( receivedMessage . Code == MessageCode . ProgressReport )
123+ listener . OnTestEvent ( receivedMessage . Data ) ;
124+ else
124125 throw new InvalidOperationException ( $ "Expected either a ProgressMessage or a CommandReturnMessage but received a { receivedType } ") ;
125-
126- listener . OnTestEvent ( progressMessage . Report ) ;
127126 }
128127 }
129128 }
You can’t perform that action at this time.
0 commit comments