Skip to content

Commit 1953152

Browse files
authored
Merge pull request #326 from bgrainger/dotnet-xunit
Use dotnet xunit for tests. Fixes #230
2 parents 85cd38b + 421622f commit 1953152

14 files changed

+98
-95
lines changed

.ci/test.ps1

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,37 @@ if ($LASTEXITCODE -ne 0){
1010
exit $LASTEXITCODE;
1111
}
1212

13-
echo "Executing connection string tests"
14-
dotnet test tests\MySqlConnector.Tests\MySqlConnector.Tests.csproj -c Release
13+
echo "Executing unit tests"
14+
pushd tests\MySqlConnector.Tests
15+
dotnet xunit -c Release
1516
if ($LASTEXITCODE -ne 0){
1617
exit $LASTEXITCODE;
1718
}
19+
popd
20+
21+
pushd .\tests\SideBySide
1822

1923
echo "Executing tests with No Compression, No SSL"
20-
Copy-Item -Force .ci\config\config.json tests\SideBySide\config.json
21-
dotnet test tests\SideBySide\SideBySide.csproj -c Release
24+
Copy-Item -Force ..\..\.ci\config\config.json config.json
25+
dotnet xunit -c Release
2226
if ($LASTEXITCODE -ne 0){
2327
exit $LASTEXITCODE;
2428
}
2529
echo "Executing Debug Only tests"
26-
dotnet test tests\SideBySide\SideBySide.csproj -c Debug --filter "FullyQualifiedName~SideBySide.DebugOnlyTests"
30+
dotnet xunit -c Debug -class SideBySide.DebugOnlyTests
2731
if ($LASTEXITCODE -ne 0){
2832
exit $LASTEXITCODE;
2933
}
3034

3135
echo "Executing tests with Compression, No SSL"
32-
Copy-Item -Force .ci\config\config.compression.json tests\SideBySide\config.json
33-
dotnet test tests\SideBySide\SideBySide.csproj -c Release
36+
Copy-Item -Force ..\..\.ci\config\config.compression.json config.json
37+
dotnet xunit -c Release
3438
if ($LASTEXITCODE -ne 0){
3539
exit $LASTEXITCODE;
3640
}
3741

42+
popd
43+
3844
echo "Executing baseline connection string tests"
3945
dotnet restore tests\MySqlConnector.Tests\MySqlConnector.Tests.csproj /p:Configuration=Baseline
4046
dotnet test tests\MySqlConnector.Tests\MySqlConnector.Tests.csproj -c Baseline

.travis.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,18 @@ before_install:
2525

2626
script:
2727
- dotnet restore
28-
- dotnet test tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj -c Release -f netcoreapp2.0
29-
- dotnet build tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
30-
- echo 'Executing netcoreapp1.1.2 tests with No Compression, No SSL' && ./.ci/use-config.sh config.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.2
31-
- echo 'Executing netcoreapp2.0 tests with No Compression, No SSL' && ./.ci/use-config.sh config.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
32-
- echo 'Executing netcoreapp2.0 Debug Only tests' && time dotnet test tests/SideBySide/SideBySide.csproj -c Debug -f netcoreapp2.0 --filter "FullyQualifiedName~SideBySide.DebugOnlyTests"
33-
- echo 'Executing netcoreapp2.0 tests with Compression, No SSL' && ./.ci/use-config.sh config.compression.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
34-
- echo 'Executing netcoreapp2.0 tests with No Compression, SSL' && ./.ci/use-config.sh config.ssl.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
35-
- echo 'Executing netcoreapp2.0 tests with Compression, SSL' && ./.ci/use-config.sh config.compression+ssl.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
36-
- echo 'Executing netcoreapp2.0 tests with Unix Domain Socket, No Compression, No SSL' && ./.ci/use-config.sh config.uds.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
37-
- echo 'Executing netcoreapp2.0 tests with Buffering, No Compression, No SSL' && ./.ci/use-config.sh config.buffer.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
28+
- pushd tests/MySqlConnector.Tests && dotnet xunit -c Release && popd
29+
- pushd tests/SideBySide
30+
- dotnet build SideBySide.csproj -c Release -f netcoreapp2.0
31+
- echo 'Executing netcoreapp1.1.2 tests with No Compression, No SSL' && ../../.ci/use-config.sh config.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet xunit -c Release -f netcoreapp1.1.2
32+
- echo 'Executing netcoreapp2.0 tests with No Compression, No SSL' && ../../.ci/use-config.sh config.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet xunit -c Release -f netcoreapp2.0
33+
- echo 'Executing netcoreapp2.0 Debug Only tests' && time dotnet xunit -c Debug -f netcoreapp2.0 -class SideBySide.DebugOnlyTests
34+
- echo 'Executing netcoreapp2.0 tests with Compression, No SSL' && ../../.ci/use-config.sh config.compression.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet xunit -c Release -f netcoreapp2.0
35+
- echo 'Executing netcoreapp2.0 tests with No Compression, SSL' && ../../.ci/use-config.sh config.ssl.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet xunit -c Release -f netcoreapp2.0
36+
- echo 'Executing netcoreapp2.0 tests with Compression, SSL' && ../../.ci/use-config.sh config.compression+ssl.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet xunit -c Release -f netcoreapp2.0
37+
- echo 'Executing netcoreapp2.0 tests with Unix Domain Socket, No Compression, No SSL' && ../../.ci/use-config.sh config.uds.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet xunit -c Release -f netcoreapp2.0
38+
- echo 'Executing netcoreapp2.0 tests with Buffering, No Compression, No SSL' && ../../.ci/use-config.sh config.buffer.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet xunit -c Release -f netcoreapp2.0
39+
- popd
3840

3941
after_script:
4042
- chmod +x .ci/build-docs.sh && ./.ci/build-docs.sh

tests/MySqlConnector.Tests/MySqlConnectionStringBuilderTests.cs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,43 @@ public void Defaults()
1111
{
1212
var csb = new MySqlConnectionStringBuilder();
1313
#if !BASELINE
14-
Assert.Equal(false, csb.AllowPublicKeyRetrieval);
14+
Assert.False(csb.AllowPublicKeyRetrieval);
1515
#endif
16-
Assert.Equal(false, csb.AllowUserVariables);
17-
Assert.Equal(true, csb.AutoEnlist);
18-
Assert.Equal(null, csb.CertificateFile);
19-
Assert.Equal(null, csb.CertificatePassword);
16+
Assert.False(csb.AllowUserVariables);
17+
Assert.True(csb.AutoEnlist);
18+
Assert.Null(csb.CertificateFile);
19+
Assert.Null(csb.CertificatePassword);
2020
Assert.Equal("", csb.CharacterSet);
2121
#if BASELINE
22-
Assert.Equal(false, csb.ConnectionReset);
22+
Assert.False(csb.ConnectionReset);
2323
#else
2424
Assert.Equal(0u, csb.ConnectionLifeTime);
25-
Assert.Equal(true, csb.ConnectionReset);
25+
Assert.True(csb.ConnectionReset);
2626
#endif
2727
Assert.Equal(15u, csb.ConnectionTimeout);
28-
Assert.Equal(false, csb.ConvertZeroDateTime);
28+
Assert.False(csb.ConvertZeroDateTime);
2929
Assert.Equal("", csb.Database);
3030
#if !BASELINE
31-
Assert.Equal(false, csb.BufferResultSets);
31+
Assert.False(csb.BufferResultSets);
3232
Assert.Equal(180u, csb.ConnectionIdleTimeout);
33-
Assert.Equal(false, csb.ForceSynchronous);
34-
Assert.Equal(null, csb.CACertificateFile);
33+
Assert.False(csb.ForceSynchronous);
34+
Assert.Null(csb.CACertificateFile);
3535
#endif
3636
Assert.Equal(0u, csb.Keepalive);
3737
Assert.Equal(100u, csb.MaximumPoolSize);
3838
Assert.Equal(0u, csb.MinimumPoolSize);
3939
Assert.Equal("", csb.Password);
40-
Assert.Equal(false, csb.OldGuids);
41-
Assert.Equal(false, csb.PersistSecurityInfo);
42-
Assert.Equal(true, csb.Pooling);
40+
Assert.False(csb.OldGuids);
41+
Assert.False(csb.PersistSecurityInfo);
42+
Assert.True(csb.Pooling);
4343
Assert.Equal(3306u, csb.Port);
4444
Assert.Equal("", csb.Server);
4545
#if !BASELINE
46-
Assert.Equal(null, csb.ServerRsaPublicKeyFile);
46+
Assert.Null(csb.ServerRsaPublicKeyFile);
4747
#endif
4848
Assert.Equal(MySqlSslMode.Preferred, csb.SslMode);
49-
Assert.Equal(true, csb.TreatTinyAsBoolean);
50-
Assert.Equal(false, csb.UseCompression);
49+
Assert.True(csb.TreatTinyAsBoolean);
50+
Assert.False(csb.UseCompression);
5151
Assert.Equal("", csb.UserID);
5252
#if BASELINE
5353
Assert.False(csb.UseAffectedRows);
@@ -94,37 +94,37 @@ public void ParseConnectionString()
9494
"Uid=username;" +
9595
"useaffectedrows=false"
9696
};
97-
Assert.Equal(true, csb.AllowUserVariables);
98-
Assert.Equal(false, csb.AutoEnlist);
97+
Assert.True(csb.AllowUserVariables);
98+
Assert.False(csb.AutoEnlist);
9999
Assert.Equal("file.pfx", csb.CertificateFile);
100100
Assert.Equal("Pass1234", csb.CertificatePassword);
101101
Assert.Equal("latin1", csb.CharacterSet);
102102
Assert.Equal(15u, csb.ConnectionLifeTime);
103-
Assert.Equal(false, csb.ConnectionReset);
103+
Assert.False(csb.ConnectionReset);
104104
Assert.Equal(30u, csb.ConnectionTimeout);
105-
Assert.Equal(true, csb.ConvertZeroDateTime);
105+
Assert.True(csb.ConvertZeroDateTime);
106106
Assert.Equal("schema_name", csb.Database);
107107
#if !BASELINE
108-
Assert.Equal(true, csb.BufferResultSets);
108+
Assert.True(csb.BufferResultSets);
109109
Assert.Equal(30u, csb.ConnectionIdleTimeout);
110-
Assert.Equal(true, csb.ForceSynchronous);
110+
Assert.True(csb.ForceSynchronous);
111111
Assert.Equal("ca.pem", csb.CACertificateFile);
112-
Assert.Equal(true, csb.AllowPublicKeyRetrieval);
112+
Assert.True(csb.AllowPublicKeyRetrieval);
113113
Assert.Equal("rsa.pem", csb.ServerRsaPublicKeyFile);
114114
#endif
115115
Assert.Equal(90u, csb.Keepalive);
116116
Assert.Equal(15u, csb.MaximumPoolSize);
117117
Assert.Equal(5u, csb.MinimumPoolSize);
118118
Assert.Equal("Pass1234", csb.Password);
119-
Assert.Equal(true, csb.OldGuids);
120-
Assert.Equal(true, csb.PersistSecurityInfo);
121-
Assert.Equal(false, csb.Pooling);
119+
Assert.True(csb.OldGuids);
120+
Assert.True(csb.PersistSecurityInfo);
121+
Assert.False(csb.Pooling);
122122
Assert.Equal(1234u, csb.Port);
123123
Assert.Equal("db-server", csb.Server);
124-
Assert.Equal(false, csb.TreatTinyAsBoolean);
124+
Assert.False(csb.TreatTinyAsBoolean);
125125
Assert.Equal(MySqlSslMode.VerifyCA, csb.SslMode);
126-
Assert.Equal(false, csb.UseAffectedRows);
127-
Assert.Equal(true, csb.UseCompression);
126+
Assert.False(csb.UseAffectedRows);
127+
Assert.True(csb.UseCompression);
128128
Assert.Equal("username", csb.UserID);
129129
}
130130

tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@
1818
</PropertyGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
22-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-*" />
23-
<PackageReference Include="Microsoft.TestPlatform.TestHost" Version="15.0.0-*" />
24-
<PackageReference Include="xunit" Version="2.2.0" />
25-
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
21+
<PackageReference Include="xunit" Version="2.3.0-beta5-build3769" />
22+
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta5-build3769" />
2623
</ItemGroup>
2724

2825
<ItemGroup Condition=" '$(Configuration)' != 'Baseline' ">

tests/MySqlConnector.Tests/Utf8Tests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public class Utf8Tests
1313
[InlineData("\u07FF", new byte[] { 0xDF, 0xBF })]
1414
[InlineData("\u0800", new byte[] { 0xE0, 0xA0, 0x80 })]
1515
[InlineData("\uFFFF", new byte[] { 0xEF, 0xBF, 0xBF })]
16-
[InlineData("\uFFFF", new byte[] { 0xEF, 0xBF, 0xBF })]
1716
[InlineData("\U00010000", new byte[] { 0xF0, 0x90, 0x80, 0x80 })]
1817
[InlineData("\U0010FFF0\U0010FFF1", new byte[] { 0xF4, 0x8F, 0xBF, 0xB0, 0xF4, 0x8F, 0xBF, 0xB1 })]
1918
public void Encode(string input, byte[] expected)

tests/SideBySide/BulkLoaderAsync.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,19 @@ public async Task BulkLoadLocalCsvFileNotFound()
191191
}
192192
else
193193
{
194-
Assert.IsType(typeof(System.IO.FileNotFoundException), mySqlException.InnerException);
194+
Assert.IsType<System.IO.FileNotFoundException>(mySqlException.InnerException);
195195
break;
196196
}
197197
}
198198
if (mySqlException.InnerException == null)
199199
{
200-
Assert.IsType(typeof(System.IO.FileNotFoundException), mySqlException);
200+
Assert.IsType<System.IO.FileNotFoundException>(mySqlException);
201201
}
202202
}
203203
catch (Exception exception)
204204
{
205205
//We know that the exception is not a MySqlException, just use the assertion to fail the test
206-
Assert.IsType(typeof(MySqlException), exception);
206+
Assert.IsType<MySqlException>(exception);
207207
};
208208
}
209209

tests/SideBySide/BulkLoaderSync.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,19 @@ public void BulkLoadLocalCsvFileNotFound()
193193
}
194194
else
195195
{
196-
Assert.IsType(typeof(System.IO.FileNotFoundException), mySqlException.InnerException);
196+
Assert.IsType<System.IO.FileNotFoundException>(mySqlException.InnerException);
197197
break;
198198
}
199199
}
200200
if (mySqlException.InnerException == null)
201201
{
202-
Assert.IsType(typeof(System.IO.FileNotFoundException), mySqlException);
202+
Assert.IsType<System.IO.FileNotFoundException>(mySqlException);
203203
}
204204
}
205205
catch (Exception exception)
206206
{
207207
//We know that the exception is not a MySqlException, just use the assertion to fail the test
208-
Assert.IsType(typeof(MySqlException), exception);
208+
Assert.IsType<MySqlException>(exception);
209209
};
210210
}
211211

tests/SideBySide/CancelTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Data;
33
using System.Diagnostics;
44
using System.Linq;
@@ -166,7 +166,7 @@ public void DapperQueryMultiple()
166166
using (var gridReader = m_database.Connection.QueryMultiple(@"select 1; " + c_hugeQuery))
167167
{
168168
var first = gridReader.Read<int>().ToList();
169-
Assert.Equal(1, first.Count);
169+
Assert.Single(first);
170170
Assert.Equal(1, first[0]);
171171

172172
// don't read the second result set; disposing the GridReader should Cancel the command

tests/SideBySide/DataTypes.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Data.Common;
33
using System.Globalization;
44
using System.Linq;
@@ -91,7 +91,7 @@ public async Task GetInt64(string column, int[] flags, long[] values)
9191
await DoGetValue(column, (r, n) => r.GetInt64(n), flags, values).ConfigureAwait(false);
9292
}
9393

94-
public async Task DoGetValue<T>(string column, Func<DbDataReader, int, T> getInt, int[] flags, T[] values)
94+
private async Task DoGetValue<T>(string column, Func<DbDataReader, int, T> getInt, int[] flags, T[] values)
9595
{
9696
using (var cmd = m_database.Connection.CreateCommand())
9797
{
@@ -612,8 +612,8 @@ private static byte[] CreateByteArray(int size)
612612
}
613613

614614
[RequiresFeatureTheory(ServerFeatures.Json)]
615-
[InlineData("Value", new[] { null, "NULL", "BOOLEAN", "ARRAY", "ARRAY", "ARRAY", "INTEGER", "INTEGER", "OBJECT", "OBJECT" })]
616-
public void JsonType(string column, string[] expectedTypes)
615+
[InlineData(new object[] { new[] { null, "NULL", "BOOLEAN", "ARRAY", "ARRAY", "ARRAY", "INTEGER", "INTEGER", "OBJECT", "OBJECT" }})]
616+
public void JsonType(string[] expectedTypes)
617617
{
618618
var types = m_database.Connection.Query<string>(@"select JSON_TYPE(value) from datatypes_json_core order by rowid;").ToList();
619619
Assert.Equal(expectedTypes, types);

tests/SideBySide/InsertTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Linq;
33
using MySql.Data.MySqlClient;
44
using Dapper;
@@ -27,7 +27,7 @@ public async Task LastInsertedId()
2727
{
2828
command.Parameters.Add(new MySqlParameter { ParameterName = "@text", Value = "test" });
2929
await command.ExecuteNonQueryAsync();
30-
Assert.Equal(command.LastInsertedId, 1L);
30+
Assert.Equal(1L, command.LastInsertedId);
3131
}
3232
}
3333
finally
@@ -70,7 +70,7 @@ public void LastInsertedIdExplicitStart()
7070
using (var command = new MySqlCommand("insert into insert_ai_2(text) values('test');", m_database.Connection))
7171
{
7272
command.ExecuteNonQuery();
73-
Assert.Equal(command.LastInsertedId, 1234L);
73+
Assert.Equal(1234L, command.LastInsertedId);
7474
}
7575
}
7676
finally
@@ -207,9 +207,9 @@ public void InsertEnumValue()
207207
new { e16a = default(Enum16?), e32a = default(Enum32?), e64a = default(Enum64?), e16b = Enum16.On, e32b = Enum32.Off, e64b = Enum64.On });
208208
var results = m_database.Connection.Query<EnumValues>(@"select Enum16, Enum32, Enum64 from insert_enum_value order by rowid;").ToList();
209209
Assert.Equal(2, results.Count);
210-
Assert.Equal(null, results[0].Enum16);
211-
Assert.Equal(null, results[0].Enum32);
212-
Assert.Equal(null, results[0].Enum64);
210+
Assert.Null(results[0].Enum16);
211+
Assert.Null(results[0].Enum32);
212+
Assert.Null(results[0].Enum64);
213213
Assert.Equal(Enum16.On, results[1].Enum16);
214214
Assert.Equal(Enum32.Off, results[1].Enum32);
215215
Assert.Equal(Enum64.On, results[1].Enum64);

0 commit comments

Comments
 (0)