1
1
using System ;
2
2
using System . Diagnostics ;
3
+ using System . Linq ;
4
+ using CommandLine ;
3
5
using Medallion . Shell ;
4
6
using NUnit . Framework ;
5
7
@@ -15,7 +17,7 @@ public class ProgramTests
15
17
{
16
18
private const double Timeout = 3 * 60 ; //sec
17
19
private const string appCommand = @"o2pgen" ;
18
- static Func < string , Command > TestCommand = ( s => Command . Run ( appCommand , s . Split ( ' ' ) ,
20
+ static Func < string , Medallion . Shell . Command > TestCommand = ( s => Medallion . Shell . Command . Run ( appCommand , s . Split ( ' ' ) ,
19
21
options => options . Timeout ( TimeSpan . FromSeconds ( Timeout ) ) ) ) ;
20
22
21
23
/// <summary>
@@ -28,7 +30,7 @@ public class ProgramTests
28
30
/// </remarks>
29
31
private Func < string , Tuple < int , string > > RunCommand = ( s =>
30
32
{
31
- var command = Command . Run ( appCommand , s . Split ( ' ' ) ,
33
+ var command = Medallion . Shell . Command . Run ( appCommand , s . Split ( ' ' ) ,
32
34
options => options . Timeout ( TimeSpan . FromSeconds ( Timeout ) ) ) ;
33
35
34
36
var outText = command . Result . StandardOutput ;
@@ -75,6 +77,70 @@ public void PocoSettingTest(string url, string version, int n)
75
77
Assert . IsFalse ( output . Contains ( "public class Product :" ) ) ; // -i is not set
76
78
}
77
79
80
+ [ Test ]
81
+ public void PocoWithInheritanceTest ( )
82
+ {
83
+ var url = "http://services.odata.org/V4/TripPinServiceRW/" ;
84
+ var a = $ "-r { url } -v";
85
+
86
+ var tuble = RunCommand ( a ) ;
87
+ var output = tuble . Item2 ;
88
+
89
+ Assert . IsTrue ( output . Contains ( "public class PublicTransportation : PlanItem" ) ) ;
90
+ }
91
+
92
+ [ Test ( Description = "If model inheritance is used (the default) check that the propterties of a base calsss are not duplicated inderived classes" ) ]
93
+ public void PropertyInheritenceTest ( )
94
+ {
95
+ var url = "http://services.odata.org/V4/TripPinServiceRW/" ;
96
+ var a = $ "-r { url } -v";
97
+
98
+ var tuble = RunCommand ( a ) ;
99
+ var output = tuble . Item2 ;
100
+
101
+ var lines = output . Split ( '\n ' ) ;
102
+ var occurneces = lines . Count ( l => l . Contains ( "public int PlanItemId" ) ) ;
103
+
104
+ Assert . IsTrue ( occurneces == 1 ) ; // For inheritance, check that PlanItemId property only occurs in the base class
105
+
106
+ }
107
+ [ Test ]
108
+ public void PocoWithBaseClassTest ( )
109
+ {
110
+ var url = "http://services.odata.org/V4/TripPinServiceRW/" ;
111
+ const string myBaseClass = nameof ( myBaseClass ) ;
112
+
113
+ var a = $ "-r { url } -v -i { myBaseClass } ";
114
+
115
+ var tuble = RunCommand ( a ) ;
116
+ var output = tuble . Item2 ;
117
+
118
+ Assert . IsTrue ( output . Contains ( $ "public class PublicTransportation : { myBaseClass } ") ) ;
119
+
120
+ var lines = output . Split ( '\n ' ) ;
121
+ var occurneces = lines . Count ( l => l . Contains ( "public int PlanItemId" ) ) ;
122
+
123
+ Assert . IsTrue ( occurneces > 1 ) ;
124
+ }
125
+
126
+ [ Test ( Description = "If model inheritance is not used, the properties from a base class should by duplicated in the derived classes." ) ]
127
+ public void PropertyDuplicationTest ( )
128
+ {
129
+ var url = "http://services.odata.org/V4/TripPinServiceRW/" ;
130
+ const string myBaseClass = nameof ( myBaseClass ) ;
131
+
132
+ var a = $ "-r { url } -v -i { myBaseClass } ";
133
+
134
+ var tuble = RunCommand ( a ) ;
135
+ var output = tuble . Item2 ;
136
+
137
+ var lines = output . Split ( '\n ' ) ;
138
+ var occurneces = lines . Count ( l => l . Contains ( "public int PlanItemId" ) ) ;
139
+
140
+ Assert . IsTrue ( occurneces > 1 ) ; // If not using model inheritance, check that the PlanItemId property is duplicated in derived classes
141
+
142
+ }
143
+
78
144
[ Test ]
79
145
[ TestCaseSource ( typeof ( TestSample ) , "UrlCases" ) ]
80
146
public void NullableDatatypeTest ( string url , string version , int n )
@@ -183,7 +249,7 @@ public void PocoSettingNamespaceTest(string url, string version, int n)
183
249
Assert . AreEqual ( 0 , tuble . Item1 ) ;
184
250
// Console.WriteLine(tuble.Item2);
185
251
186
- Assert . IsTrue ( output . Contains ( "MyNamespace1.MyNamespace2." ) ) ; //-i , -v
252
+ Assert . IsTrue ( output . Contains ( "MyNamespace1.MyNamespace2." ) ) ; //-m , -v
187
253
188
254
}
189
255
@@ -287,6 +353,27 @@ public void InValidArgumentTest(string url, string version, int n)
287
353
//}
288
354
289
355
356
+ [ Test ]
357
+ public void InheritanceEnabledByDefaultTest ( )
358
+ {
359
+ var a = new string [ ] { } ;
360
+
361
+ var options = new Options ( ) ;
362
+ Parser . Default . ParseArguments ( a , options ) ;
363
+ var command = new Command ( options ) ;
290
364
291
- } //
365
+ Assert . IsTrue ( command . PocoSettingOptions . UseInheritance ) ;
366
+ }
367
+ [ Test ]
368
+ public void InheritanceDisabledWithInheritSettingTest ( )
369
+ {
370
+ var a = new [ ] { "-i" , "MyBaseClass" } ;
371
+
372
+ var options = new Options ( ) ;
373
+ Parser . Default . ParseArguments ( a , options ) ;
374
+ var command = new Command ( options ) ;
375
+
376
+ Assert . IsFalse ( command . PocoSettingOptions . UseInheritance ) ;
377
+ }
378
+ }
292
379
} //
0 commit comments