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

Commit 0b927a5

Browse files
committed
First iteration of making ServiceStack.Redis.Tests compilable on .NET Core
1 parent 2f9a6e2 commit 0b927a5

File tree

11 files changed

+143
-25
lines changed

11 files changed

+143
-25
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
10+
namespace NUnitLite.Tests
11+
{
12+
public class Program
13+
{
14+
/// <summary>
15+
/// The main program executes the tests. Output may be routed to
16+
/// various locations, depending on the arguments passed.
17+
/// </summary>
18+
/// <remarks>Run with --help for a full list of arguments supported</remarks>
19+
/// <param name="args"></param>
20+
public static int Main(string[] args)
21+
{
22+
var licenseKey = Environment.GetEnvironmentVariable("SERVICESTACK_LICENSE");
23+
if (licenseKey.IsNullOrEmpty())
24+
throw new ArgumentNullException("SERVICESTACK_LICENSE", "Add Environment variable for SERVICESTACK_LICENSE");
25+
26+
Licensing.RegisterLicense(licenseKey);
27+
//"ActivatedLicenseFeatures: ".Print(LicenseUtils.ActivatedLicenseFeatures());
28+
29+
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
30+
JsConfig.InitStatics();
31+
//JsonServiceClient client = new JsonServiceClient();
32+
var writer = new ExtendedTextWrapper(Console.Out);
33+
return new AutoRun(((IReflectableType)typeof(Program)).GetTypeInfo().Assembly).Execute(args, writer, Console.In);
34+
}
35+
}
36+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"configurations": {
3+
"Debug": {
4+
"buildOptions": {
5+
"define": ["NETCORE_SUPPORT", "NETCORE", "DEBUG", "TRACE"]
6+
}
7+
},
8+
"Release": {
9+
"buildOptions": {
10+
"define": ["NETCORE_SUPPORT", "NETCORE", "TRACE"],
11+
"optimize": true
12+
}
13+
}
14+
},
15+
"buildOptions": {
16+
"debugType": "portable",
17+
"emitEntryPoint": true
18+
},
19+
"compile": ["../../ServiceStack.Redis.Tests/**/*.cs"],
20+
"dependencies": {
21+
"Microsoft.NETCore.App": {
22+
"type": "platform",
23+
"version": "1.0.0"
24+
},
25+
"NUnitLite" : "3.2.1",
26+
"ServiceStack.Redis" : "4.0.*",
27+
"ServiceStack.Interfaces" : "4.0.*",
28+
"ServiceStack.Text" : "4.0.*",
29+
"ServiceStack.Common" : "4.0.*"
30+
},
31+
"frameworks": {
32+
"netcoreapp1.0": {
33+
"imports": "dnxcore50",
34+
"dependencies" : {
35+
"System.Drawing.Primitives" : "4.0.0",
36+
"System.Collections.Specialized": "4.0.1",
37+
"System.Runtime.Serialization.Json": "4.0.2",
38+
"System.Runtime.Serialization.Primitives": "4.1.1",
39+
"System.Collections.NonGeneric": "4.0.1",
40+
"System.Diagnostics.Tracing": "4.1.0",
41+
"System.Diagnostics.Debug": "4.0.11",
42+
"System.Diagnostics.TextWriterTraceListener" : "4.0.0",
43+
"System.Reflection": "4.1.0",
44+
"System.Reflection.Extensions" : "4.0.1",
45+
}
46+
}
47+
}
48+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"projects": [
3+
"../../src/ServiceStack.Redis.NetCore",
4+
"ServiceStack.Common.Tests"
5+
]
6+
}

tests/ServiceStack.Redis.Tests/Issues/TransactionIssueTests.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Threading;
44
using System.Threading.Tasks;
5-
using System.Timers;
65
using NUnit.Framework;
76
using ServiceStack.Text;
87

@@ -108,17 +107,15 @@ private void CheckThisConnection()
108107
}
109108
}
110109

111-
private void CheckConnection(object sender, ElapsedEventArgs e)
110+
private void CheckConnection()
112111
{
113112
Task.Factory.StartNew(CheckThisConnection);
114113
}
115114

116115
[Explicit, Test]
117116
public void Can_queue_large_transaction()
118117
{
119-
var q = new System.Timers.Timer { Interval = 2 };
120-
q.Elapsed += CheckConnection;
121-
q.Enabled = true;
118+
var q = new System.Threading.Timer(CheckConnection, null, 30000, 2);
122119

123120
Thread.Sleep(30000);
124121
}

tests/ServiceStack.Redis.Tests/LicenseUsageTests.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Copyright (c) Service Stack LLC. All Rights Reserved.
22
// License: https://raw.github.com/ServiceStack/ServiceStack/master/license.txt
33

4-
4+
#if !NETCORE
55
using System.Data;
6+
#endif
67
using NUnit.Framework;
78
using ServiceStack.Configuration;
89
using ServiceStack.Text;
@@ -22,7 +23,11 @@ public void SetUp()
2223
[TearDown]
2324
public void TearDown()
2425
{
26+
#if NETCORE
27+
Environment.GetEnvironmentVariable("SERVICESTACK_LICENSE");
28+
#else
2529
Licensing.RegisterLicense(new AppSettings().GetString("servicestack:license"));
30+
#endif
2631
}
2732

2833
[Test]

tests/ServiceStack.Redis.Tests/RedisClientTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ public void Can_GetServerTime()
216216
var now = Redis.GetServerTime();
217217

218218
now.Kind.PrintDump();
219-
now.ToLongDateString().Print();
220-
now.ToLongTimeString().Print();
219+
now.ToString("D").Print();
220+
now.ToString("T").Print();
221221

222222
"UtcNow".Print();
223-
DateTime.UtcNow.ToLongDateString().Print();
224-
DateTime.UtcNow.ToLongTimeString().Print();
223+
DateTime.UtcNow.ToString("D").Print();
224+
DateTime.UtcNow.ToString("T").Print();
225225

226226
Assert.That(now.Date, Is.EqualTo(DateTime.UtcNow.Date));
227227
}

tests/ServiceStack.Redis.Tests/RedisPasswordTests.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,26 @@ public void Can_connect_to_Slaves_and_Masters_with_Password()
2525
}
2626

2727
[Test]
28-
[ExpectedException(typeof(ServiceStack.Redis.RedisResponseException), UserMessage = "Expected an exception after Redis AUTH command; try using a password that doesn't match.")]
2928
public void Passwords_are_not_leaked_in_exception_messages()
30-
{
29+
{
3130
const string password = "yesterdayspassword";
32-
try
33-
{
34-
var factory = new PooledRedisClientManager(password + "@" + TestConfig.SingleHost); // redis will throw when using password and it's not configured
35-
using (var redis = factory.GetClient())
31+
32+
Assert.Throws<ServiceStack.Redis.RedisResponseException>(() => {
33+
try
3634
{
37-
redis.SetEntry("Foo", "Bar");
35+
var factory = new PooledRedisClientManager(password + "@" + TestConfig.SingleHost); // redis will throw when using password and it's not configured
36+
using (var redis = factory.GetClient())
37+
{
38+
redis.SetEntry("Foo", "Bar");
39+
}
3840
}
39-
}
40-
catch (RedisResponseException ex)
41-
{
42-
Assert.That(ex.Message, Is.Not.StringContaining(password));
43-
throw;
44-
}
41+
catch (RedisResponseException ex)
42+
{
43+
Assert.That(ex.Message, Is.Not.StringContaining(password));
44+
throw;
45+
}
46+
},
47+
"Expected an exception after Redis AUTH command; try using a password that doesn't match.");
4548
}
4649
}
4750
}

tests/ServiceStack.Redis.Tests/RetryCommandTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Linq;
33
using System.Net.Sockets;
44
using System.Threading;
5-
using System.Timers;
65
using NUnit.Framework;
76
using ServiceStack.Logging;
87
using ServiceStack.Text;

tests/ServiceStack.Redis.Tests/SslTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ public void Can_connect_to_NetworkStream()
9393

9494
if (!socket.Connected)
9595
{
96+
#if NETCORE
97+
socket.Dispose();
98+
#else
9699
socket.Close();
100+
#endif
97101
throw new Exception("Could not connect");
98102
}
99103

@@ -115,7 +119,11 @@ public void Can_connect_to_Buffered_SslStream()
115119

116120
if (!socket.Connected)
117121
{
122+
#if NETCORE
123+
socket.Dispose();
124+
#else
118125
socket.Close();
126+
#endif
119127
throw new Exception("Could not connect");
120128
}
121129

@@ -133,8 +141,13 @@ public void Can_connect_to_Buffered_SslStream()
133141
}
134142
else
135143
{
144+
#if NETCORE
145+
var ctor = typeof(SslStream).GetTypeInfo().GetConstructors()
146+
.First(x => x.GetParameters().Length == 5);
147+
#else
136148
var ctor = typeof(SslStream).GetConstructors()
137149
.First(x => x.GetParameters().Length == 5);
150+
#endif
138151

139152
var policyType = AssemblyUtils.FindType("System.Net.Security.EncryptionPolicy");
140153
var policyValue = Enum.Parse(policyType, "RequireEncryption");
@@ -154,7 +167,11 @@ public void Can_connect_to_Buffered_SslStream()
154167
// encryptionPolicy: EncryptionPolicy.RequireEncryption);
155168
}
156169

170+
#if NETCORE
171+
sslStream.AuthenticateAsClientAsync(Host).Wait();
172+
#else
157173
sslStream.AuthenticateAsClient(Host);
174+
#endif
158175

159176
if (!sslStream.IsEncrypted)
160177
throw new Exception("Could not establish an encrypted connection to " + Host);

tests/ServiceStack.Redis.Tests/Support/TcpClientWithTimeout.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ void Main()
9292
stream.Read(readbuf, 0, 10); // read
9393

9494
// Disconnect nicely
95+
#if NETCORE
96+
stream.Dispose();
97+
#else
9598
stream.Close(); // workaround for a .net bug: http://support.microsoft.com/kb/821625
99+
#endif
96100
connection.Close();
97101
}
98102
}

0 commit comments

Comments
 (0)