-
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add master-pr-ci.yml;
- Loading branch information
agile.zhou
committed
Jan 7, 2024
1 parent
5e77ba9
commit 462654d
Showing
9 changed files
with
341 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: master pr ci workflow | ||
|
||
on: | ||
pull_request: | ||
branches: [ master ] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build-reactapp: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: src/AgileConfig.Server.UI/react-ui-antd | ||
strategy: | ||
matrix: | ||
node-version: [16.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- run: npm install | ||
- run: npm run build | ||
build-dotnet: | ||
needs: build-reactapp | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup .NET Core | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: 8.0.* | ||
- name: Install dependencies | ||
run: dotnet restore | ||
- name: Build | ||
run: dotnet build --configuration Release --no-restore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
.../AgileConfig.Server.Data.AbstractionTests/AgileConfig.Server.Data.AbstractionTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="3.0.4" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="3.0.4" /> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\AgileConfig.Server.Common\AgileConfig.Server.Common.csproj" /> | ||
<ProjectReference Include="..\..\src\AgileConfig.Server.Data.Abstraction\AgileConfig.Server.Data.Abstraction.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
47 changes: 47 additions & 0 deletions
47
test/AgileConfig.Server.Data.AbstractionTests/DbConfig/DbConfigInfoFactoryTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using AgileConfig.Server.Common; | ||
using AgileConfig.Server.Data.Abstraction.DbProvider; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace AgileConfig.Server.Data.AbstractionTests.DbConfig | ||
{ | ||
[TestClass] | ||
public class DbConfigInfoFactoryTests | ||
{ | ||
[TestMethod] | ||
public void TestGetConfigInfo() | ||
{ | ||
var configMap = new Dictionary<string, string>() { | ||
{"db:provider","sqlserver" }, | ||
{"db:conn","localhost" }, | ||
{"db:env:test:provider","sqlite" }, | ||
{"db:env:test:conn","Data Source=agile_config.db" }, | ||
}; | ||
|
||
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); | ||
configurationBuilder.AddInMemoryCollection(configMap); | ||
var configuration = configurationBuilder.Build(); | ||
Global.Config = configuration; | ||
|
||
var configInfo = DbConfigInfoFactory.GetConfigInfo(); | ||
Assert.IsNotNull(configInfo); | ||
Assert.AreEqual("sqlserver", configInfo.Provider); | ||
Assert.AreEqual("localhost", configInfo.ConnectionString); | ||
|
||
configInfo = DbConfigInfoFactory.GetConfigInfo("test"); | ||
Assert.IsNotNull(configInfo); | ||
Assert.AreEqual("sqlite", configInfo.Provider); | ||
Assert.AreEqual("Data Source=agile_config.db", configInfo.ConnectionString); | ||
|
||
configInfo = DbConfigInfoFactory.GetConfigInfo("x"); | ||
Assert.IsNotNull(configInfo); | ||
Assert.AreEqual("sqlserver", configInfo.Provider); | ||
Assert.AreEqual("localhost", configInfo.ConnectionString); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
test/AgileConfig.Server.Data.FreesqlTests/AgileConfig.Server.Data.FreesqlTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="3.0.4" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="3.0.4" /> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\AgileConfig.Server.Data.Freesql\AgileConfig.Server.Data.Freesql.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using AgileConfig.Server.Data.Freesql; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Configuration; | ||
using AgileConfig.Server.Common; | ||
|
||
namespace AgileConfig.Server.Data.Freesql.Tests | ||
{ | ||
[TestClass()] | ||
public class FreeSQLTests | ||
{ | ||
[TestMethod()] | ||
public void GetInstanceByEnvTest() | ||
{ | ||
var configMap = new Dictionary<string, string>() { | ||
{"db:provider","sqlite" }, | ||
{"db:conn","Data Source=agile_config.db" }, | ||
{"db:env:test:provider","sqlite" }, | ||
{"db:env:test:conn","Data Source=agile_config1.db" }, | ||
}; | ||
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); | ||
configurationBuilder.AddInMemoryCollection(configMap); | ||
var configuration = configurationBuilder.Build(); | ||
Global.Config = configuration; | ||
|
||
var fsq = FreeSQL.GetInstanceByEnv(""); | ||
Assert.IsNotNull(fsq); | ||
Assert.AreEqual(FreeSql.DataType.Sqlite, fsq.Ado.DataType); | ||
|
||
var fsqtest = FreeSQL.GetInstanceByEnv("test"); | ||
Assert.IsNotNull(fsqtest); | ||
Assert.AreEqual(FreeSql.DataType.Sqlite, fsqtest.Ado.DataType); | ||
|
||
Assert.AreNotSame(fsq, fsqtest); | ||
var fsqtest_ag = FreeSQL.GetInstanceByEnv("test"); | ||
Assert.AreSame(fsqtest, fsqtest_ag); | ||
|
||
|
||
var fsq_none = FreeSQL.GetInstanceByEnv("x"); | ||
Assert.IsNotNull(fsq_none); | ||
Assert.AreEqual(FreeSql.DataType.Sqlite, fsq_none.Ado.DataType); | ||
Assert.AreSame(fsq, fsq_none); | ||
} | ||
} | ||
} |
141 changes: 141 additions & 0 deletions
141
test/AgileConfig.Server.Data.FreesqlTests/FreeSqlUowTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using AgileConfig.Server.Data.Freesql; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Configuration; | ||
using AgileConfig.Server.Common; | ||
using AgileConfig.Server.Data.Entity; | ||
|
||
namespace AgileConfig.Server.Data.Freesql.Tests | ||
{ | ||
[TestClass()] | ||
public class FreeSqlUowTests | ||
{ | ||
[TestInitialize] | ||
public void TestInitialize() | ||
{ | ||
var configMap = new Dictionary<string, string>() { | ||
{"db:provider","sqlite" }, | ||
{"db:conn","Data Source=agile_config.db" }, | ||
{"db:env:test:provider","sqlite" }, | ||
{"db:env:test:conn","Data Source=agile_config1.db" }, | ||
}; | ||
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); | ||
configurationBuilder.AddInMemoryCollection(configMap); | ||
var configuration = configurationBuilder.Build(); | ||
Global.Config = configuration; | ||
|
||
var fsql = FreeSQL.GetInstanceByEnv(""); | ||
fsql.CodeFirst.SyncStructure<User_test>(); | ||
fsql.CodeFirst.SyncStructure<Address_test>(); | ||
fsql.Delete<User_test>(new User_test() { Id = 1 }).ExecuteAffrows(); | ||
fsql.Delete<Address_test>(new Address_test() { Id = 1 }).ExecuteAffrows(); | ||
} | ||
|
||
|
||
[TestMethod()] | ||
public async Task SaveChangesAsyncTest_success() | ||
{ | ||
// arrange | ||
var fsql = FreeSQL.GetInstanceByEnv(""); | ||
var user = new User_test() | ||
{ | ||
Id = 1, | ||
Name = "abc" | ||
}; | ||
var address = new Address_test() | ||
{ | ||
Id = 1, | ||
Address = "Address" | ||
}; | ||
// act | ||
using var uow = new FreeSqlUow(fsql); | ||
|
||
var userrepository = fsql.GetRepository<User_test>(); | ||
userrepository.UnitOfWork = uow.GetFreesqlUnitOfWork(); | ||
var addressrepository = fsql.GetRepository<Address_test>(); | ||
addressrepository.UnitOfWork = uow.GetFreesqlUnitOfWork(); | ||
|
||
uow.Begin(); | ||
|
||
userrepository.Insert(user); | ||
user.Name = "test1"; | ||
userrepository.Update(user); | ||
addressrepository.Insert(address); | ||
address.Address = "test1"; | ||
addressrepository.Update(address); | ||
|
||
await uow.SaveChangesAsync(); | ||
|
||
// assert | ||
var username = fsql.GetRepository<User_test>().Where(x => x.Id == 1).ToOne().Name; | ||
var add = fsql.GetRepository<Address_test>().Where(x => x.Id == 1).ToOne().Address; | ||
Assert.AreEqual("test1", username); | ||
Assert.AreEqual("test1", add); | ||
} | ||
|
||
[TestMethod()] | ||
public async Task SaveChangesAsyncTest_rollback() | ||
{ | ||
// arrange | ||
var fsql = FreeSQL.GetInstanceByEnv(""); | ||
var user = new User_test() | ||
{ | ||
Id = 2, | ||
Name = "abc" | ||
}; | ||
var address = new Address_test() | ||
{ | ||
Id = 2, | ||
Address = "Address" | ||
}; | ||
|
||
// act | ||
using var uow = new FreeSqlUow(fsql); | ||
var userrepository = fsql.GetRepository<User_test>(); | ||
userrepository.UnitOfWork = uow.GetFreesqlUnitOfWork(); | ||
var addressrepository = fsql.GetRepository<Address_test>(); | ||
addressrepository.UnitOfWork = uow.GetFreesqlUnitOfWork(); | ||
|
||
uow.Begin(); | ||
try | ||
{ | ||
userrepository.Insert(user); | ||
user.Name = "test1"; | ||
userrepository.Update(user); | ||
throw new Exception("test"); | ||
addressrepository.Insert(address); | ||
address.Address = "test1"; | ||
addressrepository.Update(address); | ||
|
||
await uow.SaveChangesAsync(); | ||
} | ||
catch (Exception exc) | ||
{ | ||
Assert.IsNotNull(exc); | ||
} | ||
|
||
|
||
// assert | ||
var _user = fsql.GetRepository<User_test>().Where(x => x.Id == 2).ToOne(); | ||
var _address = fsql.GetRepository<Address_test>().Where(x => x.Id == 2).ToOne(); | ||
|
||
Assert.IsNull(_user); | ||
Assert.IsNull(_address); | ||
} | ||
} | ||
|
||
public class User_test | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
} | ||
public class Address_test | ||
{ | ||
public int Id { get; set; } | ||
public string Address { get; set; } | ||
} | ||
} |