Skip to content

Commit d303b2b

Browse files
committed
Upgrade to AdoNet.Specification.Tests 2.0.0-alpha1.
1 parent 1100217 commit d303b2b

File tree

6 files changed

+130
-21
lines changed

6 files changed

+130
-21
lines changed

tests/Conformance.Tests/Conformance.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="AdoNet.Specification.Tests" Version="1.0.0" />
14+
<PackageReference Include="AdoNet.Specification.Tests" Version="2.0.0-alpha1" />
1515
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
1616
<PackageReference Include="xunit" Version="2.3.1" />
1717
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />

tests/Conformance.Tests/DataReaderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Conformance.Tests
44
{
5-
public sealed class DataReaderTests : DataReaderTestBase<DbFactoryFixture>
5+
public sealed class DataReaderTests : DataReaderTestBase<SelectValueFixture>
66
{
7-
public DataReaderTests(DbFactoryFixture fixture)
7+
public DataReaderTests(SelectValueFixture fixture)
88
: base(fixture)
99
{
1010
}
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
using System;
12
using System.Data.Common;
2-
using AdoNet.Specification.Tests.Databases;
3+
using AdoNet.Specification.Tests;
34
using MySql.Data.MySqlClient;
45

56
namespace Conformance.Tests
67
{
7-
public sealed class DbFactoryFixture : DbFactoryFixtureBase<MySqlDatabase>
8+
public class DbFactoryFixture : IDbFactoryFixture
89
{
9-
public override DbProviderFactory Factory => MySqlClientFactory.Instance;
10+
public DbFactoryFixture()
11+
{
12+
ConnectionString = Environment.GetEnvironmentVariable("CONNECTION_STRING") ?? "Server=localhost;User Id=mysqltest;Password='test;key=\"val';SSL Mode=None";
13+
}
14+
15+
public string ConnectionString { get; }
16+
public DbProviderFactory Factory => MySqlClientFactory.Instance;
1017
}
1118
}

tests/Conformance.Tests/MySqlDatabase.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using AdoNet.Specification.Tests;
2+
using Xunit;
3+
4+
namespace Conformance.Tests
5+
{
6+
public sealed class ParameterTests : ParameterTestBase<DbFactoryFixture>
7+
{
8+
public ParameterTests(DbFactoryFixture fixture)
9+
: base(fixture)
10+
{
11+
}
12+
13+
[Fact(Skip = "Allows `null` as well as `DBNull.value` for backwards compatibility.")]
14+
public override void Bind_requires_set_value()
15+
{
16+
}
17+
}
18+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using System.Data.Common;
5+
using AdoNet.Specification.Tests;
6+
7+
namespace Conformance.Tests
8+
{
9+
public class SelectValueFixture : ISelectValueFixture
10+
{
11+
public SelectValueFixture()
12+
{
13+
ConnectionString = new DbFactoryFixture().ConnectionString;
14+
ExecuteNonQuery(@"create schema if not exists mysqltest;");
15+
16+
ConnectionString += ";Database=mysqltest";
17+
ExecuteNonQuery(@"drop table if exists select_value;
18+
create table select_value
19+
(
20+
Id int not null primary key,
21+
`Binary` blob,
22+
Boolean bool,
23+
Byte tinyint unsigned,
24+
SByte tinyint,
25+
Int16 smallint,
26+
UInt16 smallint unsigned,
27+
Int32 int,
28+
UInt32 int unsigned,
29+
Int64 bigint,
30+
UInt64 bigint unsigned,
31+
Single float,
32+
`Double` double,
33+
`Decimal` decimal(57,28),
34+
String text,
35+
Guid char(36),
36+
`Date` date,
37+
`DateTime` datetime(3),
38+
`Time` time(3)
39+
);
40+
insert into select_value values
41+
(0, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null),
42+
(1, X'', null, null, null, null, null, null, null, null, null, null, null, null, '', '', null, null, null),
43+
(2, X'00', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '0', '00000000-0000-0000-0000-000000000000', null, null, '00:00:00'),
44+
(3, X'11', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, '1', '11111111-1111-1111-1111-111111111111', '1111-11-11', '1111-11-11 11:11:11.111', '11:11:11.111'),
45+
(4, null, false, 0, -128, -32768, 0, -2147483648, 0, -9223372036854775808, 0, 1.18e-38, 2.23e-308, 0.000000000000001, null, '33221100-5544-7766-9988-aabbccddeeff', '1000-01-01', '1000-01-01 00:00:00', '-838:59:59'),
46+
(5, null, true, 255, 127, 32767, 65535, 2147483647, 4294967295, 9223372036854775807, 18446744073709551615, 3.40e38, 1.79e308, 99999999999999999999.999999999999999, null, 'ccddeeff-aabb-8899-7766-554433221100', '9999-12-31', '9999-12-31 23:59:59.999', '838:59:59');
47+
");
48+
}
49+
50+
public string ConnectionString { get; }
51+
52+
public DbProviderFactory Factory => MySql.Data.MySqlClient.MySqlClientFactory.Instance;
53+
54+
public void DropSelectValueTable(IDbFactoryFixture factoryFixture) => ExecuteNonQuery("drop table if exists select_value;");
55+
56+
public string CreateSelectSql(DbType dbType, ValueKind kind) => $"SELECT `{dbType.ToString()}` from select_value WHERE Id = {(int) kind};";
57+
58+
public string CreateSelectSql(byte[] value) => $"SELECT X'{BitConverter.ToString(value).Replace("-", "")}'";
59+
60+
public string SelectNoRows => "SELECT * FROM mysql.user WHERE 0 = 1;";
61+
62+
public IReadOnlyCollection<DbType> SupportedDbTypes { get; } = new[]
63+
{
64+
DbType.Binary,
65+
DbType.Boolean,
66+
DbType.Byte,
67+
DbType.Date,
68+
DbType.DateTime,
69+
DbType.Decimal,
70+
DbType.Double,
71+
DbType.Guid,
72+
DbType.Int16,
73+
DbType.Int32,
74+
DbType.Int64,
75+
DbType.SByte,
76+
DbType.Single,
77+
DbType.String,
78+
DbType.Time,
79+
DbType.UInt16,
80+
DbType.UInt32,
81+
DbType.UInt64,
82+
};
83+
84+
private void ExecuteNonQuery(string sql)
85+
{
86+
using (var connection = Factory.CreateConnection())
87+
{
88+
connection.ConnectionString = ConnectionString;
89+
connection.Open();
90+
91+
using (var command = connection.CreateCommand())
92+
{
93+
command.CommandText = sql;
94+
command.ExecuteNonQuery();
95+
}
96+
}
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)