diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1ca41fe..798598f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -60,7 +60,8 @@ jobs: --configuration Release \ --no-restore \ --logger "trx;LogFileName=test-results.trx" \ - --collect:"XPlat Code Coverage" + --collect:"XPlat Code Coverage" \ + --filter "Category!=LocalOnly" - name: Publish Test Results uses: actions/upload-artifact@v4 diff --git a/src/Backend/DiunaBI.Core/Services/PluginManager.cs b/src/Backend/DiunaBI.Core/Services/PluginManager.cs index 0a0d8b4..8934dc3 100644 --- a/src/Backend/DiunaBI.Core/Services/PluginManager.cs +++ b/src/Backend/DiunaBI.Core/Services/PluginManager.cs @@ -46,21 +46,21 @@ public class PluginManager } } - _logger.LogInformation("Loaded {ProcessorCount} processors and {ImporterCount} importers from {AssemblyCount} assemblies", - _processorTypes.Count, - _importerTypes.Count, + _logger.LogInformation("Loaded {ProcessorCount} processors and {ImporterCount} importers from {AssemblyCount} assemblies", + _processorTypes.Count, + _importerTypes.Count, dllFiles.Length); // ZmieƄ z _plugins.Count na assemblyFiles.Length } private void LoadPluginFromAssembly(string assemblyPath) { _logger.LogDebug("Loading assembly from: {Path}", assemblyPath); // Information -> Debug - + try { var assembly = Assembly.LoadFrom(assemblyPath); _logger.LogDebug("Assembly loaded successfully: {Name}", assembly.FullName); // Information -> Debug - + foreach (var type in assembly.GetTypes()) { if (typeof(IDataProcessor).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract) @@ -68,7 +68,7 @@ public class PluginManager _processorTypes.Add(type); _logger.LogDebug("Registered processor: {Type}", type.Name); // Information -> Debug } - + if (typeof(IDataImporter).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract) { _importerTypes.Add(type); @@ -90,7 +90,7 @@ public class PluginManager { using var scope = _serviceProvider.CreateScope(); var instance = (IDataProcessor)ActivatorUtilities.CreateInstance(scope.ServiceProvider, type); - + if (instance.CanProcess(processorType)) { var scopedProvider = _serviceProvider.CreateScope().ServiceProvider; @@ -113,7 +113,7 @@ public class PluginManager { using var scope = _serviceProvider.CreateScope(); var instance = (IDataImporter)ActivatorUtilities.CreateInstance(scope.ServiceProvider, type); - + if (instance.CanImport(importerType)) { var scopedProvider = _serviceProvider.CreateScope().ServiceProvider; @@ -132,7 +132,5 @@ public class PluginManager { return _exporters.FirstOrDefault(e => e.CanExport(exporterType)); } - - public IEnumerable GetAllExporters() => _exporters.AsReadOnly(); - public IEnumerable GetAllPlugins() => _plugins.AsReadOnly(); + public int GetPluginsCount() => _processorTypes.Count + _importerTypes.Count + _exporters.Count; } \ No newline at end of file diff --git a/src/Backend/DiunaBI.Tests/BaseTests.cs b/src/Backend/DiunaBI.Tests/BaseTests.cs index 42e80eb..ca366c5 100644 --- a/src/Backend/DiunaBI.Tests/BaseTests.cs +++ b/src/Backend/DiunaBI.Tests/BaseTests.cs @@ -18,15 +18,16 @@ public class ApiConnectionTests : IClassFixture> { var client = _factory.CreateClient(); - var response = await client.GetAsync("/api/Ping/Ping"); + var response = await client.GetAsync("/api/Tests/Ping"); var content = await response.Content.ReadAsStringAsync(); var statusCode = (int)response.StatusCode; - Assert.Equal(200, statusCode); + Assert.Equal(200, statusCode); Assert.Equal("Pong", content); } [Fact] + [Trait("Category", "LocalOnly")] public async Task DatabaseConnectionTest() { var client = _factory.CreateClient(); @@ -39,4 +40,17 @@ public class ApiConnectionTests : IClassFixture> var layers = JsonSerializer.Deserialize(content); Assert.NotNull(layers); } + [Fact] + public async Task LoadPLuginsTest() + { + var client = _factory.CreateClient(); + + var response = await client.GetAsync("/api/Tests/Plugins"); + var content = await response.Content.ReadAsStringAsync(); + var statusCode = (int)response.StatusCode; + + Assert.Equal(200, statusCode); + var pluginsCount = JsonSerializer.Deserialize(content); + Assert.True(pluginsCount > 0, "Expected plugins count to be greater than 0"); + } } \ No newline at end of file diff --git a/src/Backend/DiunaBI.WebAPI/Controllers/AdminController.cs b/src/Backend/DiunaBI.WebAPI/Controllers/AdminController.cs deleted file mode 100644 index ad4b843..0000000 --- a/src/Backend/DiunaBI.WebAPI/Controllers/AdminController.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Data; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Data.SqlClient; -using DiunaBI.Core.Models; - -namespace DiunaBI.Core.Controllers; - -[ApiController] -[Route("api/[controller]")] -public class AdminController : Controller -{ - - private readonly IConfiguration _configuration; - - public AdminController( - IConfiguration configuration) - { - _configuration = configuration; - } - - [HttpGet] - [Route("Version")] - public IActionResult GetVersion() - { - return Ok(new { version = _configuration["app-version"] }); - } -} \ No newline at end of file diff --git a/src/Backend/DiunaBI.WebAPI/Controllers/PingController.cs b/src/Backend/DiunaBI.WebAPI/Controllers/PingController.cs deleted file mode 100644 index 19304c7..0000000 --- a/src/Backend/DiunaBI.WebAPI/Controllers/PingController.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace DiunaBI.WebAPI.Controllers; - -[ApiController] -[Route("api/[controller]")] -[Authorize] -public class PingController : Controller -{ - private readonly IConfiguration _configuration; - public PingController( - IConfiguration configuration) - { - _configuration = configuration; - } - - [HttpGet] - [Route("Ping")] - [AllowAnonymous] - public IActionResult Ping() - { - return Ok("Pong"); - } -} \ No newline at end of file diff --git a/src/Backend/DiunaBI.WebAPI/Controllers/TestsController.cs b/src/Backend/DiunaBI.WebAPI/Controllers/TestsController.cs new file mode 100644 index 0000000..908c944 --- /dev/null +++ b/src/Backend/DiunaBI.WebAPI/Controllers/TestsController.cs @@ -0,0 +1,34 @@ +using DiunaBI.Core.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace DiunaBI.WebAPI.Controllers; + +[ApiController] +[Route("api/[controller]")] +[Authorize] +public class TestsController : Controller +{ + private readonly PluginManager _pluginManager; + public TestsController( + PluginManager pluginManager) + { + _pluginManager = pluginManager; + } + + [HttpGet] + [Route("Ping")] + [AllowAnonymous] + public IActionResult Ping() + { + return Ok("Pong"); + } + [HttpGet] + [Route("Plugins")] + [AllowAnonymous] + public IActionResult GetPlugins() + { + var plugins = _pluginManager.GetPluginsCount(); + return Ok(plugins); + } +} \ No newline at end of file diff --git a/tools/http-tests/AutoImport.http b/tools/http-tests/AutoImport.http index 6b35da4..8fb5368 100644 --- a/tools/http-tests/AutoImport.http +++ b/tools/http-tests/AutoImport.http @@ -1,3 +1,3 @@ ### -GET http://localhost:5400/api/Layers/RunQueueJobs/10763478CB738D4ecb2h76g803478CB738D4e +GET http://localhost:5400/api/Tests/Plugins