-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for generating schema (#11)
Co-authored-by: Giau. Tran Minh <[email protected]>
- Loading branch information
1 parent
e434ac6
commit 8d5ad94
Showing
11 changed files
with
225 additions
and
10 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
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
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,36 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Atlas.Provider.Demo\Atlas.Provider.Demo.csproj" /> | ||
<ProjectReference Include="..\..\src\Atlas.Provider.Core\Atlas.Provider.Core.csproj" /> | ||
<ProjectReference Include="..\..\src\Atlas.Provider.Loader\Atlas.Provider.Loader.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="data\*" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="data\*"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</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,46 @@ | ||
using Xunit; | ||
using System.Diagnostics; | ||
using System.Reflection; | ||
|
||
public class GenerateSchemaTest | ||
{ | ||
[Theory] | ||
[InlineData("SqlServer", "data/sqlserver_default")] | ||
[InlineData("Postgres", "data/postgres_default")] | ||
[InlineData("MySql", "data/mysql_default")] | ||
[InlineData("Sqlite", "data/sqlite_default")] | ||
public void Can_generate_script(string providerName, string expectedFile) | ||
{ | ||
var dllFileName = Assembly.Load(new AssemblyName("Atlas.Provider.Loader")).Location; | ||
|
||
ProcessStartInfo startInfo = new ProcessStartInfo | ||
{ | ||
WorkingDirectory = Path.GetFullPath("../../../../../src/Atlas.Provider.Demo"), | ||
FileName = "dotnet", | ||
Arguments = $"exec {dllFileName} -- {providerName}", | ||
RedirectStandardOutput = true, | ||
RedirectStandardError = true, | ||
UseShellExecute = false, | ||
CreateNoWindow = true | ||
}; | ||
|
||
using Process? process = Process.Start(startInfo); | ||
Assert.NotNull(process); | ||
string output = process.StandardOutput.ReadToEnd(); | ||
string error = process.StandardError.ReadToEnd(); | ||
process.WaitForExit(); | ||
Assert.Equal(FileReader.Read(expectedFile), output); | ||
Assert.Equal("", error); | ||
} | ||
} | ||
internal static class FileReader | ||
{ | ||
public static string Read(string filePath) | ||
{ | ||
return File.ReadAllText( | ||
Path.Combine( | ||
Directory.GetCurrentDirectory(), | ||
filePath | ||
)); | ||
} | ||
} |
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,29 @@ | ||
ALTER DATABASE CHARACTER SET utf8mb4; | ||
|
||
|
||
CREATE TABLE `Blogs` ( | ||
`BlogId` int NOT NULL AUTO_INCREMENT, | ||
`Url` varchar(200) CHARACTER SET utf8mb4 NOT NULL, | ||
`Rating` decimal(5,2) NOT NULL, | ||
`Title` longtext CHARACTER SET utf8mb4 NOT NULL, | ||
`Content` longtext CHARACTER SET utf8mb4 NOT NULL, | ||
`Author` varchar(200) CHARACTER SET utf8mb4 NOT NULL DEFAULT 'Anonymous', | ||
CONSTRAINT `PK_Blogs` PRIMARY KEY (`BlogId`), | ||
CONSTRAINT `AK_Blogs_Url` UNIQUE (`Url`) | ||
) CHARACTER SET=utf8mb4; | ||
|
||
|
||
CREATE TABLE `Post` ( | ||
`PostId` int NOT NULL AUTO_INCREMENT, | ||
`Title` longtext CHARACTER SET utf8mb4 NOT NULL, | ||
`Content` longtext CHARACTER SET utf8mb4 NOT NULL, | ||
`BlogUrl` varchar(200) CHARACTER SET utf8mb4 NULL, | ||
CONSTRAINT `PK_Post` PRIMARY KEY (`PostId`), | ||
CONSTRAINT `FK_Post_Blogs_BlogUrl` FOREIGN KEY (`BlogUrl`) REFERENCES `Blogs` (`Url`) | ||
) CHARACTER SET=utf8mb4; | ||
|
||
|
||
CREATE INDEX `IX_Post_BlogUrl` ON `Post` (`BlogUrl`); | ||
|
||
|
||
|
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,26 @@ | ||
CREATE TABLE "Blogs" ( | ||
"BlogId" integer GENERATED BY DEFAULT AS IDENTITY, | ||
"Url" varchar(200) NOT NULL, | ||
"Rating" numeric(5,2) NOT NULL, | ||
"Title" text NOT NULL, | ||
"Content" text NOT NULL, | ||
"Author" character varying(200) NOT NULL DEFAULT 'Anonymous', | ||
CONSTRAINT "PK_Blogs" PRIMARY KEY ("BlogId"), | ||
CONSTRAINT "AK_Blogs_Url" UNIQUE ("Url") | ||
); | ||
|
||
|
||
CREATE TABLE "Post" ( | ||
"PostId" integer GENERATED BY DEFAULT AS IDENTITY, | ||
"Title" text NOT NULL, | ||
"Content" text NOT NULL, | ||
"BlogUrl" varchar(200) NULL, | ||
CONSTRAINT "PK_Post" PRIMARY KEY ("PostId"), | ||
CONSTRAINT "FK_Post_Blogs_BlogUrl" FOREIGN KEY ("BlogUrl") REFERENCES "Blogs" ("Url") | ||
); | ||
|
||
|
||
CREATE INDEX "IX_Post_BlogUrl" ON "Post" ("BlogUrl"); | ||
|
||
|
||
|
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 @@ | ||
CREATE TABLE "Blogs" ( | ||
"BlogId" INTEGER NOT NULL CONSTRAINT "PK_Blogs" PRIMARY KEY AUTOINCREMENT, | ||
"Url" varchar(200) NOT NULL, | ||
"Rating" decimal(5, 2) NOT NULL, | ||
"Title" TEXT NOT NULL, | ||
"Content" TEXT NOT NULL, | ||
"Author" TEXT NOT NULL DEFAULT 'Anonymous', | ||
CONSTRAINT "AK_Blogs_Url" UNIQUE ("Url") | ||
); | ||
|
||
|
||
CREATE TABLE "Post" ( | ||
"PostId" INTEGER NOT NULL CONSTRAINT "PK_Post" PRIMARY KEY AUTOINCREMENT, | ||
"Title" TEXT NOT NULL, | ||
"Content" TEXT NOT NULL, | ||
"BlogUrl" varchar(200) NULL, | ||
CONSTRAINT "FK_Post_Blogs_BlogUrl" FOREIGN KEY ("BlogUrl") REFERENCES "Blogs" ("Url") | ||
); | ||
|
||
|
||
CREATE INDEX "IX_Post_BlogUrl" ON "Post" ("BlogUrl"); | ||
|
||
|
||
|
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,30 @@ | ||
-- atlas:delimiter GO | ||
CREATE TABLE [Blogs] ( | ||
[BlogId] int NOT NULL IDENTITY, | ||
[Url] varchar(200) NOT NULL, | ||
[Rating] decimal(5,2) NOT NULL, | ||
[Title] nvarchar(max) NOT NULL, | ||
[Content] nvarchar(max) NOT NULL, | ||
[Author] nvarchar(200) NOT NULL DEFAULT N'Anonymous', | ||
CONSTRAINT [PK_Blogs] PRIMARY KEY ([BlogId]), | ||
CONSTRAINT [AK_Blogs_Url] UNIQUE ([Url]) | ||
); | ||
GO | ||
|
||
|
||
CREATE TABLE [Post] ( | ||
[PostId] int NOT NULL IDENTITY, | ||
[Title] nvarchar(max) NOT NULL, | ||
[Content] nvarchar(max) NOT NULL, | ||
[BlogUrl] varchar(200) NULL, | ||
CONSTRAINT [PK_Post] PRIMARY KEY ([PostId]), | ||
CONSTRAINT [FK_Post_Blogs_BlogUrl] FOREIGN KEY ([BlogUrl]) REFERENCES [Blogs] ([Url]) | ||
); | ||
GO | ||
|
||
|
||
CREATE INDEX [IX_Post_BlogUrl] ON [Post] ([BlogUrl]); | ||
GO | ||
|
||
|
||
|