Skip to content

Commit c62d804

Browse files
committed
build .NetCore Global Tool v3
1 parent cb2149b commit c62d804

26 files changed

+315
-414
lines changed

Directory.Build.props

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<Project>
2+
<PropertyGroup>
3+
<SolutionDir Condition="'$(SolutionDir)'==''">$(MSBuildThisFileDirectory)</SolutionDir>
4+
<!--<GenerateAssemblyInfo>false</GenerateAssemblyInfo>-->
5+
<LangVersion>7.3</LangVersion>
6+
<Authors>Mohamed Hassan</Authors>
7+
<Copyright>Copyright © 2016-2018, Mohamed Hassan </Copyright>
8+
<Product>OData2Poco</Product>
9+
<PackageLicenseUrl>https://github.com/moh-hassan/odata2poco/blob/master/license.txt?raw=true</PackageLicenseUrl>
10+
<PackageProjectUrl>https://github.com/moh-hassan/odata2poco</PackageProjectUrl>
11+
<PackageIconUrl>https://github.com/moh-hassan/odata2poco/blob/master/ODataLogo-32.ico?raw=true </PackageIconUrl>
12+
<RepositoryUrl>https://github.com/moh-hassan/odata2poco</RepositoryUrl>
13+
<PackageTags>OData poco code-generation</PackageTags>
14+
<Description>OData2Poco is a tool to generate plain-old CLR objects (POCO) from OData feeds V1-V4 OData protocol.The generation is based on the XML metadata of the service stored on the server. POCO classes can be used in typed RESTful client OData services.</Description>
15+
<IsTestProject>$(MSBuildProjectName.Contains('Test'))</IsTestProject>
16+
<Company>OData2Poco</Company>
17+
<PackageReleaseNotes>https://github.com/moh-hassan/odata2poco/blob/master/ReleaseNotes.md </PackageReleaseNotes>
18+
<PackageTags>OData poco code-generation</PackageTags>
19+
<!-- Disable warnings from XML documentation.-->
20+
<NoWarn>$(NoWarn);1570;1572;1573;1587</NoWarn>
21+
</PropertyGroup>
22+
23+
<!-- version -->
24+
<PropertyGroup>
25+
<Version>3.0.0</Version>
26+
<AssemblyVersion>3.0.0.0</AssemblyVersion>
27+
</PropertyGroup>
28+
29+
30+
<ItemGroup Condition="'$(IsTestProject)' == 'true'">
31+
<PackageReference Include="nunit" Version="3.11.0" />
32+
<PackageReference Include="NUnit3TestAdapter" Version="3.12.0" />
33+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
34+
</ItemGroup>
35+
36+
</Project>

OData2Poco.CommandLine.Test/OData2Poco.CommandLine.Test.csproj

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net45</TargetFramework>
4-
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
5-
<ApplicationIcon>ODataLogo-32.ico</ApplicationIcon>
3+
<TargetFramework>net452</TargetFramework>
4+
<!--<TargetFrameworks>netcoreapp2.0;net45</TargetFrameworks>-->
5+
<!--<GenerateAssemblyInfo>false</GenerateAssemblyInfo>-->
66
<Authors>Mohamed Hassan</Authors>
7-
<Copyright>Copyright © Mohamed Hassan 2016</Copyright>
87
<AssemblyTitle>OData2Poco.Tests</AssemblyTitle>
9-
<Company>OData2Poco</Company>
108
<Product>OData2Poco</Product>
9+
<IsTestProject>true</IsTestProject>
1110
</PropertyGroup>
1211
<ItemGroup>
1312
<Compile Include="..\CommonTestData.cs" Link="CommonTestData.cs" />
1413
</ItemGroup>
1514

15+
<PropertyGroup Condition=" '$(TargetFramework)' == 'net45'">
16+
<DefineConstants>NET45;NETFULL</DefineConstants>
17+
</PropertyGroup>
1618

1719
<ItemGroup>
1820
<PackageReference Include="MedallionShell" Version="1.5.1" />
19-
<PackageReference Include="NUnit" Version="2.6.4" />
2021
</ItemGroup>
2122

23+
<!--<ItemGroup>
24+
<PackageReference Include="nunit" Version="3.11.0" />
25+
<PackageReference Include="NUnit3TestAdapter" Version="3.12.0" />
26+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
27+
</ItemGroup>-->
2228

2329
<ItemGroup>
2430
<ProjectReference Include="..\OData2Poco.CommandLine\OData2Poco.CommandLine.csproj" />
@@ -37,4 +43,8 @@
3743
</None>
3844
</ItemGroup>
3945

46+
<PropertyGroup Condition=" '$(TargetFramework)' == 'net452'">
47+
<DefineConstants>NET45;NETFULL</DefineConstants>
48+
</PropertyGroup>
49+
4050
</Project>

OData2Poco.CommandLine.Test/ProgramTests.cs

Lines changed: 63 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Linq;
45
using Medallion.Shell;
56
using NUnit.Framework;
7+
using OData2Poco.Extension;
68

79
namespace OData2Poco.CommandLine.Test
810
{
11+
public enum ExitCodes
12+
{
13+
Success = 0,
14+
ArgumentsInvalid = -1,
15+
HandledException = -2,
16+
UnhandledException = -99,
17+
}
18+
919
/*
1020
* Note for text contain check for properties of class
1121
* all properties are declared with one and only one space between words
@@ -14,10 +24,31 @@ namespace OData2Poco.CommandLine.Test
1424
[TestFixture]
1525
public class ProgramTests
1626
{
27+
private static string WorkingDirectory = ".";
1728
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
1833
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+
});
2152

2253
/// <summary>
2354
/// exitcode = tuble.item1 , output= tuble.item2
@@ -29,10 +60,22 @@ public class ProgramTests
2960
/// </remarks>
3061
private Func<string, Tuple<int, string>> RunCommand = (s =>
3162
{
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+
});
3476

3577
var outText = command.Result.StandardOutput;
78+
//Console.WriteLine(outText);
3679
var errText = command.Result.StandardError;
3780
var exitCode = command.Result.ExitCode;
3881
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)
63106
var tuble = RunCommand(a);
64107
var output = tuble.Item2;
65108
Assert.AreEqual(0, tuble.Item1);
66-
// Console.WriteLine(tuble.Item2);
67-
109+
// Console.WriteLine(tuble.Item2);
110+
68111
Assert.IsTrue(output.Contains("public class Product"));
69112
Assert.IsTrue(output.Contains("[Table(\"Products\")]")); //-t
70113
Assert.IsTrue(output.Contains("System.ComponentModel.DataAnnotations.Schema")); //-t
@@ -79,7 +122,7 @@ public void PocoSettingTest(string url, string version, int n)
79122
[Test]
80123
public void PocoWithInheritanceTest()
81124
{
82-
var url = "http://services.odata.org/V4/TripPinServiceRW/" ;
125+
var url = "http://services.odata.org/V4/TripPinServiceRW/";
83126
var a = $"-r {url} -v";
84127

85128
var tuble = RunCommand(a);
@@ -148,12 +191,12 @@ public void NullableDatatypeTest(string url, string version, int n)
148191
var tuble = RunCommand(a);
149192
var output = tuble.Item2;
150193
Assert.AreEqual(0, tuble.Item1);
151-
// Console.WriteLine(tuble.Item2);
194+
// Console.WriteLine(tuble.Item2);
152195

153196
Assert.IsTrue(output.Contains("public class Product"));
154197
Assert.IsTrue(output.Contains("virtual public Supplier Supplier {get;set;}")); //-n
155198
Assert.IsTrue(output.Contains("int?")); //-b
156-
199+
157200
}
158201

159202
[Test]
@@ -181,13 +224,13 @@ public void PocoSettingWithJsonAttributeAndCamelCaseTest(string url, string vers
181224
var tuble = RunCommand(a);
182225
var output = tuble.Item2;
183226
//Assert.AreEqual(0, tuble.Item1);
184-
// Console.WriteLine(tuble.Item2);
227+
// Console.WriteLine(tuble.Item2);
185228
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");
187230
Assert.IsTrue(output.Contains("categoryName"));
188231
Assert.IsTrue(output.Contains("[JsonProperty(PropertyName = \"CategoryID\")]"));
189232
Assert.IsTrue(output.Contains("category"));
190-
233+
191234

192235
}
193236

@@ -207,8 +250,8 @@ public void PocoSettingWithJsonAttributePasCaseTest(string url, string version,
207250
Assert.IsTrue(output.Contains("CategoryName"));
208251

209252
}
210-
211-
253+
254+
212255
[Test]
213256
[TestCaseSource(typeof(TestSample), "UrlCases")]
214257
public void PocoSettingEagerTest(string url, string version, int n)
@@ -217,23 +260,23 @@ public void PocoSettingEagerTest(string url, string version, int n)
217260
var tuble = RunCommand(a);
218261
var output = tuble.Item2;
219262
Assert.AreEqual(0, tuble.Item1);
220-
// Console.WriteLine(tuble.Item2);
221-
263+
// Console.WriteLine(tuble.Item2);
264+
222265
Assert.IsTrue(output.Contains("public class Product")); //-v
223266
Assert.IsTrue(output.Contains("public Supplier Supplier {get;set;}")); //-e
224-
267+
225268
}
226269

227270
[Test]
228271
[TestCaseSource(typeof(TestSample), "UrlCases")]
229272
public void PocoSettingInheritTest(string url, string version, int n)
230273
{
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");
232275
var tuble = RunCommand(a);
233276
var output = tuble.Item2;
234277
Assert.AreEqual(0, tuble.Item1);
235278
// Console.WriteLine(tuble.Item2);
236-
279+
237280
Assert.IsTrue(output.Contains("public class Product : MyBaseClass,MyInterface")); //-i, -v
238281

239282
}
@@ -259,7 +302,7 @@ public void FileDefaultSettingTest(string url, string version, int n)
259302
var a = string.Format("-r {0} -v ", url);
260303
var tuble = RunCommand(a);
261304
var output = tuble.Item2;
262-
305+
263306
Assert.AreEqual(0, tuble.Item1);
264307
//Console.WriteLine(tuble.Item2);
265308
Assert.IsTrue(output.Contains("public class Product"));

OData2Poco.CommandLine.Test/Properties/AssemblyInfo.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Reflection;
1+
#if x
2+
using System.Reflection;
23
using System.Runtime.InteropServices;
34

45
// General Information about an assembly is controlled through the following
@@ -33,3 +34,5 @@
3334
// [assembly: AssemblyVersion("1.0.*")]
3435
[assembly: AssemblyVersion("1.0.0.0")]
3536
[assembly: AssemblyFileVersion("1.0.0.0")]
37+
38+
#endif

OData2Poco.CommandLine/Coloring/ConColor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public void Confirm(string format, params object[] arg)
7373
{
7474
WriteLine(ConsoleColor.White,ConsoleColor.Blue, format, arg);
7575
}
76+
public void Normal(string format, params object[] arg)
77+
{
78+
79+
WriteLine(ConsoleColor.Gray, ConsoleColor.Black, format, arg);
80+
}
7681
}
7782
}
7883

OData2Poco.CommandLine/Command.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,31 @@ public async Task Execute()
5151

5252
//show result
5353
await GenerateCodeCommandAsync();
54+
ServiceInfo();
55+
_logger.Confirm("CSharp code is generated Successfully.");
5456
SaveMetaDataCommand();
5557
ShowHeaderCommand();
5658
ListPocoCommand();
5759
VerboseCommand();
58-
59-
}
6060

61+
}
62+
public void ServiceInfo()
63+
{
64+
_logger.Normal($"{new string('-', 15)}Service Information {new string('-', 15)}");
65+
_logger.Info($"OData Service Url: {ArgOptions.Url} ");
66+
_logger.Info($"OData Service Version: {O2PGen.MetaDataVersion} ");
67+
_logger.Info($"Number of Entities: {O2PGen.ClassList.Count}");
68+
_logger.Normal(new string('-', 50));
69+
_logger.Sucess("Sucess creation of the Poco Model");
70+
}
6171

6272
public void ShowOptions()
73+
{
74+
CommandLineUtility.ShowOptions(ArgOptions);
75+
}
76+
77+
//obsolete
78+
public void ShowOptions0()
6379
{
6480
if (!ArgOptions.Verbose) return;
6581
Console.WriteLine("************* CommandLine options***********");
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using CommandLine;
5+
6+
namespace OData2Poco.CommandLine
7+
{
8+
internal class CommandLineUtility
9+
{
10+
public static void ShowOptions(Options option)
11+
{
12+
//format option as: -n Navigation= True
13+
Console.WriteLine("************* CommandLine options***********");
14+
var list = GetOptions( option);
15+
list.ForEach(Console.WriteLine);
16+
Console.WriteLine("********************************************");
17+
}
18+
19+
public static List<string> GetOptions(Options option)
20+
{
21+
var list = new List<string>();
22+
var t = option.GetType();
23+
var props = t.GetProperties()
24+
.Where(p => p.GetValue(option) != null)
25+
.Select(p => new { p, attrs = p.GetCustomAttributes(typeof(OptionAttribute), false) });
26+
27+
foreach (var p1 in props)
28+
{
29+
if (p1.p.Name.Contains("Example")) continue;
30+
var val = p1.p.GetValue(option);
31+
32+
switch (val)
33+
{
34+
case string[] s:
35+
{
36+
val = string.Join(",", s);
37+
break;
38+
}
39+
case bool b:
40+
if (!b) continue;
41+
break;
42+
43+
}
44+
45+
var att = (OptionAttribute)p1.attrs?.FirstOrDefault();
46+
if (att == null) continue;
47+
var shortName = att.ShortName == null ? $"--{att.LongName}" : $"-{att.ShortName}";
48+
var text = $"{shortName} {p1.p.Name}= {val} ";
49+
list.Add(text);
50+
}
51+
return list;
52+
}
53+
54+
}
55+
}

0 commit comments

Comments
 (0)