1
1
using System ;
2
+ using System . Collections . Generic ;
2
3
using System . IO ;
3
4
using System . Linq ;
4
5
using Medallion . Shell ;
5
6
using NUnit . Framework ;
7
+ using OData2Poco . Extension ;
6
8
7
9
namespace OData2Poco . CommandLine . Test
8
10
{
11
+ public enum ExitCodes
12
+ {
13
+ Success = 0 ,
14
+ ArgumentsInvalid = - 1 ,
15
+ HandledException = - 2 ,
16
+ UnhandledException = - 99 ,
17
+ }
18
+
9
19
/*
10
20
* Note for text contain check for properties of class
11
21
* all properties are declared with one and only one space between words
@@ -14,10 +24,31 @@ namespace OData2Poco.CommandLine.Test
14
24
[ TestFixture ]
15
25
public class ProgramTests
16
26
{
27
+ private static string WorkingDirectory = "." ;
17
28
private const double Timeout = 3 * 60 ; //sec
29
+ //const string folder = @"F:\odata2poco-dotnet\dotnet-o2pgen-v0-3-1-2019\dotnet-o2pgen\OData2Poco.CommandLine\bin\Debug\netcoreapp2.1\";
30
+ // private const string appCommand = "\"dotnet o2pgen.dll\"";
31
+ //private static string appCommand = $"dotnet {folder}O2Pgen.dll";
32
+ //#if NETFULL
18
33
private const string appCommand = @"o2pgen" ;
19
- static Func < string , Medallion . Shell . Command > TestCommand = ( s => Medallion . Shell . Command . Run ( appCommand , s . Split ( ' ' ) ,
20
- options => options . Timeout ( TimeSpan . FromSeconds ( Timeout ) ) ) ) ;
34
+ //#else
35
+ // private const string appCommand = @"dotnet-o2pgen";
36
+ //#endif
37
+ [ OneTimeSetUp ]
38
+ public void SetupOneTime ( )
39
+ {
40
+ Environment . CurrentDirectory = TestContext . CurrentContext . TestDirectory ;
41
+ Console . WriteLine ( $ "TestBase.Init: Environment.CurrentDirectory: { Environment . CurrentDirectory } ") ;
42
+ WorkingDirectory = Environment . CurrentDirectory ;
43
+ }
44
+
45
+ private static Func < string , Medallion . Shell . Command > TestCommand = ( s =>
46
+ {
47
+ string [ ] args = s . Split ( new [ ] { ' ' } , StringSplitOptions . RemoveEmptyEntries ) ;
48
+ Console . WriteLine ( args . Dump ( ) ) ;
49
+ return Medallion . Shell . Command . Run ( appCommand , args ,
50
+ options => options . Timeout ( TimeSpan . FromSeconds ( Timeout ) ) ) ;
51
+ } ) ;
21
52
22
53
/// <summary>
23
54
/// exitcode = tuble.item1 , output= tuble.item2
@@ -29,10 +60,22 @@ public class ProgramTests
29
60
/// </remarks>
30
61
private Func < string , Tuple < int , string > > RunCommand = ( s =>
31
62
{
32
- var command = Medallion . Shell . Command . Run ( appCommand , s . Split ( ' ' ) ,
33
- options => options . Timeout ( TimeSpan . FromSeconds ( Timeout ) ) ) ;
63
+ Console . WriteLine ( $ "WorkingDirectory: { WorkingDirectory } ") ;
64
+
65
+ string [ ] args = s . Split ( new [ ] { ' ' } , StringSplitOptions . RemoveEmptyEntries ) ;
66
+
67
+ //Console.WriteLine(appCommand);
68
+
69
+ var command = Medallion . Shell . Command . Run ( appCommand , args ,
70
+ options =>
71
+ {
72
+ options . Timeout ( TimeSpan . FromSeconds ( Timeout ) ) ;
73
+ options . WorkingDirectory ( WorkingDirectory ) ;
74
+
75
+ } ) ;
34
76
35
77
var outText = command . Result . StandardOutput ;
78
+ //Console.WriteLine(outText);
36
79
var errText = command . Result . StandardError ;
37
80
var exitCode = command . Result . ExitCode ;
38
81
Tuple < int , string > tuple = new Tuple < int , string > ( exitCode , outText + "\n " + errText ) ;
@@ -63,8 +106,8 @@ public void PocoSettingTest(string url, string version, int n)
63
106
var tuble = RunCommand ( a ) ;
64
107
var output = tuble . Item2 ;
65
108
Assert . AreEqual ( 0 , tuble . Item1 ) ;
66
- // Console.WriteLine(tuble.Item2);
67
-
109
+ // Console.WriteLine(tuble.Item2);
110
+
68
111
Assert . IsTrue ( output . Contains ( "public class Product" ) ) ;
69
112
Assert . IsTrue ( output . Contains ( "[Table(\" Products\" )]" ) ) ; //-t
70
113
Assert . IsTrue ( output . Contains ( "System.ComponentModel.DataAnnotations.Schema" ) ) ; //-t
@@ -79,7 +122,7 @@ public void PocoSettingTest(string url, string version, int n)
79
122
[ Test ]
80
123
public void PocoWithInheritanceTest ( )
81
124
{
82
- var url = "http://services.odata.org/V4/TripPinServiceRW/" ;
125
+ var url = "http://services.odata.org/V4/TripPinServiceRW/" ;
83
126
var a = $ "-r { url } -v";
84
127
85
128
var tuble = RunCommand ( a ) ;
@@ -148,12 +191,12 @@ public void NullableDatatypeTest(string url, string version, int n)
148
191
var tuble = RunCommand ( a ) ;
149
192
var output = tuble . Item2 ;
150
193
Assert . AreEqual ( 0 , tuble . Item1 ) ;
151
- // Console.WriteLine(tuble.Item2);
194
+ // Console.WriteLine(tuble.Item2);
152
195
153
196
Assert . IsTrue ( output . Contains ( "public class Product" ) ) ;
154
197
Assert . IsTrue ( output . Contains ( "virtual public Supplier Supplier {get;set;}" ) ) ; //-n
155
198
Assert . IsTrue ( output . Contains ( "int?" ) ) ; //-b
156
-
199
+
157
200
}
158
201
159
202
[ Test ]
@@ -181,13 +224,13 @@ public void PocoSettingWithJsonAttributeAndCamelCaseTest(string url, string vers
181
224
var tuble = RunCommand ( a ) ;
182
225
var output = tuble . Item2 ;
183
226
//Assert.AreEqual(0, tuble.Item1);
184
- // Console.WriteLine(tuble.Item2);
227
+ // Console.WriteLine(tuble.Item2);
185
228
Assert . IsTrue ( output . Contains ( "public class Category" ) ) ;
186
- Assert . IsTrue ( output . Contains ( "[JsonProperty(PropertyName = \" CategoryName\" )]" ) , "itshould be CategoryName" ) ;
229
+ Assert . IsTrue ( output . Contains ( "[JsonProperty(PropertyName = \" CategoryName\" )]" ) , "itshould be CategoryName" ) ;
187
230
Assert . IsTrue ( output . Contains ( "categoryName" ) ) ;
188
231
Assert . IsTrue ( output . Contains ( "[JsonProperty(PropertyName = \" CategoryID\" )]" ) ) ;
189
232
Assert . IsTrue ( output . Contains ( "category" ) ) ;
190
-
233
+
191
234
192
235
}
193
236
@@ -207,8 +250,8 @@ public void PocoSettingWithJsonAttributePasCaseTest(string url, string version,
207
250
Assert . IsTrue ( output . Contains ( "CategoryName" ) ) ;
208
251
209
252
}
210
-
211
-
253
+
254
+
212
255
[ Test ]
213
256
[ TestCaseSource ( typeof ( TestSample ) , "UrlCases" ) ]
214
257
public void PocoSettingEagerTest ( string url , string version , int n )
@@ -217,23 +260,23 @@ public void PocoSettingEagerTest(string url, string version, int n)
217
260
var tuble = RunCommand ( a ) ;
218
261
var output = tuble . Item2 ;
219
262
Assert . AreEqual ( 0 , tuble . Item1 ) ;
220
- // Console.WriteLine(tuble.Item2);
221
-
263
+ // Console.WriteLine(tuble.Item2);
264
+
222
265
Assert . IsTrue ( output . Contains ( "public class Product" ) ) ; //-v
223
266
Assert . IsTrue ( output . Contains ( "public Supplier Supplier {get;set;}" ) ) ; //-e
224
-
267
+
225
268
}
226
269
227
270
[ Test ]
228
271
[ TestCaseSource ( typeof ( TestSample ) , "UrlCases" ) ]
229
272
public void PocoSettingInheritTest ( string url , string version , int n )
230
273
{
231
- var a = string . Format ( "-r {0} -v -i {1}" , url , "MyBaseClass,MyInterface" ) ;
274
+ var a = string . Format ( "-r {0} -v -i {1}" , url , "MyBaseClass,MyInterface" ) ;
232
275
var tuble = RunCommand ( a ) ;
233
276
var output = tuble . Item2 ;
234
277
Assert . AreEqual ( 0 , tuble . Item1 ) ;
235
278
// Console.WriteLine(tuble.Item2);
236
-
279
+
237
280
Assert . IsTrue ( output . Contains ( "public class Product : MyBaseClass,MyInterface" ) ) ; //-i, -v
238
281
239
282
}
@@ -259,7 +302,7 @@ public void FileDefaultSettingTest(string url, string version, int n)
259
302
var a = string . Format ( "-r {0} -v " , url ) ;
260
303
var tuble = RunCommand ( a ) ;
261
304
var output = tuble . Item2 ;
262
-
305
+
263
306
Assert . AreEqual ( 0 , tuble . Item1 ) ;
264
307
//Console.WriteLine(tuble.Item2);
265
308
Assert . IsTrue ( output . Contains ( "public class Product" ) ) ;
0 commit comments