Skip to content

Commit 857b554

Browse files
committed
feat:添加单元基础操作单元测试,验证通过适配版本已可用
1 parent eb5837b commit 857b554

File tree

9 files changed

+106
-20
lines changed

9 files changed

+106
-20
lines changed

Directory.Build.props

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,4 @@
1919
<PackageProjectUrl>https://github.com/dotnetcore/EntityFrameworkCore.KingbaseES</PackageProjectUrl>
2020
</PropertyGroup>
2121

22-
<ItemGroup>
23-
<None Include="$(MSBuildThisFileDirectory)postgresql.png" Pack="true" PackagePath="" />
24-
</ItemGroup>
2522
</Project>

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</PropertyGroup>
66
<ItemGroup>
77
<PackageVersion Include="JetBrains.Annotations" Version="2023.2.0" />
8-
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="$(EFCoreVersion)" />
8+
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="6.0.22" />
99
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="$(EFCoreVersion)" />
1010
<PackageVersion Include="Microsoft.EntityFrameworkCore.Abstractions" Version="$(EFCoreVersion)" />
1111
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational.Specification.Tests" Version="$(EFCoreVersion)" />

EFCore.KingbaseES.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{ED612DB1-A
1818
EndProject
1919
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.KingbaseES", "src\EFCore.KingbaseES\EFCore.KingbaseES.csproj", "{FADDA2D1-03B4-4DEF-8D24-DD1CA4E81F4A}"
2020
EndProject
21+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KingbaseES.BasicTest", "test\KingbaseES.BasicTest\KingbaseES.BasicTest.csproj", "{25141572-8051-4D49-98ED-7AE12F7EF9FC}"
22+
EndProject
2123
Global
2224
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2325
Debug|Any CPU = Debug|Any CPU
@@ -36,12 +38,25 @@ Global
3638
{FADDA2D1-03B4-4DEF-8D24-DD1CA4E81F4A}.Release|Any CPU.Build.0 = Release|Any CPU
3739
{FADDA2D1-03B4-4DEF-8D24-DD1CA4E81F4A}.Release|x64.ActiveCfg = Release|Any CPU
3840
{FADDA2D1-03B4-4DEF-8D24-DD1CA4E81F4A}.Release|x86.ActiveCfg = Release|Any CPU
41+
{25141572-8051-4D49-98ED-7AE12F7EF9FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42+
{25141572-8051-4D49-98ED-7AE12F7EF9FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
43+
{25141572-8051-4D49-98ED-7AE12F7EF9FC}.Debug|x64.ActiveCfg = Debug|Any CPU
44+
{25141572-8051-4D49-98ED-7AE12F7EF9FC}.Debug|x64.Build.0 = Debug|Any CPU
45+
{25141572-8051-4D49-98ED-7AE12F7EF9FC}.Debug|x86.ActiveCfg = Debug|Any CPU
46+
{25141572-8051-4D49-98ED-7AE12F7EF9FC}.Debug|x86.Build.0 = Debug|Any CPU
47+
{25141572-8051-4D49-98ED-7AE12F7EF9FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
48+
{25141572-8051-4D49-98ED-7AE12F7EF9FC}.Release|Any CPU.Build.0 = Release|Any CPU
49+
{25141572-8051-4D49-98ED-7AE12F7EF9FC}.Release|x64.ActiveCfg = Release|Any CPU
50+
{25141572-8051-4D49-98ED-7AE12F7EF9FC}.Release|x64.Build.0 = Release|Any CPU
51+
{25141572-8051-4D49-98ED-7AE12F7EF9FC}.Release|x86.ActiveCfg = Release|Any CPU
52+
{25141572-8051-4D49-98ED-7AE12F7EF9FC}.Release|x86.Build.0 = Release|Any CPU
3953
EndGlobalSection
4054
GlobalSection(SolutionProperties) = preSolution
4155
HideSolutionNode = FALSE
4256
EndGlobalSection
4357
GlobalSection(NestedProjects) = preSolution
4458
{FADDA2D1-03B4-4DEF-8D24-DD1CA4E81F4A} = {8537E50E-CF7F-49CB-B4EF-3E2A1B11F050}
59+
{25141572-8051-4D49-98ED-7AE12F7EF9FC} = {ED612DB1-AB32-4603-95E7-891BACA71C39}
4560
EndGlobalSection
4661
GlobalSection(ExtensibilityGlobals) = postSolution
4762
SolutionGuid = {F4EAAE6D-758C-4184-9D8C-7113384B61A8}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class BlogContext : DbContext
2121
public DbSet<Blog> Blogs { get; set; }
2222

2323
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
24-
=> optionsBuilder.UseKdbndp(@"Host=myserver;Username=mylogin;Password=mypass;Database=mydatabase");
24+
=> optionsBuilder.UseKdbndp(@"host={host};port={port};database={database};user id={username};password={password};");
2525
}
2626

2727
public class Blog

test/Directory.Build.props

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,6 @@
55
<PropertyGroup>
66
<IsPackable>false</IsPackable>
77
<GenerateDocumentationFile>false</GenerateDocumentationFile>
8-
9-
<!-- There's lots of use of internal EF Core APIs from the tests, suppress the analyzer warnings for those -->
10-
<NoWarn>$(NoWarn);xUnit1003;xUnit1004;xUnit1013;EF1001</NoWarn>
118
</PropertyGroup>
129

13-
<ItemGroup>
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" />
15-
<PackageReference Include="xunit" />
16-
<PackageReference Include="xunit.runner.visualstudio" />
17-
<PackageReference Include="GitHubActionsTestLogger" />
18-
<PackageReference Include="Npgsql" />
19-
</ItemGroup>
20-
21-
<ItemGroup>
22-
<None Include="$(MSBuildThisFileDirectory)xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
23-
</ItemGroup>
24-
2510
</Project>

test/KingbaseES.BasicTest/Blog.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using System.ComponentModel.DataAnnotations.Schema;
3+
4+
namespace KingbaseES.BasicTest
5+
{
6+
[Table("blogs")]
7+
public class Blog
8+
{
9+
[Key]
10+
[Column("id")]
11+
public int Id { get; set; }
12+
[Column("name")]
13+
public string Name { get; set; }
14+
}
15+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Microsoft.EntityFrameworkCore;
2+
3+
namespace KingbaseES.BasicTest
4+
{
5+
public class BlogContext : DbContext
6+
{
7+
public BlogContext(DbContextOptions<BlogContext> options):base(options)
8+
{
9+
10+
}
11+
public DbSet<Blog> Blogs { get; set; }
12+
13+
protected override void OnModelCreating(ModelBuilder modelBuilder)
14+
{
15+
modelBuilder.HasSequence("tests_id_seq")
16+
.HasMin(1).IncrementsBy(1).HasMax(long.MaxValue).StartsAt(1);
17+
18+
modelBuilder.Entity<Blog>(b =>
19+
{
20+
b.Property(p => p.Id).HasDefaultValueSql("nextval('tests_id_seq'::regclass)");
21+
});
22+
}
23+
}
24+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.EntityFrameworkCore" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\..\src\EFCore.KingbaseES\EFCore.KingbaseES.csproj" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using Microsoft.Extensions.DependencyInjection;
3+
4+
namespace KingbaseES.BasicTest
5+
{
6+
internal static class Program
7+
{
8+
static void Main(string[] args)
9+
{
10+
var services = new ServiceCollection();
11+
12+
services.AddDbContext<BlogContext>(options => options.UseKdbndp(@"host=localhost;port=54321;database=test;user id=system;password=123456;"));
13+
14+
var serviceProvider = services.BuildServiceProvider();
15+
16+
var context = serviceProvider.GetRequiredService<BlogContext>();
17+
18+
// get list
19+
var blogs = context.Blogs.ToList();
20+
21+
//add
22+
context.Add(new Blog() { Name = "jeffcky" });
23+
var result = context.SaveChanges();
24+
25+
//update
26+
var first = context.Blogs.FirstOrDefault();
27+
first.Name = "jeffcky2";
28+
context.SaveChanges();
29+
30+
Console.ReadKey();
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)