Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The unit test project (SmartSql.Test.Unit) uses MySql as the database for easy integration testing. #163

Merged
merged 32 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ad6aaff
add unit-test-mysql branch(https://github.com/dotnetcore/SmartSql/iss…
Ahoo-Wang Apr 11, 2022
c07306d
refactor unit-test (undone)
Ahoo-Wang Apr 12, 2022
53e1160
add integration-test.yml
Ahoo-Wang Apr 12, 2022
53308f7
fix TargetFrameworks
Ahoo-Wang Apr 12, 2022
ee7a190
change TargetFrameworks 6.0
Ahoo-Wang Apr 12, 2022
a31f7ec
refactor CustomizeTypeHandlerTest
Ahoo-Wang Apr 12, 2022
d4bc7fc
refactor EnvTest/DynamicTest
Ahoo-Wang Apr 12, 2022
7d1bb9c
fix DynamicTest
Ahoo-Wang Apr 12, 2022
0d661a1
refactor
Ahoo-Wang Apr 12, 2022
949045e
refactor NowTest/UUIDTest
Ahoo-Wang Apr 12, 2022
5ce6a4b
refactor SetTest
Ahoo-Wang Apr 12, 2022
7abf4c2
refactor PlaceholderTest
Ahoo-Wang Apr 12, 2022
41e62c4
refactor `WhereTest`
Ahoo-Wang Apr 12, 2022
30af3ae
refactor RangeTest
Ahoo-Wang Apr 12, 2022
edebdb2
refactor IsGreaterThanTest
Ahoo-Wang Apr 12, 2022
b8ae5cb
refactor IsLessThanTest
Ahoo-Wang Apr 12, 2022
be62bbc
refactor IsNotEmptyTest
Ahoo-Wang Apr 12, 2022
a3c0794
refactor ForTest
Ahoo-Wang Apr 12, 2022
1719c44
refactor IncludeTest
Ahoo-Wang Apr 12, 2022
a32a8ca
refactor OrderByTest
Ahoo-Wang Apr 12, 2022
7919be8
config tag unit test refactoring completed
Ahoo-Wang Apr 12, 2022
f3426e2
refactor DITest
Ahoo-Wang Apr 12, 2022
f29de91
refactor SnowflakeIdTest
Ahoo-Wang Apr 12, 2022
cd70c79
refactor ValueTypeDeserializerTest
Ahoo-Wang Apr 12, 2022
928794b
fix AddDeserializer
Ahoo-Wang Apr 12, 2022
ff77b6c
refactor some unit-test
Ahoo-Wang Apr 12, 2022
c3831d0
update init-mysql-db.sql
Ahoo-Wang Apr 12, 2022
f7d9b83
refactor DbSessionTest
Ahoo-Wang Apr 12, 2022
a3721b8
refactor some unit-test
Ahoo-Wang Apr 12, 2022
d7b9e9a
refactor unit-test
Ahoo-Wang Apr 12, 2022
55b7e7b
fix IsGitHubCI
Ahoo-Wang Apr 12, 2022
2b7563a
rename SkipGitHubCIAttribute to SkipGitHubActionAttribute
Ahoo-Wang Apr 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Integration Test
on: [ push ]
jobs:
SmartSql-Unit-Test:
name: SmartSql Unit Test
runs-on: ubuntu-latest
strategy:
matrix:
dotnet: [ '6.0.x' ]
services:
redis:
image: redis
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379

steps:
- name: Start Mysql
run: sudo /etc/init.d/mysql start

- name: Checkout
uses: actions/checkout@master

- name: Set up dotnet
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ matrix.dotnet }}
server-id: github
settings-path: ${{ github.workspace }}

- name: Init SmartSql-Test-Db
run: mysql -vvv -h localhost -uroot -proot < src/SmartSql.Test.Unit/DB/init-mysql-db.sql

- name: Unit Test
run: dotnet test
8 changes: 0 additions & 8 deletions sample/SmartSql.Sample.AspNetCore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,8 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SkyApm.Diagnostics.SmartSql;
using SkyApm.Utilities.DependencyInjection;
using SmartSql.Cache.Sync;
using SmartSql.ConfigBuilder;
using SmartSql.DIExtension;
using SmartSql.InvokeSync;
using SmartSql.InvokeSync.Kafka;
using SmartSql.InvokeSync.RabbitMQ;
using SmartSql.Sample.AspNetCore.Service;
using Swashbuckle.AspNetCore.Swagger;
Expand Down
2 changes: 1 addition & 1 deletion src/SmartSql.Bulk.MySql/SmartSql.Bulk.MySql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MySql.Data" Version="8.0.15" />
<PackageReference Include="MySql.Data" Version="8.0.28" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/SmartSql.Test.Unit/AbstractTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace SmartSql.Test.Unit
{
public abstract class AbstractTest
{
protected String DbType => "SqlServer";
protected String ConnectionString => "Data Source=.;Initial Catalog=SmartSqlTestDB;Integrated Security=True";
protected String DbType => "MySql";
protected String ConnectionString => "server=localhost;uid=root;pwd=root;database=SmartSqlTestDB";
}
}
21 changes: 14 additions & 7 deletions src/SmartSql.Test.Unit/AutoConverter/AutoConverterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public AutoConverterTest(SmartSqlFixture smartSqlFixture)
SqlMapper = smartSqlFixture.SqlMapper;
}

[Fact]
// TODO
[Fact(Skip = "TODO")]
public void DefaultAutoConverterTest()
{
for (var i = 1; i <= 2; i++)
Expand All @@ -42,7 +43,8 @@ public void DefaultAutoConverterTest()
Assert.NotEqual(0, userList.First().Id);
}

[Fact]
// TODO
[Fact(Skip = "TODO")]
public void DisabledAutoConverterTest()
{
var userId = SqlMapper.QuerySingle<long>(new RequestContext
Expand Down Expand Up @@ -70,7 +72,8 @@ public void DisabledAutoConverterTest()
Assert.Equal(userId, userEntity.Id);
}

[Fact]
// TODO
[Fact(Skip = "TODO")]
public void UseNoneAutoConverterTest()
{
var userId = SqlMapper.QuerySingle<long>(new RequestContext
Expand Down Expand Up @@ -98,7 +101,8 @@ public void UseNoneAutoConverterTest()
Assert.Equal(userId, userEntity.Id);
}

[Fact]
// TODO
[Fact(Skip = "TODO")]
public void AssignAutoFromRequestConverterTest()
{
for (var i = 1; i <= 2; i++)
Expand Down Expand Up @@ -127,7 +131,8 @@ public void AssignAutoFromRequestConverterTest()
Assert.NotEqual(0, list.First().Col_Id);
}

[Fact]
// TODO
[Fact(Skip = "TODO")]
public void AssignFromMapAutoConverterTest()
{
for (var i = 1; i <= 2; i++)
Expand Down Expand Up @@ -155,7 +160,8 @@ public void AssignFromMapAutoConverterTest()
Assert.NotEqual(0, list.First().Col_Id);
}

[Fact]
// TODO
[Fact(Skip = "TODO")]
public void AssignFromStatementAutoConverterTest()
{
for (var i = 1; i <= 2; i++)
Expand Down Expand Up @@ -187,7 +193,8 @@ public void AssignFromStatementAutoConverterTest()
/// <summary>
/// 同时指定AutoConverter和ResultMap时,ResultMap优先级高于AutoConverter
/// </summary>
[Fact]
// TODO
[Fact(Skip = "TODO")]
public void AssignResultMapAndAutoConverterTest()
{
for (var i = 1; i <= 2; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/SmartSql.Test.Unit/Bulk/BulkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void ToDataTable()
}

var watch = Stopwatch.StartNew();
var dataTableE1 = list.ToDataTable();
var dataTable = list.ToDataTable();
_output.WriteLine($"ToDataTable taken :{watch.ElapsedMilliseconds}");
watch.Stop();
}
Expand Down
8 changes: 4 additions & 4 deletions src/SmartSql.Test.Unit/Bulk/MsSqlServerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public MsSqlServerTest(MsSqlServerFixture serverFixture)
_dbSessionFactory = serverFixture.DbSessionFactory;
}

[Fact]
[Fact(Skip = "The database environment that the project depends on does not exist.")]
public void Insert()
{
using (var dbSession = _dbSessionFactory.Open())
Expand All @@ -54,7 +54,7 @@ public void Insert()
}


[Fact]
[Fact(Skip = "The database environment that the project depends on does not exist.")]
public void InsertByList()
{
using (var dbSession = _dbSessionFactory.Open())
Expand All @@ -69,7 +69,7 @@ public void InsertByList()
}
}

[Fact]
[Fact(Skip = "The database environment that the project depends on does not exist.")]
public async Task InsertAsync()
{
using (var dbSession = _dbSessionFactory.Open())
Expand All @@ -85,7 +85,7 @@ public async Task InsertAsync()
}
}

[Fact]
[Fact(Skip = "The database environment that the project depends on does not exist.")]
public async Task InsertByListAsync()
{
using (var dbSession = _dbSessionFactory.Open())
Expand Down
4 changes: 2 additions & 2 deletions src/SmartSql.Test.Unit/Bulk/MySqlConnectorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ namespace SmartSql.Test.Unit.Bulk
{
public class MySqlConnectorTest
{
[Fact]
[Fact(Skip = "The database environment that the project depends on does not exist.")]
public void Insert()
{
var dbSessionFactory = new SmartSqlBuilder()
.UseDataSource(DbProvider.MYSQL_CONNECTOR, "Data Source=localhost;database=SmartSqlTestDB;uid=root;pwd=SmartSql.net")
.UseDataSource(DbProvider.MYSQL_CONNECTOR, "Data Source=localhost;database=SmartSqlTestDB;uid=root;pwd=root")
.UseAlias("MySqlConnectorTest")
.Build().GetDbSessionFactory();

Expand Down
4 changes: 2 additions & 2 deletions src/SmartSql.Test.Unit/Bulk/MySqlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ namespace SmartSql.Test.Unit.Bulk
{
public class MySqlTest
{
[Fact]
[Fact(Skip = "The database environment that the project depends on does not exist.")]
public void Insert()
{
var dbSessionFactory = new SmartSqlBuilder()
.UseDataSource(DbProvider.MYSQL, "Data Source=localhost;database=SmartSqlTestDB;uid=root;pwd=SmartSql.net")
.UseDataSource(DbProvider.MYSQL, "Data Source=localhost;database=SmartSqlTestDB;uid=root;pwd=root")
.UseAlias("MySqlTest")
.Build().GetDbSessionFactory();

Expand Down
2 changes: 1 addition & 1 deletion src/SmartSql.Test.Unit/Bulk/PostgreSqlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace SmartSql.Test.Unit.Bulk
{
public class PostgreSqlTest
{
[Fact]
[Fact(Skip = "The database environment that the project depends on does not exist.")]
public void Insert()
{
var dbSessionFactory = new SmartSqlBuilder()
Expand Down
8 changes: 4 additions & 4 deletions src/SmartSql.Test.Unit/Bulk/SqlServerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public SqlServerTest(SqlServerFixture serverFixture)
_dbSessionFactory = serverFixture.DbSessionFactory;
}

[Fact]
[Fact(Skip = "The database environment that the project depends on does not exist.")]
public void Insert()
{
using (var dbSession = _dbSessionFactory.Open())
Expand All @@ -54,7 +54,7 @@ public void Insert()
}


[Fact]
[Fact(Skip = "The database environment that the project depends on does not exist.")]
public void InsertByList()
{
using (var dbSession = _dbSessionFactory.Open())
Expand All @@ -69,7 +69,7 @@ public void InsertByList()
}
}

[Fact]
[Fact(Skip = "The database environment that the project depends on does not exist.")]
public async Task InsertAsync()
{
using (var dbSession = _dbSessionFactory.Open())
Expand All @@ -85,7 +85,7 @@ public async Task InsertAsync()
}
}

[Fact]
[Fact(Skip = "The database environment that the project depends on does not exist.")]
public async Task InsertByListAsync()
{
using (var dbSession = _dbSessionFactory.Open())
Expand Down
8 changes: 8 additions & 0 deletions src/SmartSql.Test.Unit/Cache/CachedEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace SmartSql.Test.Unit.Cache;

public class CachedEntity
{
public string Name { get; set; }
}
22 changes: 9 additions & 13 deletions src/SmartSql.Test.Unit/Cache/FifoCacheProviderTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using SmartSql.Test.Entities;
using System;
using System.Collections.Generic;
using System.Text;
using SmartSql.Cache;
using SmartSql.Cache.Default;
using Xunit;

namespace SmartSql.Test.Unit.Cache
Expand All @@ -18,21 +16,19 @@ public FifoCacheProviderTest(SmartSqlFixture smartSqlFixture)
}

[Fact]
public void QueryByFifoCache()
public void GetByCache()
{
var list = SqlMapper.Query<AllPrimitive>(new RequestContext
var expected = SqlMapper.QuerySingle<CachedEntity>(new RequestContext
{
Scope = nameof(AllPrimitive),
SqlId = "QueryByFifoCache",
Request = new {Taken = 8},
Scope = "FifoCache",
SqlId = "GetByCache"
});
var cachedList = SqlMapper.Query<AllPrimitive>(new RequestContext
var actual = SqlMapper.QuerySingle<CachedEntity>(new RequestContext
{
Scope = nameof(AllPrimitive),
SqlId = "QueryByFifoCache",
Request = new {Taken = 8}
Scope = "FifoCache",
SqlId = "GetByCache"
});
Assert.Equal(list.GetHashCode(), cachedList.GetHashCode());
Assert.Equal(expected, actual);
}
}
}
36 changes: 17 additions & 19 deletions src/SmartSql.Test.Unit/Cache/LruCacheProviderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,35 @@ public LruCacheProviderTest(SmartSqlFixture smartSqlFixture)
}

[Fact]
public void QueryByLruCache()
public void GetByCache()
{
var list = SqlMapper.Query<AllPrimitive>(new RequestContext
var expected = SqlMapper.QuerySingle<CachedEntity>(new RequestContext
{
Scope = nameof(AllPrimitive),
SqlId = "QueryByLruCache",
Request = new {Taken = 8}
Scope = "LruCache",
SqlId = "GetByCache"
});
var cachedList = SqlMapper.Query<AllPrimitive>(new RequestContext
var actual = SqlMapper.QuerySingle<CachedEntity>(new RequestContext
{
Scope = nameof(AllPrimitive),
SqlId = "QueryByLruCache",
Request = new {Taken = 8}
Scope = "LruCache",
SqlId = "GetByCache"
});
Assert.Equal(list.GetHashCode(), cachedList.GetHashCode());
Assert.Equal(expected, actual);
}

[Fact]
public void QueryByLruCacheFromRequest()
public void GetByCacheFromRequest()
{
var list = SqlMapper.Query<AllPrimitive>(new RequestContext
var list = SqlMapper.Query<CachedEntity>(new RequestContext
{
Scope = nameof(AllPrimitive),
SqlId = "QueryByLruCacheFromRequest",
Request = new {Request = new {Taken = 8}}
Scope = "LruCache",
SqlId = "GetByCacheFromRequest",
Request = new { CacheKey = "CacheKey" }
});
var cachedList = SqlMapper.Query<AllPrimitive>(new RequestContext
var cachedList = SqlMapper.Query<CachedEntity>(new RequestContext
{
Scope = nameof(AllPrimitive),
SqlId = "QueryByLruCacheFromRequest",
Request = new {Request = new {Taken = 8}}
Scope = "LruCache",
SqlId = "GetByCacheFromRequest",
Request = new { CacheKey = "CacheKey" }
});
Assert.Equal(list.GetHashCode(), cachedList.GetHashCode());
}
Expand Down
Loading