Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 9648c42

Browse files
authored
Merge pull request #542 from ServiceStack/netcore
Add more tests for .NET Core
2 parents 2ceb9eb + 35470a9 commit 9648c42

22 files changed

+191
-64
lines changed

build/build-core.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@ echo replace AssemblyFileVersion
2323
find ./src -type f -name "AssemblyInfo.cs" -exec sed -i "s/AssemblyFileVersion(\"[^\"]\+\")/AssemblyFileVersion(\"${Version}\")/g" {} +
2424

2525
echo replace project.json
26-
find ./src -type f -name "project.json" -exec sed -i "s/\"version\": \"[^\"]\+\"/\"version\": \"${Version}\"/g" {} +
26+
sed -i "s/\"version\": \"[^\"]\+\"/\"version\": \"${Version}\"/g" ./src/ServiceStack.OrmLite/project.json
27+
sed -i "s/\"version\": \"[^\"]\+\"/\"version\": \"${Version}\"/g" ./src/ServiceStack.OrmLite.PostgreSQL/project.json
28+
sed -i "s/\"version\": \"[^\"]\+\"/\"version\": \"${Version}\"/g" ./src/ServiceStack.OrmLite.SqlServer/project.json
29+
sed -i "s/\"version\": \"[^\"]\+\"/\"version\": \"${Version}\"/g" ./src/ServiceStack.OrmLite.Sqlite/project.json
30+
sed -i "s/\"version\": \"[^\"]\+\"/\"version\": \"${Version}\"/g" ./src/ServiceStack.Text/project.json
31+
sed -i "s/\"version\": \"[^\"]\+\"/\"version\": \"${Version}\"/g" ./src/ServiceStack.Client/project.json
32+
sed -i "s/\"version\": \"[^\"]\+\"/\"version\": \"${Version}\"/g" ./src/ServiceStack.Common/project.json
33+
sed -i "s/\"version\": \"[^\"]\+\"/\"version\": \"${Version}\"/g" ./src/ServiceStack.Interfaces/project.json
34+
2735

2836
echo replace package
2937
find ./NuGet.Core -type f -name "*.nuspec" -exec sed -i "s/<version>[^<]\+/<version>${PackageVersion}/g" {} +

src/ServiceStack.OrmLite.PostgreSQL.Tests/Expressions/AuthorUseCase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ public void AuthorUsesCases()
107107
//in the string.
108108
//An underscore ("_") in the LIKE pattern matches any single character in the string.
109109
//Any other character matches itself or its lower/upper case equivalent (i.e. case-insensitive matching).
110+
//case-sensitivity matching depends on PostgreSQL underlying OS.
111+
#if NETCORE
112+
expected = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux)? 1 : 3;
113+
#else
110114
expected = 3;
115+
#endif
116+
111117
ev.Where().Where(rn => rn.Name.EndsWith("garzon"));
112118
result = db.Select(ev);
113119
Assert.AreEqual(expected, result.Count);

src/ServiceStack.OrmLite.PostgreSQL.Tests/ForeignKeyAttributeTests.cs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,35 @@ public ForeignKeyAttributeTests() : base(Dialect.PostgreSql) { }
1212
[TestFixtureSetUp]
1313
public void Setup()
1414
{
15+
DropTables();
16+
1517
using (var dbConn = OpenDbConnection())
1618
{
1719
dbConn.CreateTable<ReferencedType>(true);
1820
}
1921
}
2022

23+
[TestFixtureTearDown]
24+
public void TearDown()
25+
{
26+
DropTables();
27+
}
28+
29+
private void DropTables()
30+
{
31+
using (var dbConn = OpenDbConnection())
32+
{
33+
dbConn.DropTable<TypeWithOnDeleteAndUpdateCascade>();
34+
dbConn.DropTable<TypeWithOnDeleteSetNull>();
35+
dbConn.DropTable<TypeWithOnDeleteSetDefault>();
36+
dbConn.DropTable<TypeWithOnDeleteRestrict>();
37+
dbConn.DropTable<TypeWithOnDeleteNoAction>();
38+
dbConn.DropTable<TypeWithOnDeleteCascade>();
39+
dbConn.DropTable<TypeWithSimpleForeignKey>();
40+
dbConn.DropTable<ReferencedType>();
41+
}
42+
}
43+
2144
[Test]
2245
public void CanCreateSimpleForeignKey()
2346
{
@@ -100,22 +123,6 @@ public void CanCreateForeignWithOnDeleteSetNull()
100123
dbConn.CreateTable<TypeWithOnDeleteSetNull>(true);
101124
}
102125
}
103-
104-
[TestFixtureTearDown]
105-
public void TearDwon()
106-
{
107-
using (var dbConn = OpenDbConnection())
108-
{
109-
dbConn.DropTable<TypeWithOnDeleteAndUpdateCascade>();
110-
dbConn.DropTable<TypeWithOnDeleteSetNull>();
111-
dbConn.DropTable<TypeWithOnDeleteSetDefault>();
112-
dbConn.DropTable<TypeWithOnDeleteRestrict>();
113-
dbConn.DropTable<TypeWithOnDeleteNoAction>();
114-
dbConn.DropTable<TypeWithOnDeleteCascade>();
115-
dbConn.DropTable<TypeWithSimpleForeignKey>();
116-
dbConn.DropTable<ReferencedType>();
117-
}
118-
}
119126
}
120127

121128
public class ReferencedType
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using NUnitLite;
2+
using NUnit.Common;
3+
using System.Reflection;
4+
using ServiceStack;
5+
using ServiceStack.Text;
6+
using System;
7+
using System.Globalization;
8+
using System.Threading;
9+
using ServiceStack.OrmLite.Tests;
10+
11+
namespace ServiceStack.OrmLite.PostgreSQL.Tests
12+
{
13+
public class NetCoreTestsRunner
14+
{
15+
/// <summary>
16+
/// The main program executes the tests. Output may be routed to
17+
/// various locations, depending on the arguments passed.
18+
/// </summary>
19+
/// <remarks>Run with --help for a full list of arguments supported</remarks>
20+
/// <param name="args"></param>
21+
public static int Main(string[] args)
22+
{
23+
var licenseKey = Environment.GetEnvironmentVariable("SERVICESTACK_LICENSE");
24+
if (licenseKey.IsNullOrEmpty())
25+
throw new ArgumentNullException("SERVICESTACK_LICENSE", "Add Environment variable for SERVICESTACK_LICENSE");
26+
27+
Licensing.RegisterLicense(licenseKey);
28+
//"ActivatedLicenseFeatures: ".Print(LicenseUtils.ActivatedLicenseFeatures());
29+
30+
var postgreSqlDb = Environment.GetEnvironmentVariable("POSTGRESQL_DB");
31+
32+
if (!String.IsNullOrEmpty(postgreSqlDb))
33+
{
34+
Config.PostgreSqlDb = postgreSqlDb;
35+
}
36+
37+
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
38+
JsConfig.InitStatics();
39+
40+
//JsonServiceClient client = new JsonServiceClient();
41+
var writer = new ExtendedTextWrapper(Console.Out);
42+
return new AutoRun(((IReflectableType)typeof(NetCoreTestsRunner)).GetTypeInfo().Assembly).Execute(args, writer, Console.In);
43+
}
44+
}
45+
}

src/ServiceStack.OrmLite.PostgreSQL.Tests/OrmLiteExecuteProcedureTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using ServiceStack.DataAnnotations;
33
using ServiceStack.OrmLite.Tests;
44
using ServiceStack.Text;
5+
using IgnoreAttribute = NUnit.Framework.IgnoreAttribute;
56

67
namespace ServiceStack.OrmLite.PostgreSQL.Tests
78
{
@@ -50,6 +51,7 @@ public class ServiceStackFunction
5051
}
5152

5253
[Test]
54+
[Ignore("This test fails both on .NET and .NET Core")]
5355
public void Can_execute_stored_procedure_with_array_arguments()
5456
{
5557
using (var db = OpenDbConnection())

src/ServiceStack.OrmLite.PostgreSQL.Tests/OrmLiteGetScalarTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public void Can_get_scalar_value(){
154154
Assert.That(expectedString, Is.EqualTo(r9));
155155

156156
r9 = db.Scalar<Author,string>(e=> Sql.Max(e.Name), e=>e.City=="SinCity");
157-
Assert.IsNullOrEmpty(r9);
157+
Assert.That(r9, Is.Null.Or.Empty);
158158

159159
//var expectedBool=authors.Min(e=>e.Active);
160160
//var r10 = db.GetScalar<Author,bool>(e=> Sql.Min(e.Active));

src/ServiceStack.OrmLite.PostgreSQL.Tests/OrmLiteInsertTests.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,13 @@ public PostgreSQLUpdateTests()
211211
public void Can_insert_datetimeoffsets_regardless_of_current_culture()
212212
{
213213
// datetimeoffset's default .ToString depends on culture, ensure we use one with MDY
214+
#if NETCORE
215+
var previousCulture = CultureInfo.CurrentCulture;
216+
CultureInfo.CurrentCulture = new CultureInfo("en-US");
217+
#else
214218
var previousCulture = System.Threading.Thread.CurrentThread.CurrentCulture;
215-
System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
219+
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
220+
#endif
216221
try
217222
{
218223
using (var db = OpenDbConnection())
@@ -239,7 +244,11 @@ public void Can_insert_datetimeoffsets_regardless_of_current_culture()
239244
}
240245
finally
241246
{
247+
#if NETCORE
248+
CultureInfo.CurrentCulture = previousCulture;
249+
#else
242250
System.Threading.Thread.CurrentThread.CurrentCulture = previousCulture;
251+
#endif
243252
}
244253
}
245254

src/ServiceStack.OrmLite.PostgreSQL.Tests/ServiceStack.OrmLite.PostgreSQL.Tests.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@
6565
<Reference Include="System.Data.DataSetExtensions" />
6666
<Reference Include="System.Data" />
6767
<Reference Include="System.Xml" />
68-
<Reference Include="nunit.framework">
69-
<HintPath>..\..\lib\tests\nunit.framework.dll</HintPath>
68+
<Reference Include="nunit.framework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
69+
<HintPath>..\packages\NUnit.3.5.0\lib\net45\nunit.framework.dll</HintPath>
70+
<Private>True</Private>
7071
</Reference>
7172
<Reference Include="ServiceStack.Text">
7273
<HintPath>..\..\lib\ServiceStack.Text.dll</HintPath>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"frameworks": {
3+
"net45": {}
4+
},
5+
"runtimes": {
6+
"win": {},
7+
"win-x86": {}
8+
}
9+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Npgsql" version="3.1.8" targetFramework="net45" />
4+
<package id="NUnit" version="3.5.0" targetFramework="net45" />
45
</packages>

0 commit comments

Comments
 (0)