-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from ose-net/docs/issue-82
docs: Add samples on how to use YeSql library
- Loading branch information
Showing
33 changed files
with
539 additions
and
70 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
26 changes: 26 additions & 0 deletions
26
samples/Example.AspNetCore.Tests/Example.AspNetCore.Tests.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,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" /> | ||
<PackageReference Include="FluentAssertions" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
<PackageReference Include="NUnit" /> | ||
<PackageReference Include="NUnit3TestAdapter" /> | ||
<PackageReference Include="NUnit.Analyzers" /> | ||
<PackageReference Include="coverlet.msbuild"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Example.AspNetCore\Example.AspNetCore.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,4 @@ | ||
global using NUnit.Framework; | ||
global using FluentAssertions; | ||
global using Microsoft.AspNetCore.Mvc.Testing; | ||
global using System.Net; |
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,31 @@ | ||
namespace Example.AspNetCore.Tests; | ||
|
||
public class SqlTests | ||
{ | ||
[TestCase("/api/Sql/GetUsersSql", "SELECT* FROM [user];")] | ||
[TestCase("/api/Sql/GetRolesSql", "SELECT* FROM [role];")] | ||
[TestCase("/api/Sql/GetProductsSql", "SELECT* FROM [product];")] | ||
[TestCase("/api/Sql/GetCustomersSql", "SELECT* FROM [customer];")] | ||
[TestCase("/api/Sql/GetOrdersSql", "SELECT* FROM [order];")] | ||
[TestCase("/api/Sql/GetPermissionsSql", "SELECT* FROM [permission];")] | ||
[TestCase("/api/Sql/GetThirdPartiesSql", "SELECT* FROM [third_party];")] | ||
public async Task Get_WhenSqlCodeIsRetrieved_ShouldReturnsHttpStatusCodeOk( | ||
string requestUri, | ||
string expectedSql) | ||
{ | ||
// Arrange | ||
using var factory = new WebApplicationFactory<Program>(); | ||
var client = factory.CreateClient(); | ||
|
||
// Act | ||
var httpResponse = await client.GetAsync(requestUri); | ||
var result = (await httpResponse | ||
.Content | ||
.ReadAsStringAsync()) | ||
.TrimEnd(Environment.NewLine.ToCharArray()); | ||
|
||
// Asserts | ||
httpResponse.StatusCode.Should().Be(HttpStatusCode.OK); | ||
result.Should().Be(expectedSql); | ||
} | ||
} |
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,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
|
||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\YeSql.Net.csproj" /> | ||
<ProjectReference Include="..\Example.Reports\Example.Reports.csproj" /> | ||
<ProjectReference Include="..\Example.SqlFiles\Example.SqlFiles.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CopySqlFilesToOutputDirectory" /> | ||
<PackageReference Include="CopySqlFilesToPublishDirectory" /> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" /> | ||
</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,32 @@ | ||
using YeSql.Net; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
|
||
var sqlStatements = new YeSqlLoader().Load(); | ||
builder.Services.AddSingleton(sqlStatements); | ||
builder.Services.AddControllers(); | ||
|
||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.MapControllers(); | ||
|
||
app.Run(); | ||
|
||
public partial class Program { } |
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,41 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:8839", | ||
"sslPort": 44331 | ||
} | ||
}, | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "http://localhost:5194", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "https://localhost:7068;http://localhost:5194", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
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 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using YeSql.Net; | ||
|
||
namespace Example.AspNetCore; | ||
|
||
[ApiController] | ||
[Route("api/[controller]")] | ||
public class SqlController : ControllerBase | ||
{ | ||
private readonly IYeSqlCollection _sqlCollection; | ||
public SqlController(IYeSqlCollection sqlCollection) => _sqlCollection = sqlCollection; | ||
|
||
[HttpGet("GetUsersSql")] | ||
public string GetUsersSql() | ||
=> _sqlCollection["GetUsers"]; | ||
|
||
[HttpGet("GetRolesSql")] | ||
public string GetRolesSql() | ||
=> _sqlCollection["GetRoles"]; | ||
|
||
[HttpGet("GetProductsSql")] | ||
public string GetProductsSql() | ||
=> _sqlCollection["GetProducts"]; | ||
|
||
[HttpGet("GetCustomersSql")] | ||
public string GetCustomersSql() | ||
=> _sqlCollection["GetCustomers"]; | ||
|
||
[HttpGet("GetOrdersSql")] | ||
public string GetOrdersSql() | ||
=> _sqlCollection["GetOrders"]; | ||
|
||
[HttpGet("GetPermissionsSql")] | ||
public string GetPermissionsSql() | ||
=> _sqlCollection["GetPermissions"]; | ||
|
||
[HttpGet("GetThirdPartiesSql")] | ||
public string GetThirdPartiesSql() | ||
=> _sqlCollection["GetThirdParties"]; | ||
} |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
samples/LoaderSample/sql/sample.sql → samples/Example.AspNetCore/sql/sample.sql
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
-- name: GetProducts | ||
-- Gets a list of products. | ||
SELECT* FROM product; | ||
SELECT* FROM [product]; | ||
-- End. |
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,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\YeSql.Net.csproj" /> | ||
<ProjectReference Include="..\Example.SqlFiles\Example.SqlFiles.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CopySqlFilesToOutputDirectory" /> | ||
<PackageReference Include="CopySqlFilesToPublishDirectory" /> | ||
</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,10 @@ | ||
using YeSql.Net; | ||
|
||
var sqlStatements = new YeSqlLoader().Load(); | ||
Console.Write(sqlStatements["GetUsers"]); | ||
Console.Write(sqlStatements["GetRoles"]); | ||
Console.Write(sqlStatements["GetProducts"]); | ||
Console.Write(sqlStatements["GetCustomers"]); | ||
Console.Write(sqlStatements["GetOrders"]); | ||
Console.Write(sqlStatements["GetPermissions"]); | ||
Console.Write(sqlStatements["GetThirdParties"]); |
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,7 @@ | ||
-- name: GetUsers | ||
-- Gets user records. | ||
SELECT* FROM [user]; | ||
|
||
-- name: GetRoles | ||
-- Gets role records. | ||
SELECT* FROM [role]; |
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,4 @@ | ||
-- name: GetProducts | ||
-- Gets a list of products. | ||
SELECT* FROM [product]; | ||
-- End. |
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8.1" /> | ||
</startup> | ||
</configuration> |
Oops, something went wrong.