diff --git a/src/Backend/DiunaBI.Tests/BaseTests.cs b/src/Backend/DiunaBI.Tests/BaseTests.cs new file mode 100644 index 0000000..42e80eb --- /dev/null +++ b/src/Backend/DiunaBI.Tests/BaseTests.cs @@ -0,0 +1,42 @@ +using Microsoft.AspNetCore.Mvc.Testing; +using Xunit; +using System.Text.Json; + +namespace DiunaBI.Tests; + +public class ApiConnectionTests : IClassFixture> +{ + private readonly WebApplicationFactory _factory; + + public ApiConnectionTests(WebApplicationFactory 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(content); + Assert.NotNull(layers); + } +} \ No newline at end of file diff --git a/src/Backend/DiunaBI.Tests/DiunaBI.Tests.csproj b/src/Backend/DiunaBI.Tests/DiunaBI.Tests.csproj new file mode 100644 index 0000000..8c99a7d --- /dev/null +++ b/src/Backend/DiunaBI.Tests/DiunaBI.Tests.csproj @@ -0,0 +1,24 @@ + + + + net8.0 + enable + enable + false + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + \ No newline at end of file diff --git a/src/Backend/DiunaBI.WebAPI/Controllers/PingController.cs b/src/Backend/DiunaBI.WebAPI/Controllers/PingController.cs index 04193e3..19304c7 100644 --- a/src/Backend/DiunaBI.WebAPI/Controllers/PingController.cs +++ b/src/Backend/DiunaBI.WebAPI/Controllers/PingController.cs @@ -20,6 +20,6 @@ public class PingController : Controller [AllowAnonymous] public IActionResult Ping() { - return Ok(_configuration["PONG"]); + return Ok("Pong"); } } \ No newline at end of file diff --git a/src/Backend/DiunaBI.WebAPI/Program.cs b/src/Backend/DiunaBI.WebAPI/Program.cs index 440e6c5..2df0db6 100644 --- a/src/Backend/DiunaBI.WebAPI/Program.cs +++ b/src/Backend/DiunaBI.WebAPI/Program.cs @@ -159,4 +159,6 @@ app.Run(); if (app.Environment.IsProduction()) { Log.CloseAndFlush(); -} \ No newline at end of file +} +// for testing purposes +public partial class Program { } \ No newline at end of file diff --git a/src/Backend/DiunaBI.sln b/src/Backend/DiunaBI.sln index 7756af7..f97b921 100644 --- a/src/Backend/DiunaBI.sln +++ b/src/Backend/DiunaBI.sln @@ -1,4 +1,4 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31903.59 @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiunaBI.Core", "DiunaBI.Cor EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiunaBI.Plugins.Morska", "DiunaBI.Plugins.Morska\DiunaBI.Plugins.Morska.csproj", "{B5416A3F-550A-468D-852F-20B24243FD68}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiunaBI.Tests", "DiunaBI.Tests\DiunaBI.Tests.csproj", "{7D99AF7E-1FC7-4EC0-A320-F1A81D396F93}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution 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}.Release|Any CPU.ActiveCfg = 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 EndGlobal