BaseTestd
This commit is contained in:
42
src/Backend/DiunaBI.Tests/BaseTests.cs
Normal file
42
src/Backend/DiunaBI.Tests/BaseTests.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc.Testing;
|
||||||
|
using Xunit;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace DiunaBI.Tests;
|
||||||
|
|
||||||
|
public class ApiConnectionTests : IClassFixture<WebApplicationFactory<Program>>
|
||||||
|
{
|
||||||
|
private readonly WebApplicationFactory<Program> _factory;
|
||||||
|
|
||||||
|
public ApiConnectionTests(WebApplicationFactory<Program> factory)
|
||||||
|
{
|
||||||
|
_factory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task PingToApi()
|
||||||
|
{
|
||||||
|
var client = _factory.CreateClient();
|
||||||
|
|
||||||
|
var response = await client.GetAsync("/api/Ping/Ping");
|
||||||
|
var content = await response.Content.ReadAsStringAsync();
|
||||||
|
var statusCode = (int)response.StatusCode;
|
||||||
|
|
||||||
|
Assert.Equal(200, statusCode);
|
||||||
|
Assert.Equal("Pong", content);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task DatabaseConnectionTest()
|
||||||
|
{
|
||||||
|
var client = _factory.CreateClient();
|
||||||
|
|
||||||
|
var response = await client.GetAsync("/api/Layers?start=0&limit=1");
|
||||||
|
var content = await response.Content.ReadAsStringAsync();
|
||||||
|
var statusCode = (int)response.StatusCode;
|
||||||
|
|
||||||
|
Assert.Equal(200, statusCode);
|
||||||
|
var layers = JsonSerializer.Deserialize<dynamic>(content);
|
||||||
|
Assert.NotNull(layers);
|
||||||
|
}
|
||||||
|
}
|
||||||
24
src/Backend/DiunaBI.Tests/DiunaBI.Tests.csproj
Normal file
24
src/Backend/DiunaBI.Tests/DiunaBI.Tests.csproj
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||||
|
<PackageReference Include="xunit" Version="2.6.2" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\DiunaBI.WebAPI\DiunaBI.WebAPI.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -20,6 +20,6 @@ public class PingController : Controller
|
|||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public IActionResult Ping()
|
public IActionResult Ping()
|
||||||
{
|
{
|
||||||
return Ok(_configuration["PONG"]);
|
return Ok("Pong");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -160,3 +160,5 @@ if (app.Environment.IsProduction())
|
|||||||
{
|
{
|
||||||
Log.CloseAndFlush();
|
Log.CloseAndFlush();
|
||||||
}
|
}
|
||||||
|
// for testing purposes
|
||||||
|
public partial class Program { }
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.0.31903.59
|
VisualStudioVersion = 17.0.31903.59
|
||||||
@@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiunaBI.Core", "DiunaBI.Cor
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiunaBI.Plugins.Morska", "DiunaBI.Plugins.Morska\DiunaBI.Plugins.Morska.csproj", "{B5416A3F-550A-468D-852F-20B24243FD68}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiunaBI.Plugins.Morska", "DiunaBI.Plugins.Morska\DiunaBI.Plugins.Morska.csproj", "{B5416A3F-550A-468D-852F-20B24243FD68}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiunaBI.Tests", "DiunaBI.Tests\DiunaBI.Tests.csproj", "{7D99AF7E-1FC7-4EC0-A320-F1A81D396F93}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -34,5 +36,9 @@ Global
|
|||||||
{8C346BEA-A209-4E8F-A6BF-70B42D9106C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{8C346BEA-A209-4E8F-A6BF-70B42D9106C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{8C346BEA-A209-4E8F-A6BF-70B42D9106C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{8C346BEA-A209-4E8F-A6BF-70B42D9106C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{8C346BEA-A209-4E8F-A6BF-70B42D9106C8}.Release|Any CPU.Build.0 = Release|Any CPU
|
{8C346BEA-A209-4E8F-A6BF-70B42D9106C8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{7D99AF7E-1FC7-4EC0-A320-F1A81D396F93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{7D99AF7E-1FC7-4EC0-A320-F1A81D396F93}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{7D99AF7E-1FC7-4EC0-A320-F1A81D396F93}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{7D99AF7E-1FC7-4EC0-A320-F1A81D396F93}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
Reference in New Issue
Block a user