From d95d3f9687d4e28fa767d15576a20bad4d3ab2e0 Mon Sep 17 00:00:00 2001 From: Jason Barden Date: Sat, 2 Aug 2025 01:00:21 +0100 Subject: [PATCH 1/4] Remove unused controllers and refactor records --- .../MultiProjectResultsController.cs | 33 ------------------- .../Controllers/TestResultsController.cs | 26 --------------- .../Models/TestResult.cs | 22 ++++++------- .../Program.cs | 25 -------------- .../Shared/Dtos/TestResultDto.cs | 14 ++++---- .../TestCoverage/TestResultsEndpoint.cs | 1 - .../TrxParser.cs | 22 +++++++------ .../Components/Pages/Dashboard.razor.cs | 4 +-- .../Components/ThemeToggle.razor | 2 +- .../Models/TestResult.cs | 22 ++++++------- src/AStar.Dev.Testing.Dashboard/Program.cs | 1 - .../Services/TestResultsService.cs | 6 ++-- 12 files changed, 45 insertions(+), 133 deletions(-) delete mode 100644 src/AStar.Dev.Testing.Dashboard.Server/Controllers/MultiProjectResultsController.cs delete mode 100644 src/AStar.Dev.Testing.Dashboard.Server/Controllers/TestResultsController.cs rename src/AStar.Dev.Testing.Dashboard.Server/{Controllers => TestCoverage}/TrxParser.cs (54%) diff --git a/src/AStar.Dev.Testing.Dashboard.Server/Controllers/MultiProjectResultsController.cs b/src/AStar.Dev.Testing.Dashboard.Server/Controllers/MultiProjectResultsController.cs deleted file mode 100644 index bed572e..0000000 --- a/src/AStar.Dev.Testing.Dashboard.Server/Controllers/MultiProjectResultsController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using AStar.Dev.Testing.Dashboard.Server.Models; -using Microsoft.AspNetCore.Mvc; - -namespace AStar.Dev.Testing.Dashboard.Server.Controllers; - -[ApiController] -[Route("api/[controller]")] -public class MultiProjectResultsController : ControllerBase -{ - [HttpGet] - public ActionResult> GetTrxResults() - { - var rootPath = Path.Combine(Directory.GetCurrentDirectory(), "../../test"); - var allResults = new List(); - - var directories = Directory.GetDirectories(rootPath); - - foreach (var dir in directories) - { - var filePath = Path.Combine(dir, "TestResults", "results.trx"); - - if (!System.IO.File.Exists(filePath)) - { - continue; - } - - var results = TrxParser.ParseTrx(filePath); - allResults.AddRange(results); - } - - return Ok(allResults); - } -} diff --git a/src/AStar.Dev.Testing.Dashboard.Server/Controllers/TestResultsController.cs b/src/AStar.Dev.Testing.Dashboard.Server/Controllers/TestResultsController.cs deleted file mode 100644 index 9aed15d..0000000 --- a/src/AStar.Dev.Testing.Dashboard.Server/Controllers/TestResultsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Text.Json; -using AStar.Dev.Testing.Dashboard.Server.Models; -using Microsoft.AspNetCore.Mvc; - -namespace AStar.Dev.Testing.Dashboard.Server.Controllers; - -[ApiController] -[Route("api/[controller]")] -public class TestResultsController : ControllerBase -{ - [HttpGet] - public async Task>> GetAsync() - { - var filePath = Path.Combine("Data", "test-results.json"); - - if (!System.IO.File.Exists(filePath)) - { - return NotFound("Test result file not found."); - } - - var json = await System.IO.File.ReadAllTextAsync(filePath); - var results = JsonSerializer.Deserialize>(json, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); - - return Ok(results); - } -} diff --git a/src/AStar.Dev.Testing.Dashboard.Server/Models/TestResult.cs b/src/AStar.Dev.Testing.Dashboard.Server/Models/TestResult.cs index 4463ffc..800a44b 100644 --- a/src/AStar.Dev.Testing.Dashboard.Server/Models/TestResult.cs +++ b/src/AStar.Dev.Testing.Dashboard.Server/Models/TestResult.cs @@ -1,14 +1,12 @@ namespace AStar.Dev.Testing.Dashboard.Server.Models; -public class TestResult -{ - public string Name { get; set; } - public string Outcome { get; set; } // Passed, Failed, Skipped - public string Duration { get; set; } - public string Category { get; set; } - public string ErrorMessage { get; set; } - public DateTime Timestamp { get; set; } - public string? StartTime { get ; set ; } - public string? EndTime { get ; set ; } - public string ProjectName { get ; set ; } -} +public record TestResult( + string Name , + string Outcome , + string Duration , + string? Category , + string? ErrorMessage , + string? StartTime , + string? EndTime , + string ProjectName +); diff --git a/src/AStar.Dev.Testing.Dashboard.Server/Program.cs b/src/AStar.Dev.Testing.Dashboard.Server/Program.cs index 1c75626..d04f942 100644 --- a/src/AStar.Dev.Testing.Dashboard.Server/Program.cs +++ b/src/AStar.Dev.Testing.Dashboard.Server/Program.cs @@ -1,4 +1,3 @@ -using AStar.Dev.Testing.Dashboard.Server; using AStar.Dev.Testing.Dashboard.Server.TestCoverage; var builder = WebApplication.CreateBuilder(args); @@ -31,32 +30,8 @@ app.MapControllers(); app.UseHttpsRedirection(); -var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; - -app.MapGet("/weatherforecast", () => - { - var forecast = Enumerable.Range(1, 5).Select(index => new WeatherForecast - ( - DateOnly.FromDateTime(DateTime.Now.AddDays(index)), - Random.Shared.Next(-20, 55), - summaries[Random.Shared.Next(summaries.Length)] - )) - .ToArray(); - - return forecast; - }) - .WithName("GetWeatherForecast"); - app.MapCodeCoverageEndpoints() .MapTestResultsEndpoint() .UseCors(); await app.RunAsync(); - -namespace AStar.Dev.Testing.Dashboard.Server -{ - internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary) - { - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - } -} diff --git a/src/AStar.Dev.Testing.Dashboard.Server/Shared/Dtos/TestResultDto.cs b/src/AStar.Dev.Testing.Dashboard.Server/Shared/Dtos/TestResultDto.cs index d634cd0..e7f5cf6 100644 --- a/src/AStar.Dev.Testing.Dashboard.Server/Shared/Dtos/TestResultDto.cs +++ b/src/AStar.Dev.Testing.Dashboard.Server/Shared/Dtos/TestResultDto.cs @@ -1,8 +1,8 @@ namespace AStar.Dev.Testing.Dashboard.Server.Shared.Dtos; -public class TestResultDto +public record TestResultDto { - public string Name { get; set; } + public required string Name { get; set; } public string StatusIcon => Outcome switch { @@ -12,9 +12,9 @@ public class TestResultDto _ => "help" }; - public string Outcome { get; set; } - public double DurationMs { get; set; } - public string Category { get; set; } - public string Message { get; set; } - public DateTime Timestamp { get; set; } + public required string Outcome { get; set; } + public double DurationMs { get; set; } + public required string Category { get; set; } + public required string Message { get; set; } + public DateTime Timestamp { get; set; } } diff --git a/src/AStar.Dev.Testing.Dashboard.Server/TestCoverage/TestResultsEndpoint.cs b/src/AStar.Dev.Testing.Dashboard.Server/TestCoverage/TestResultsEndpoint.cs index 9d80219..80ef1af 100644 --- a/src/AStar.Dev.Testing.Dashboard.Server/TestCoverage/TestResultsEndpoint.cs +++ b/src/AStar.Dev.Testing.Dashboard.Server/TestCoverage/TestResultsEndpoint.cs @@ -1,4 +1,3 @@ -using AStar.Dev.Testing.Dashboard.Server.Controllers; using AStar.Dev.Testing.Dashboard.Server.Models; namespace AStar.Dev.Testing.Dashboard.Server.TestCoverage; diff --git a/src/AStar.Dev.Testing.Dashboard.Server/Controllers/TrxParser.cs b/src/AStar.Dev.Testing.Dashboard.Server/TestCoverage/TrxParser.cs similarity index 54% rename from src/AStar.Dev.Testing.Dashboard.Server/Controllers/TrxParser.cs rename to src/AStar.Dev.Testing.Dashboard.Server/TestCoverage/TrxParser.cs index e768e3e..24e5fda 100644 --- a/src/AStar.Dev.Testing.Dashboard.Server/Controllers/TrxParser.cs +++ b/src/AStar.Dev.Testing.Dashboard.Server/TestCoverage/TrxParser.cs @@ -1,7 +1,7 @@ using System.Xml.Linq; using AStar.Dev.Testing.Dashboard.Server.Models; -namespace AStar.Dev.Testing.Dashboard.Server.Controllers; +namespace AStar.Dev.Testing.Dashboard.Server.TestCoverage; public static class TrxParser { @@ -14,18 +14,20 @@ public static List ParseTrx(string filePath) const string secondSearchString = ".Tests.Unit/TestResults/results.trx"; var index = filePath.LastIndexOf(initialSearchString, StringComparison.Ordinal) + initialSearchString.Length; var index2 = filePath.LastIndexOf(secondSearchString, StringComparison.Ordinal) - index; - var root = filePath.Substring(index, index2); + var projectName = filePath.Substring(index, index2); var results = doc.Descendants(ns + "UnitTestResult") .Select(x => new TestResult - { - ProjectName = root, - Name = x.Attribute("testName")?.Value, - Outcome = x.Attribute("outcome")?.Value, - Duration = x.Attribute("duration")?.Value, - StartTime = x.Attribute("startTime")?.Value, - EndTime = x.Attribute("endTime")?.Value - }) + ( + x.Attribute("testName")?.Value!, + x.Attribute("outcome")?.Value!, + x.Attribute("duration")?.Value!, + x.Attribute("startTime")?.Value, + x.Attribute("endTime")?.Value, + x.Attribute("errorMessage")?.Value, + x.Attribute("testType")?.Value, + projectName + )) .ToList(); return results; diff --git a/src/AStar.Dev.Testing.Dashboard/Components/Pages/Dashboard.razor.cs b/src/AStar.Dev.Testing.Dashboard/Components/Pages/Dashboard.razor.cs index 056d61e..f57ffaa 100644 --- a/src/AStar.Dev.Testing.Dashboard/Components/Pages/Dashboard.razor.cs +++ b/src/AStar.Dev.Testing.Dashboard/Components/Pages/Dashboard.razor.cs @@ -1,5 +1,5 @@ -using AStar.Dev.Test.Dashboard.Ui.Models; -using AStar.Dev.Test.Dashboard.Ui.Services; +using AStar.Dev.Testing.Dashboard.Models; +using AStar.Dev.Testing.Dashboard.Services; using Microsoft.AspNetCore.Components; namespace AStar.Dev.Testing.Dashboard.Components.Pages; diff --git a/src/AStar.Dev.Testing.Dashboard/Components/ThemeToggle.razor b/src/AStar.Dev.Testing.Dashboard/Components/ThemeToggle.razor index 4fb2361..10578b5 100644 --- a/src/AStar.Dev.Testing.Dashboard/Components/ThemeToggle.razor +++ b/src/AStar.Dev.Testing.Dashboard/Components/ThemeToggle.razor @@ -1,7 +1,7 @@ @using AStar.Dev.Testing.Dashboard.Services @namespace AStar.Dev.Testing.Dashboard.Components @inject ThemeService ThemeService -@inject IJSRuntime JsRuntime +@inject IJSRuntime JsRuntime