From a427c5648a673c7908273f9e16fb8f1d0c36723c Mon Sep 17 00:00:00 2001 From: "phares@iscn5cg20977xq" Date: Tue, 29 Jul 2025 16:56:09 -0700 Subject: [PATCH] - Include root in valid directories - AppSetting bug fix - Updated testes with base test class and editor configuration changes - Created new server and wafer counter tasks json files and pipelines to match --- .editorconfig | 3 +- .gitignore | 2 +- .vscode/launch.json | 6 +- .vscode/tasks.json | 52 +-- Archive/.vscode/tasks.json | 8 +- Server/.vscode/launch.json | 2 +- Server/.vscode/mklink.md | 5 + Server/.vscode/tasks.json | 411 +++++++++++++---- .../ApiControllers/AppSettingsController.cs | 5 +- Server/Models/AppSettings.cs | 70 ++- Server/Models/Binder/.editorconfig | 2 - Server/Models/Binder/AppSettings.cs | 148 ------- Server/Program.cs | 4 +- Server/Repositories/AppSettingsRepository.cs | 19 +- Server/server-pipeline.yml | 158 +++++++ .../Stateless/IAzureDevOpsController.cs | 16 - .../Stateless/IAzureDevOpsRepository.cs | 8 - Shared/OI.Metrology.Shared.csproj | 2 +- Tests/.vscode/mklink.md | 6 + Tests/.vscode/settings.json | 20 +- Tests/.vscode/tasks.json | 47 +- Tests/.vscode/tc_col_metrology-viewer-v3.http | 3 + Tests/BaseTestClass.cs | 21 + Tests/Settings.xml | 9 + Tests/UnitAwaitingDispoController.cs | 49 ++- Tests/UnitInboundController.cs | 22 +- Tests/UnitTestAppSettingsController.cs | 57 ++- Tests/UnitTestClientSettingsController.cs | 57 ++- Tests/UnitTestExportController.cs | 79 ++-- Tests/UnitTestFileShareController.cs | 53 ++- ...stISpreadingResistanceProfileController.cs | 20 +- Tests/UnitTestInfinityQSController.cs | 65 +-- Tests/UnitTestInfinityQSV2Controller.cs | 55 ++- Tests/UnitTestInfinityQSV3Controller.cs | 70 +-- Tests/UnitTestInfinityQSV4Controller.cs | 78 ++-- Tests/UnitTestOpenInsightV1Controller.cs | 20 +- Tests/UnitTestPinController.cs | 25 +- Tests/UnitTestServiceShopOrderController.cs | 37 +- Tests/UnitTestToolTypesController.cs | 113 ++--- Tests/UnitTestWaferCounterController.cs | 22 +- Wafer-Counter/.vscode/launch.json | 2 +- Wafer-Counter/.vscode/tasks.json | 416 ++++++++++++++---- .../ApiControllers/AzureDevOpsController.cs | 26 -- Wafer-Counter/Helper/ParameterHelper.cs | 15 +- Wafer-Counter/Models/AppSettings.cs | 8 +- Wafer-Counter/Program.cs | 1 - .../Repositories/AzureDevOpsRepository.cs | 25 -- .../Repositories/FileShareRepository.cs | 2 +- Wafer-Counter/wafer-counter-pipeline.yml | 158 +++++++ 49 files changed, 1680 insertions(+), 822 deletions(-) create mode 100644 Server/.vscode/mklink.md delete mode 100644 Server/Models/Binder/.editorconfig delete mode 100644 Server/Models/Binder/AppSettings.cs create mode 100644 Server/server-pipeline.yml delete mode 100644 Shared/Models/Stateless/IAzureDevOpsController.cs delete mode 100644 Shared/Models/Stateless/IAzureDevOpsRepository.cs create mode 100644 Tests/.vscode/mklink.md create mode 100644 Tests/BaseTestClass.cs create mode 100644 Tests/Settings.xml delete mode 100644 Wafer-Counter/ApiControllers/AzureDevOpsController.cs delete mode 100644 Wafer-Counter/Repositories/AzureDevOpsRepository.cs create mode 100644 Wafer-Counter/wafer-counter-pipeline.yml diff --git a/.editorconfig b/.editorconfig index 9198eff..934f2a6 100644 --- a/.editorconfig +++ b/.editorconfig @@ -105,7 +105,7 @@ dotnet_diagnostic.CS8936.severity = error # Feature 'collection expressions' is dotnet_diagnostic.IDE0001.severity = warning # IDE0001: Simplify name dotnet_diagnostic.IDE0002.severity = warning # Simplify (member access) - System.Version.Equals("1", "2"); Version.Equals("1", "2"); dotnet_diagnostic.IDE0004.severity = warning # IDE0004: Cast is redundant. -dotnet_diagnostic.IDE0005.severity = warning # Using directive is unnecessary +dotnet_diagnostic.IDE0005.severity = none # Using directive is unnecessary dotnet_diagnostic.IDE0028.severity = none # IDE0028: Collection initialization can be simplified dotnet_diagnostic.IDE0031.severity = warning # Use null propagation (IDE0031) dotnet_diagnostic.IDE0047.severity = warning # IDE0047: Parentheses can be removed @@ -115,6 +115,7 @@ dotnet_diagnostic.IDE0290.severity = none # Use primary constructor [Distance]cs dotnet_diagnostic.IDE0300.severity = none # IDE0300: Collection initialization can be simplified dotnet_diagnostic.IDE0301.severity = none #IDE0301: Collection initialization can be simplified dotnet_diagnostic.IDE0305.severity = none # IDE0305: Collection initialization can be simplified +dotnet_diagnostic.MSTEST0015.severity = none # MSTEST0015: Test method {method} should not be ignored dotnet_naming_rule.abstract_method_should_be_pascal_case.severity = warning dotnet_naming_rule.abstract_method_should_be_pascal_case.style = pascal_case dotnet_naming_rule.abstract_method_should_be_pascal_case.symbols = abstract_method diff --git a/.gitignore b/.gitignore index 7b6966c..d0154e0 100644 --- a/.gitignore +++ b/.gitignore @@ -345,4 +345,4 @@ ASALocalRun/ .kanbn Tests/.kanbn -/Wafer-Counter/.vscode/.UserSecrets/secrets.json \ No newline at end of file +secrets.json \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 53ef191..0bcf67e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "name": ".NET Core Launch (web) - Server", "type": "coreclr", "request": "launch", - "preLaunchTask": "buildServer", + "preLaunchTask": "Build Server", // If you have changed target frameworks, make sure to update the program path. "program": "${workspaceFolder}/Server/bin/Debug/net8.0/win-x64/OI.Metrology.Server.dll", "args": [], @@ -31,7 +31,7 @@ "name": ".NET Core Attach - Server", "type": "coreclr", "request": "attach", - "preLaunchTask": "watchServer", + "preLaunchTask": "Watch Server", "processName": "OI.Metrology.Server.exe" }, { @@ -41,7 +41,7 @@ "name": ".NET Core Launch (web) - ClientHub", "type": "coreclr", "request": "launch", - "preLaunchTask": "buildClientHub", + "preLaunchTask": "Build Client Hub", // If you have changed target frameworks, make sure to update the program path. "program": "${workspaceFolder}/ClientHub/bin/Debug/net7.0/win-x64/OI.Metrology.ClientHub.dll", "args": [], diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 6cd5c22..28af0a5 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -28,72 +28,60 @@ "problemMatcher": "$msCompile" }, { - "label": "buildServer", + "label": "Build Server", "command": "dotnet", "type": "process", "args": [ "build", - "${workspaceFolder}/Server/OI.Metrology.Server.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" + "${workspaceFolder}/Server/OI.Metrology.Server.csproj" ], "problemMatcher": "$msCompile" }, { - "label": "buildTests", + "label": "Build Tests", "command": "dotnet", "type": "process", "args": [ "build", - "${workspaceFolder}/Tests/OI.Metrology.Tests.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" + "${workspaceFolder}/Tests/OI.Metrology.Tests.csproj" ], "problemMatcher": "$msCompile" }, { - "label": "buildShared", + "label": "Build Shared", "command": "dotnet", "type": "process", "args": [ "build", - "${workspaceFolder}/Shared/OI.Metrology.Shared.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" + "${workspaceFolder}/Shared/OI.Metrology.Shared.csproj" ], "problemMatcher": "$msCompile" }, { - "label": "publishServer", + "label": "Publish Server", "command": "dotnet", "type": "process", "args": [ "publish", - "${workspaceFolder}/Server/OI.Metrology.Server.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" + "${workspaceFolder}/Server/OI.Metrology.Server.csproj" ], "problemMatcher": "$msCompile" }, { - "label": "testDebug", + "label": "Test Debug", "command": "dotnet", "type": "process", "args": [ - "test", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" + "test" ], "problemMatcher": "$msCompile" }, { - "label": "testRelease", + "label": "Test Release", "command": "dotnet", "type": "process", "args": [ "test", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary", "-c", "Release" ], @@ -115,7 +103,7 @@ "problemMatcher": "$msCompile" }, { - "label": "old-watch", + "label": "Old Watch", "command": "dotnet", "type": "process", "args": [ @@ -127,7 +115,7 @@ "problemMatcher": "$msCompile" }, { - "label": "watchServer", + "label": "Watch Server", "command": "dotnet", "type": "process", "args": [ @@ -161,31 +149,27 @@ } }, { - "label": "buildClientHub", + "label": "Build Client Hub", "command": "dotnet", "type": "process", "args": [ "build", - "${workspaceFolder}/ClientHub/OI.Metrology.ClientHub.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" + "${workspaceFolder}/ClientHub/OI.Metrology.ClientHub.csproj" ], "problemMatcher": "$msCompile" }, { - "label": "publishClientHub", + "label": "Publish Client Hub", "command": "dotnet", "type": "process", "args": [ "publish", - "${workspaceFolder}/ClientHub/OI.Metrology.ClientHub.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" + "${workspaceFolder}/ClientHub/OI.Metrology.ClientHub.csproj" ], "problemMatcher": "$msCompile" }, { - "label": "watchClientHub", + "label": "Watch Client Hub", "command": "dotnet", "type": "process", "args": [ diff --git a/Archive/.vscode/tasks.json b/Archive/.vscode/tasks.json index ecc8e45..4764103 100644 --- a/Archive/.vscode/tasks.json +++ b/Archive/.vscode/tasks.json @@ -7,9 +7,7 @@ "type": "process", "args": [ "build", - "${workspaceFolder}/Archive.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" + "${workspaceFolder}/Archive.csproj" ], "problemMatcher": "$msCompile" }, @@ -19,9 +17,7 @@ "type": "process", "args": [ "publish", - "${workspaceFolder}/Archive.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" + "${workspaceFolder}/Archive.csproj" ], "problemMatcher": "$msCompile" }, diff --git a/Server/.vscode/launch.json b/Server/.vscode/launch.json index 485debc..a899ab7 100644 --- a/Server/.vscode/launch.json +++ b/Server/.vscode/launch.json @@ -8,7 +8,7 @@ "name": ".NET Core Launch (web)", "type": "coreclr", "request": "launch", - "preLaunchTask": "build", + "preLaunchTask": "Build", // If you have changed target frameworks, make sure to update the program path. "program": "${workspaceFolder}/bin/Debug/net8.0/OI.Metrology.Server.dll", "args": [], diff --git a/Server/.vscode/mklink.md b/Server/.vscode/mklink.md new file mode 100644 index 0000000..f923158 --- /dev/null +++ b/Server/.vscode/mklink.md @@ -0,0 +1,5 @@ +# mklink + +```bash Thu Aug 29 2024 09:47:22 GMT-0700 (Mountain Standard Time) +mklink /J "L:\DevOps\OpenInsight-Metrology-Viewer\OI-Metrology\Server\.vscode\.UserSecrets" "C:\Users\phares\AppData\Roaming\Microsoft\UserSecrets\b0a3891c-b775-422c-80ee-63a2f385045d" +``` \ No newline at end of file diff --git a/Server/.vscode/tasks.json b/Server/.vscode/tasks.json index 535c86d..859d994 100644 --- a/Server/.vscode/tasks.json +++ b/Server/.vscode/tasks.json @@ -1,60 +1,158 @@ { - "version": "2.0.0", + "inputs": [ + { + "default": "Development", + "description": "Which ASP Net Core Environment?", + "id": "ASPNETCORE_ENVIRONMENT", + "options": [ + "Development", + "Production" + ], + "type": "pickString" + }, + { + "default": "{AssemblyTitle}", + "description": "What Assembly Title?", + "id": "AssemblyTitle", + "type": "promptString" + }, + { + "default": "{Build.BuildId}", + "description": "Which Build BuildId?", + "id": "Build.BuildId", + "type": "promptString" + }, + { + "default": "{Build.Reason}", + "description": "Which Build Reason?", + "id": "Build.Reason", + "type": "promptString" + }, + { + "default": "{Build.Repository.Id}", + "description": "Which Build Repository Id?", + "id": "Build.Repository.Id", + "type": "promptString" + }, + { + "default": "{Build.Repository.Name}", + "description": "Which Build Repository Name?", + "id": "Build.Repository.Name", + "type": "promptString" + }, + { + "default": "{Build.SourceVersion}", + "description": "Which Build Source Version?", + "id": "Build.SourceVersion", + "type": "promptString" + }, + { + "default": "Debug", + "description": "Which Configuration?", + "id": "Configuration", + "options": [ + "Debug", + "Release" + ], + "type": "pickString" + }, + { + "default": "net8.0", + "description": "Which Core Version?", + "id": "CoreVersion", + "options": [ + "net8.0" + ], + "type": "pickString" + }, + { + "default": "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/MSBuild/Current/Bin/MSBuild.exe", + "description": "Which MS Build?", + "id": "MSBuild", + "type": "promptString" + }, + { + "default": "https://artifactory.intra.infineon.com/artifactory/api/nuget/ngt-fi-package-main-vir/", + "description": "Which Nuget Source?", + "id": "NugetSource", + "type": "promptString" + }, + { + "default": "win-x64", + "description": "Which Runtime?", + "id": "Runtime", + "options": [ + "win-x64", + "win-x32", + "linux-x64", + "linux-x32" + ], + "type": "pickString" + }, + { + "default": "L:/", + "description": "Which System DefaultWorkingDirectory?", + "id": "System.DefaultWorkingDirectory", + "options": [ + "L:/", + "D:/", + "C:/" + ], + "type": "pickString" + }, + { + "default": "v4.8", + "description": "Which Core Target Framework Version?", + "id": "TargetFrameworkVersion", + "options": [ + "v4.8" + ], + "type": "pickString" + } + ], "tasks": [ { - "label": "build", - "command": "dotnet", - "type": "process", "args": [ - "build", - "${workspaceFolder}/OI.Metrology.Server.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" + "build" ], - "problemMatcher": "$msCompile" + "command": "dotnet", + "label": "Build", + "problemMatcher": "$msCompile", + "type": "process" }, { - "label": "buildTests", - "command": "dotnet", - "type": "process", "args": [ "build", - "${workspaceFolder}/../Tests/OI.Metrology.Tests.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" + "${workspaceFolder}/../Tests/OI.Metrology.Tests.csproj" ], - "problemMatcher": "$msCompile" + "command": "dotnet", + "label": "Build Tests", + "problemMatcher": "$msCompile", + "type": "process" }, { - "label": "testDebug", + "args": [ + "test", + "${workspaceFolder}/../Tests/OI.Metrology.Tests.csproj" + ], "command": "dotnet", - "type": "process", + "label": "Test Debug", + "problemMatcher": "$msCompile", + "type": "process" + }, + { "args": [ "test", "${workspaceFolder}/../Tests/OI.Metrology.Tests.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "testRelease", - "command": "dotnet", - "type": "process", - "args": [ - "test", - "${workspaceFolder}/../Tests/OI.Metrology.Tests.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary", "-c", "Release" ], - "problemMatcher": "$msCompile" + "command": "dotnet", + "label": "Test Release", + "problemMatcher": "$msCompile", + "type": "process" }, { - "label": "Format", - "command": "dotnet", - "type": "process", "args": [ "format", "--report", @@ -64,27 +162,24 @@ "--severity", "warn" ], - "problemMatcher": "$msCompile" + "command": "dotnet", + "label": "Format", + "problemMatcher": "$msCompile", + "type": "process" }, { - "label": "Format-Whitespace", - "command": "dotnet", - "type": "process", "args": [ "format", "whitespace" ], - "problemMatcher": "$msCompile" + "command": "dotnet", + "label": "Format Whitespace", + "problemMatcher": "$msCompile", + "type": "process" }, { - "label": "publish", - "command": "dotnet", - "type": "process", "args": [ "publish", - "${workspaceFolder}/OI.Metrology.Server.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary", "--configuration", "Release", "--runtime", @@ -93,17 +188,14 @@ "-o", "D:/web-sites/OI-Metrology/hh-3498d1da-_______-OI-Metrology-Release/Server" ], - "problemMatcher": "$msCompile" + "command": "dotnet", + "label": "Publish", + "problemMatcher": "$msCompile", + "type": "process" }, { - "label": "Publish AOT", - "command": "dotnet", - "type": "process", "args": [ "publish", - "${workspaceFolder}/OI.Metrology.Server.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary", "--configuration", "Release", "--runtime", @@ -111,64 +203,217 @@ "-p:PublishAot=true", "/property:GenerateFullPaths=true" ], - "problemMatcher": "$msCompile" + "command": "dotnet", + "label": "Publish AOT", + "problemMatcher": "$msCompile", + "type": "process" }, { - "label": "old-watch", - "command": "dotnet", - "type": "process", "args": [ "watch", - "run", - "--project", - "${workspaceFolder}/OI.Metrology.Server.csproj" + "run" ], - "problemMatcher": "$msCompile" + "command": "dotnet", + "label": "Old Watch", + "problemMatcher": "$msCompile", + "type": "process" }, { - "label": "watch", - "command": "dotnet", - "type": "process", "args": [ "watch", "--launch-profile", "http", "run", - "--project", - "${workspaceFolder}/OI.Metrology.Server.csproj", "--verbose" ], - "isBackground": true, + "command": "dotnet", "dependsOn": [ "build" ], + "isBackground": true, + "label": "Watch", "problemMatcher": { - "fileLocation": "relative", - "pattern": { - "regexp": "^([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\):\\s+(error|warning|info)\\s+(TS\\d+)\\s*:\\s*(.*)$", - "file": 1, - "location": 2, - "severity": 3, - "code": 4, - "message": 5 - }, "background": { "activeOnStart": true, "beginsPattern": "^.*Shutdown requested.*", "endsPattern": "^.*Application started.*" + }, + "fileLocation": "relative", + "pattern": { + "code": 4, + "file": 1, + "location": 2, + "message": 5, + "regexp": "^([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\):\\s+(error|warning|info)\\s+(TS\\d+)\\s*:\\s*(.*)$", + "severity": 3 } - } + }, + "type": "process" }, { - "label": "File-Folder-Helper AOT s X Server", - "type": "shell", - "command": "L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe", "args": [ "s", "X", "L:/DevOps/Mesa_FI/OI-Metrology Day-Helper-2024-01-08 L:/DevOps/Mesa_FI/OI-Metrology/Server" ], - "problemMatcher": [] + "command": "L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe", + "label": "File-Folder-Helper AOT s X Server", + "problemMatcher": [], + "type": "shell" + }, + { + "command": "echo Assembly Title: ${input:AssemblyTitle} & echo Build Id: ${input:Build.BuildId} & echo Build Reason: ${input:Build.Reason} & echo Repo Id: ${input:Build.Repository.Id} & echo Repo Name: ${input:Build.Repository.Name} & echo Source Version: ${input:Build.SourceVersion} & echo Configuration: ${input:Configuration} & echo Core Version: ${input:CoreVersion} & echo Nuget Source: ${input:NugetSource} & echo Runtime: ${input:Runtime}", + "label": "Echo Check", + "problemMatcher": [], + "type": "shell" + }, + { + "command": "dotnet user-secrets init & dotnet user-secrets set BuildNumber ${input:Build.BuildId} & dotnet user-secrets set GitCommit ${input:Build.SourceVersion} & dotnet user-secrets list", + "label": "Server - Safe storage of app secrets", + "problemMatcher": [], + "type": "shell" + }, + { + "args": [ + "build", + "--configuration", + "${input:Configuration}", + "--source", + "${input:NugetSource}" + ], + "command": "dotnet", + "label": "Server - Build", + "problemMatcher": "$msCompile", + "type": "process" + }, + { + "args": [ + "build", + "${workspaceFolder}/../Tests/OI.Metrology.Tests.csproj", + "--configuration", + "${input:Configuration}", + "--source", + "${input:NugetSource}" + ], + "command": "dotnet", + "label": "Tests - Build", + "problemMatcher": "$msCompile", + "type": "process" + }, + { + "args": [ + "test", + "${workspaceFolder}/../Tests/OI.Metrology.Tests.csproj", + "--configuration", + "${input:Configuration}" + ], + "command": "dotnet", + "label": "Tests - Test", + "problemMatcher": "$msCompile", + "type": "process" + }, + { + "args": [ + "publish", + "--configuration", + "${input:Configuration}", + "--runtime", + "${input:Runtime}", + "--self-contained" + ], + "command": "dotnet", + "label": "Server - Publish", + "problemMatcher": "$msCompile", + "type": "process" + }, + { + "args": [ + "publish", + "--configuration", + "${input:Configuration}", + "--runtime", + "${input:Runtime}", + "-p:PublishAot=true" + ], + "command": "dotnet", + "label": "Server - AOT Publish", + "problemMatcher": "$msCompile", + "type": "process" + }, + { + "command": "(robocopy /MIR \"bin/${input:Configuration}/${input:CoreVersion}/${input:Runtime}/publish\" \"D:/${input:CoreVersion}/${input:Runtime}/${input:Build.Repository.Name}/${input:Build.BuildId}/${input:Configuration}-${input:AssemblyTitle}\") ^& IF %ERRORLEVEL% LEQ 7 exit 0", + "label": "Copy Files to: D:/", + "problemMatcher": [], + "type": "shell" + }, + { + "args": [ + "tool", + "restore" + ], + "command": "dotnet", + "label": "Tool Restore", + "problemMatcher": [], + "type": "process" + }, + { + "args": [ + "ReportGenerator", + "-reports:${input:System.DefaultWorkingDirectory}/TestResults/**/coverage.cobertura.xml", + "-targetDir:${input:Build.ArtifactStagingDirectory}/Coverage", + "-reportTypes:Html_Dark" + ], + "command": "dotnet", + "label": "Report Generator", + "problemMatcher": [], + "type": "process" + }, + { + "args": [ + "clean", + "${workspaceFolder}/../Tests/OI.Metrology.Tests.csproj", + "--configuration", + "${input:Configuration}" + ], + "command": "dotnet", + "label": "Tests - Clean", + "problemMatcher": "$msCompile", + "type": "process" + }, + { + "args": [ + "clean", + "--configuration", + "${input:Configuration}" + ], + "command": "dotnet", + "label": "Server - Clean", + "problemMatcher": "$msCompile", + "type": "process" + }, + { + "args": [ + "Server - AOT Publish", + "Tool Restore", + "Report Generator" + ], + "command": "echo", + "dependsOn": [ + "Echo Check", + "Server - Safe storage of app secrets", + "Server - Build", + "Tests - Build", + "Tests - Test", + "Server - Publish", + "Copy Files to: D:/", + "Tests - Clean", + "Server - Clean" + ], + "dependsOrder": "sequence", + "label": "Pipeline", + "problemMatcher": [], + "type": "shell" } - ] + ], + "version": "2.0.0" } \ No newline at end of file diff --git a/Server/ApiControllers/AppSettingsController.cs b/Server/ApiControllers/AppSettingsController.cs index ce0bf8f..381bd65 100644 --- a/Server/ApiControllers/AppSettingsController.cs +++ b/Server/ApiControllers/AppSettingsController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using OI.Metrology.Server.Models; using OI.Metrology.Shared.Models.Stateless; namespace OI.Metrology.Server.ApiControllers; @@ -8,9 +9,9 @@ namespace OI.Metrology.Server.ApiControllers; public class AppSettingsController : ControllerBase, IAppSettingsController { - private readonly IAppSettingsRepository _AppSettingsRepository; + private readonly IAppSettingsRepository _AppSettingsRepository; - public AppSettingsController(IAppSettingsRepository AppSettingsRepository) => _AppSettingsRepository = AppSettingsRepository; + public AppSettingsController(IAppSettingsRepository AppSettingsRepository) => _AppSettingsRepository = AppSettingsRepository; [HttpGet(nameof(IAppSettingsController.Action.App))] public ActionResult GetAppSettings() => diff --git a/Server/Models/AppSettings.cs b/Server/Models/AppSettings.cs index 89138cc..8cad90b 100644 --- a/Server/Models/AppSettings.cs +++ b/Server/Models/AppSettings.cs @@ -1,4 +1,5 @@ using System.Text.Json; +using System.Text.Json.Serialization; namespace OI.Metrology.Server.Models; @@ -36,8 +37,75 @@ public record AppSettings(string ApiFileShare, public override string ToString() { - string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true }); + string result = JsonSerializer.Serialize(this, AppSettingsSourceGenerationContext.Default.AppSettings); return result; } + private static void Verify(AppSettings appSettings) + { + if (string.IsNullOrEmpty(appSettings.Company)) + throw new Exception("Company name must have a value!"); + if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName)) + throw new Exception("Working directory name must have a value!"); + } + + public static AppSettings Get(IConfigurationRoot configurationRoot) + { + AppSettings result; + AppSettings? appSettings = configurationRoot.Get(); +#pragma warning restore IL3050, IL2026 + if (appSettings is null + || appSettings?.Company is null) + { + List paths = []; + foreach (IConfigurationProvider configurationProvider in configurationRoot.Providers) + { + if (configurationProvider is not Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider jsonConfigurationProvider) + continue; + if (jsonConfigurationProvider.Source.FileProvider is not Microsoft.Extensions.FileProviders.PhysicalFileProvider physicalFileProvider) + continue; + paths.Add(physicalFileProvider.Root); + } + throw new NotSupportedException($"Not found!{Environment.NewLine}{string.Join(Environment.NewLine, paths.Distinct())}"); + } + result = new(appSettings.ApiFileShare, + appSettings.ApiLoggingContentTypes, + appSettings.ApiLoggingPathPrefixes, + appSettings.ApiLogPath, + appSettings.ApiUrl, + appSettings.BuildNumber, + appSettings.Company, + appSettings.ConnectionString, + appSettings.EcCharacterizationSi, + appSettings.EcMesaFileShareCharacterizationSi, + appSettings.EcMesaFileShareMetrologySi, + appSettings.EcMetrologySi, + appSettings.GitCommitSeven, + appSettings.InboundApiAllowedIPList, + appSettings.IqsColumns, + appSettings.IqsFileSegments, + appSettings.IqsKey, + appSettings.IqsRed, + appSettings.IqsYellow, + appSettings.IsDevelopment, + appSettings.IsStaging, + appSettings.MockRoot, + appSettings.MonAResource, + appSettings.MonASite, + appSettings.OpenInsightApplicationProgrammingInterface, + appSettings.TableToPath, + appSettings.URLs, + appSettings.WaferCounterDestinationDirectory, + appSettings.WaferCounterTwoFileSecondsWait, + appSettings.WorkingDirectoryName); + Verify(result); + return result; + } + +} + +[JsonSourceGenerationOptions(WriteIndented = true)] +[JsonSerializable(typeof(AppSettings))] +public partial class AppSettingsSourceGenerationContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/Server/Models/Binder/.editorconfig b/Server/Models/Binder/.editorconfig deleted file mode 100644 index 1c444cd..0000000 --- a/Server/Models/Binder/.editorconfig +++ /dev/null @@ -1,2 +0,0 @@ -[*.cs] -csharp_preserve_single_line_statements = true \ No newline at end of file diff --git a/Server/Models/Binder/AppSettings.cs b/Server/Models/Binder/AppSettings.cs deleted file mode 100644 index c96bda2..0000000 --- a/Server/Models/Binder/AppSettings.cs +++ /dev/null @@ -1,148 +0,0 @@ -using System.Text.Json; -using System.Text.Json.Serialization; - -namespace OI.Metrology.Server.Models.Binder; - -public class AppSettings -{ - - public string? ApiFileShare { get; set; } - public string? ApiLoggingContentTypes { get; set; } - public string? ApiLoggingPathPrefixes { get; set; } - public string? ApiLogPath { get; set; } - public string? ApiUrl { get; set; } - public string? BuildNumber { get; set; } - public string? Company { get; set; } - public string? ConnectionString { get; set; } - public string? EcCharacterizationSi { get; set; } - public string? EcMesaFileShareCharacterizationSi { get; set; } - public string? EcMesaFileShareMetrologySi { get; set; } - public string? EcMetrologySi { get; set; } - public string? GitCommitSeven { get; set; } - public string? InboundApiAllowedIPList { get; set; } - public string? IqsColumns { get; set; } - public string[]? IqsFileSegments { get; set; } - public string? IqsKey { get; set; } - public string? IqsRed { get; set; } - public string? IqsYellow { get; set; } - public bool? IsDevelopment { get; set; } - public bool? IsStaging { get; set; } - public string? MockRoot { get; set; } - public string? MonAResource { get; set; } - public string? MonASite { get; set; } - public string? OpenInsightApplicationProgrammingInterface { get; set; } - public Dictionary? TableToPath { get; set; } - public string? URLs { get; set; } - public string? WaferCounterDestinationDirectory { get; set; } - public int? WaferCounterTwoFileSecondsWait { get; set; } - public string? WorkingDirectoryName { get; set; } - - public override string ToString() - { - string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true }); - return result; - } - - private static void PreVerify(IConfigurationRoot configurationRoot, AppSettings? appSettings) - { - if (appSettings?.ApiFileShare is null) - { - List paths = new(); - foreach (IConfigurationProvider configurationProvider in configurationRoot.Providers) - { - if (configurationProvider is not Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider jsonConfigurationProvider) - continue; - if (jsonConfigurationProvider.Source.FileProvider is not Microsoft.Extensions.FileProviders.PhysicalFileProvider physicalFileProvider) - continue; - paths.Add(physicalFileProvider.Root); - } - throw new NotSupportedException($"Not found!{Environment.NewLine}{string.Join(Environment.NewLine, paths.Distinct())}"); - } - } - - private static Models.AppSettings Get(AppSettings? appSettings) - { - Models.AppSettings result; - if (appSettings is null) throw new NullReferenceException(nameof(appSettings)); - if (appSettings.ApiFileShare is null) throw new NullReferenceException(nameof(ApiFileShare)); - if (appSettings.ApiLoggingContentTypes is null) throw new NullReferenceException(nameof(ApiLoggingContentTypes)); - if (appSettings.ApiLoggingPathPrefixes is null) throw new NullReferenceException(nameof(ApiLoggingPathPrefixes)); - if (appSettings.ApiLogPath is null) throw new NullReferenceException(nameof(ApiLogPath)); - if (appSettings.ApiUrl is null) throw new NullReferenceException(nameof(ApiUrl)); - if (appSettings.BuildNumber is null) throw new NullReferenceException(nameof(BuildNumber)); - if (appSettings.Company is null) throw new NullReferenceException(nameof(Company)); - if (appSettings.ConnectionString is null) throw new NullReferenceException(nameof(ConnectionString)); - if (appSettings.EcCharacterizationSi is null) throw new NullReferenceException(nameof(EcCharacterizationSi)); - if (appSettings.EcMesaFileShareCharacterizationSi is null) throw new NullReferenceException(nameof(EcMesaFileShareCharacterizationSi)); - if (appSettings.EcMesaFileShareMetrologySi is null) throw new NullReferenceException(nameof(EcMesaFileShareMetrologySi)); - if (appSettings.EcMetrologySi is null) throw new NullReferenceException(nameof(EcMetrologySi)); - if (appSettings.GitCommitSeven is null) throw new NullReferenceException(nameof(GitCommitSeven)); - if (appSettings.InboundApiAllowedIPList is null) throw new NullReferenceException(nameof(InboundApiAllowedIPList)); - if (appSettings.IqsColumns is null) throw new NullReferenceException(nameof(IqsColumns)); - if (appSettings.IqsFileSegments is null) throw new NullReferenceException(nameof(IqsFileSegments)); - if (appSettings.IqsKey is null) throw new NullReferenceException(nameof(IqsKey)); - if (appSettings.IqsRed is null) throw new NullReferenceException(nameof(IqsRed)); - if (appSettings.IqsYellow is null) throw new NullReferenceException(nameof(IqsYellow)); - if (appSettings.IsDevelopment is null) throw new NullReferenceException(nameof(IsDevelopment)); - if (appSettings.IsStaging is null) throw new NullReferenceException(nameof(IsStaging)); - if (appSettings.MockRoot is null) throw new NullReferenceException(nameof(MockRoot)); - if (appSettings.MonAResource is null) throw new NullReferenceException(nameof(MonAResource)); - if (appSettings.MonASite is null) throw new NullReferenceException(nameof(MonASite)); - if (appSettings.OpenInsightApplicationProgrammingInterface is null) throw new NullReferenceException(nameof(OpenInsightApplicationProgrammingInterface)); - if (appSettings.URLs is null) throw new NullReferenceException(nameof(URLs)); - if (appSettings.TableToPath is null) throw new NullReferenceException(nameof(TableToPath)); - if (appSettings.WaferCounterDestinationDirectory is null) throw new NullReferenceException(nameof(WaferCounterDestinationDirectory)); - if (appSettings.WaferCounterTwoFileSecondsWait is null) throw new NullReferenceException(nameof(WaferCounterTwoFileSecondsWait)); - if (appSettings.WorkingDirectoryName is null) throw new NullReferenceException(nameof(WorkingDirectoryName)); - result = new( - appSettings.ApiFileShare, - appSettings.ApiLoggingContentTypes, - appSettings.ApiLoggingPathPrefixes, - appSettings.ApiLogPath, - appSettings.ApiUrl, - appSettings.BuildNumber, - appSettings.Company, - appSettings.ConnectionString, - appSettings.EcCharacterizationSi, - appSettings.EcMesaFileShareCharacterizationSi, - appSettings.EcMesaFileShareMetrologySi, - appSettings.EcMetrologySi, - appSettings.GitCommitSeven, - appSettings.InboundApiAllowedIPList, - appSettings.IqsColumns, - appSettings.IqsFileSegments, - appSettings.IqsKey, - appSettings.IqsRed, - appSettings.IqsYellow, - appSettings.IsDevelopment.Value, - appSettings.IsStaging.Value, - appSettings.MockRoot, - appSettings.MonAResource, - appSettings.MonASite, - appSettings.OpenInsightApplicationProgrammingInterface, - appSettings.TableToPath, - appSettings.URLs, - appSettings.WaferCounterDestinationDirectory, - appSettings.WaferCounterTwoFileSecondsWait.Value, - appSettings.WorkingDirectoryName); - return result; - } - - public static Models.AppSettings Get(IConfigurationRoot configurationRoot) - { - Models.AppSettings result; -#pragma warning disable IL3050, IL2026 - AppSettings? appSettings = configurationRoot.Get(); -#pragma warning restore IL3050, IL2026 - PreVerify(configurationRoot, appSettings); - result = Get(appSettings); - return result; - } - -} - -[JsonSourceGenerationOptions(WriteIndented = true)] -[JsonSerializable(typeof(AppSettings))] -internal partial class BinderAppSettingsSourceGenerationContext : JsonSerializerContext -{ -} \ No newline at end of file diff --git a/Server/Program.cs b/Server/Program.cs index a2600e7..89a283a 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -43,7 +43,7 @@ public class Program (string assemblyName, WebApplicationOptions _) = Get(args); WebApplicationBuilder webApplicationBuilder = WebApplication.CreateBuilder(args); _ = webApplicationBuilder.Configuration.AddUserSecrets(); - AppSettings appSettings = Models.Binder.AppSettings.Get(webApplicationBuilder.Configuration); + AppSettings appSettings = AppSettings.Get(webApplicationBuilder.Configuration); if (string.IsNullOrEmpty(appSettings.Company)) throw new Exception("Company name must have a value!"); if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName)) @@ -78,7 +78,7 @@ public class Program _ = webApplicationBuilder.Services.AddSingleton(); _ = webApplicationBuilder.Services.AddSingleton(); _ = webApplicationBuilder.Services.AddSingleton(_ => sqlDbConnectionFactory); - _ = webApplicationBuilder.Services.AddSingleton>(_ => appSettingsRepository); + _ = webApplicationBuilder.Services.AddSingleton>(_ => appSettingsRepository); _ = webApplicationBuilder.Services.AddSwaggerGen(); _ = webApplicationBuilder.Services.AddSession(sessionOptions => diff --git a/Server/Repositories/AppSettingsRepository.cs b/Server/Repositories/AppSettingsRepository.cs index 50e1446..2e8a85a 100644 --- a/Server/Repositories/AppSettingsRepository.cs +++ b/Server/Repositories/AppSettingsRepository.cs @@ -3,27 +3,20 @@ using OI.Metrology.Shared.Models.Stateless; namespace OI.Metrology.Server.Repository; -public class AppSettingsRepository : IAppSettingsRepository +public class AppSettingsRepository : IAppSettingsRepository { private readonly AppSettings _AppSettings; public AppSettingsRepository(AppSettings appSettings) => _AppSettings = appSettings; - internal Models.Binder.AppSettings GetAppSettings() + internal AppSettings GetAppSettings() { - Models.Binder.AppSettings result = new() - { - BuildNumber = _AppSettings.BuildNumber, - Company = _AppSettings.Company, - GitCommitSeven = _AppSettings.GitCommitSeven, - IsDevelopment = _AppSettings.IsDevelopment, - IsStaging = _AppSettings.IsStaging, - }; + AppSettings result = _AppSettings; return result; } - Models.Binder.AppSettings IAppSettingsRepository.GetAppSettings() => GetAppSettings(); + AppSettings IAppSettingsRepository.GetAppSettings() => GetAppSettings(); internal string GetBuildNumberAndGitCommitSeven() { @@ -45,8 +38,8 @@ public class AppSettingsRepository : IAppSettingsRepository.GetBuildNumberAndGitCommitSeven() => GetBuildNumberAndGitCommitSeven(); + string IAppSettingsRepository.GetBuildNumberAndGitCommitSeven() => GetBuildNumberAndGitCommitSeven(); - void IAppSettingsRepository.VerifyConnectionStrings() => VerifyConnectionStrings(); + void IAppSettingsRepository.VerifyConnectionStrings() => VerifyConnectionStrings(); } \ No newline at end of file diff --git a/Server/server-pipeline.yml b/Server/server-pipeline.yml new file mode 100644 index 0000000..bb006ee --- /dev/null +++ b/Server/server-pipeline.yml @@ -0,0 +1,158 @@ +trigger: + branches: + include: + - master + paths: + include: + - Shared + - Server + +variables: + runtime: 'win-x64' + coreVersion: 'net8.0' + nugetSource: 'https://artifactory.intra.infineon.com/artifactory/api/nuget/ngt-fi-package-main-vir/' + +stages: + - stage: Development + displayName: Development + pool: + name: 'OpenInsight Metrology Viewer' + demands: OpenInsight-Metrology-Viewer-Server-Development + variables: + ASPNETCORE_ENVIRONMENT: 'Development' + assemblyTitle: 'OI.Metrology.Server' + configuration: 'Debug' + jobs: + - job: DebugDotnet + steps: + - script: | + echo Assembly Title: $(AssemblyTitle) + echo Build Id: $(Build.BuildId) + echo Build Reason: $(Build.Reason) + echo Repo Id: $(Build.Repository.Id) + echo Repo Name: $(Build.Repository.Name) + echo Source Version: $(Build.SourceVersion) + echo Configuration: $(Configuration) + echo Core Version: $(CoreVersion) + echo Nuget Source: $(NugetSource) + echo Runtime: $(Runtime) + displayName: 'Echo Check' + + - script: | + dotnet user-secrets init + dotnet user-secrets set BuildNumber $(Build.BuildId) + dotnet user-secrets set GitCommit $(Build.SourceVersion) + dotnet user-secrets list + workingDirectory: Server + displayName: 'Server - Safe storage of app secrets' + + - script: dotnet build --configuration $(Configuration) --source $(NugetSource) + workingDirectory: Server + displayName: 'Server - Build' + + - script: dotnet build --configuration $(Configuration) --source $(NugetSource) + workingDirectory: Tests + displayName: 'Tests - Build' + + - script: dotnet test --configuration $(Configuration) + workingDirectory: Tests + displayName: 'Tests - Test' + + - script: dotnet publish --configuration $(Configuration) + workingDirectory: Server + displayName: 'Server - Publish' + enabled: false + + - script: dotnet publish --configuration $(Configuration) --runtime $(Runtime) -p:PublishAot=true + workingDirectory: Server + displayName: 'Server - AOT Publish' + + - task: CopyFiles@2 + displayName: 'Copy Files to: D:\' + inputs: + Contents: "*" + SourceFolder: 'Server\bin\$(Configuration)\$(CoreVersion)\$(Runtime)\publish' + TargetFolder: 'D:\$(CoreVersion)\$(Runtime)\$(Build.Repository.Name)\$(Build.BuildId)\$(Configuration)-$(AssemblyTitle)-AOT' + OverWrite: true + + - script: dotnet clean --configuration $(Configuration) + workingDirectory: Tests + displayName: 'Tests - Clean' + + - script: dotnet clean --configuration $(Configuration) + workingDirectory: Server + displayName: 'Server - Clean' + + - stage: Release + displayName: Release + pool: + name: 'OpenInsight Metrology Viewer' + demands: OpenInsight-Metrology-Viewer-Server + variables: + ASPNETCORE_ENVIRONMENT: 'Production' + assemblyTitle: 'OI.Metrology.Server' + configuration: 'Release' + jobs: + - job: ReleaseDotnet + steps: + - script: | + echo Assembly Title: $(AssemblyTitle) + echo Build Id: $(Build.BuildId) + echo Build Reason: $(Build.Reason) + echo Repo Id: $(Build.Repository.Id) + echo Repo Name: $(Build.Repository.Name) + echo Source Version: $(Build.SourceVersion) + echo Configuration: $(Configuration) + echo Core Version: $(CoreVersion) + echo Nuget Source: $(NugetSource) + echo Runtime: $(Runtime) + displayName: 'Echo Check' + + - script: | + dotnet user-secrets init + dotnet user-secrets set BuildNumber $(Build.BuildId) + dotnet user-secrets set GitCommit $(Build.SourceVersion) + dotnet user-secrets list + workingDirectory: Server + displayName: 'Server - Safe storage of app secrets' + + - script: dotnet build --configuration $(Configuration) --source $(NugetSource) + workingDirectory: Server + displayName: 'Server - Build' + + - script: dotnet build --configuration $(Configuration) --source $(NugetSource) + workingDirectory: Tests + displayName: 'Tests - Build' + + - script: dotnet test --configuration $(Configuration) + workingDirectory: Tests + displayName: 'Tests - Test' + + - script: dotnet publish --configuration $(Configuration) + workingDirectory: Server + displayName: 'Server - Publish' + enabled: false + + - script: dotnet publish --configuration $(Configuration) --runtime $(Runtime) -p:PublishAot=true + workingDirectory: Server + displayName: 'Server - AOT Publish' + + - task: CopyFiles@2 + displayName: 'Copy Files to: D:\' + inputs: + Contents: '*' + SourceFolder: 'Server\bin\$(Configuration)\$(CoreVersion)\$(Runtime)\publish' + TargetFolder: 'D:\$(CoreVersion)\$(Runtime)\$(Build.Repository.Name)\$(Build.BuildId)\$(Configuration)-$(AssemblyTitle)-AOT' + OverWrite: true + + - script: dotnet clean --configuration $(Configuration) + workingDirectory: Tests + displayName: 'Tests - Clean' + + - script: dotnet clean --configuration $(Configuration) + workingDirectory: Server + displayName: 'Server - Clean' + + - script: 'echo $(Build.SourceVersion)-$(Build.BuildId)>bin_x_x_\$(Configuration)\$(CoreVersion)\win-x64\$(Build.Repository.Name).txt' + displayName: 'Force Fail' + enabled: false diff --git a/Shared/Models/Stateless/IAzureDevOpsController.cs b/Shared/Models/Stateless/IAzureDevOpsController.cs deleted file mode 100644 index 31998d2..0000000 --- a/Shared/Models/Stateless/IAzureDevOpsController.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace OI.Metrology.Shared.Models.Stateless; - -public interface IAzureDevOpsController -{ - - enum Action : int - { - Index = 0, - Save = 1 - } - - static string GetRouteName() => nameof(IAzureDevOpsController)[1..^10]; - - T Save(); - -} \ No newline at end of file diff --git a/Shared/Models/Stateless/IAzureDevOpsRepository.cs b/Shared/Models/Stateless/IAzureDevOpsRepository.cs deleted file mode 100644 index c84e08c..0000000 --- a/Shared/Models/Stateless/IAzureDevOpsRepository.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace OI.Metrology.Shared.Models.Stateless; - -public interface IAzureDevOpsRepository -{ - - void Save(PollValue pollValue); - -} \ No newline at end of file diff --git a/Shared/OI.Metrology.Shared.csproj b/Shared/OI.Metrology.Shared.csproj index 8e3f89b..91a4a2c 100644 --- a/Shared/OI.Metrology.Shared.csproj +++ b/Shared/OI.Metrology.Shared.csproj @@ -29,7 +29,7 @@ Linux - + diff --git a/Tests/.vscode/mklink.md b/Tests/.vscode/mklink.md new file mode 100644 index 0000000..249c152 --- /dev/null +++ b/Tests/.vscode/mklink.md @@ -0,0 +1,6 @@ +# mklink + +```bash Thu Aug 29 2024 09:47:22 GMT-0700 (Mountain Standard Time) +mklink /J "L:\DevOps\OpenInsight-Metrology-Viewer\OI-Metrology\Tests\.vscode\.UserSecrets-Server" "C:\Users\phares\AppData\Roaming\Microsoft\UserSecrets\b0a3891c-b775-422c-80ee-63a2f385045d" +mklink /J "L:\DevOps\OpenInsight-Metrology-Viewer\OI-Metrology\Tests\.vscode\.UserSecrets-Wafer-Counter" "C:\Users\phares\AppData\Roaming\Microsoft\UserSecrets\2a0acd34-8f61-47a3-8818-73fa8fe04902" +``` \ No newline at end of file diff --git a/Tests/.vscode/settings.json b/Tests/.vscode/settings.json index b301a13..5d914b1 100644 --- a/Tests/.vscode/settings.json +++ b/Tests/.vscode/settings.json @@ -1,6 +1,24 @@ { "coverage-gutters.coverageBaseDir": "../.vscode/TestResults/**", "cSpell.words": [ - "datebegin" + "appsettings", + "BIORAD", + "datebegin", + "dateend", + "Dispo", + "headerid", + "headertitles", + "infineon", + "markasawaiting", + "markasreviewed", + "mesfs", + "messa", + "Newtonsoft", + "pdsf", + "RESIMAPCDE", + "ROTR", + "SGRP", + "Tencor", + "TSNO" ] } \ No newline at end of file diff --git a/Tests/.vscode/tasks.json b/Tests/.vscode/tasks.json index eb1405b..fed48b8 100644 --- a/Tests/.vscode/tasks.json +++ b/Tests/.vscode/tasks.json @@ -2,43 +2,57 @@ "version": "2.0.0", "tasks": [ { - "label": "build", + "label": "Build", "command": "dotnet", "type": "process", "args": [ - "build", - "${workspaceFolder}/OI.Metrology.Tests.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" + "build" ], "problemMatcher": "$msCompile" }, { - "label": "testDebug", + "label": "Test Debug", "command": "dotnet", "type": "process", "args": [ "test", - "${workspaceFolder}/OI.Metrology.Tests.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" + "--settings:test.runsettings" ], "problemMatcher": "$msCompile" }, { - "label": "testRelease", + "label": "Test Debug with Settings", + "command": "dotnet", + "type": "process", + "args": [ + "test", + "--settings:Settings.xml" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "Test Release", "command": "dotnet", "type": "process", "args": [ "test", - "${workspaceFolder}/OI.Metrology.Tests.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary", "-c", "Release" ], "problemMatcher": "$msCompile" }, + { + "label": "Test Release with Settings", + "command": "dotnet", + "type": "process", + "args": [ + "test", + "-c", + "Release", + "--settings:Settings.xml" + ], + "problemMatcher": "$msCompile" + }, { "label": "Format", "command": "dotnet", @@ -55,7 +69,7 @@ "problemMatcher": "$msCompile" }, { - "label": "Format-Whitespace", + "label": "Format Whitespace", "command": "dotnet", "type": "process", "args": [ @@ -65,14 +79,11 @@ "problemMatcher": "$msCompile" }, { - "label": "publish", + "label": "Publish", "command": "dotnet", "type": "process", "args": [ "publish", - "${workspaceFolder}/../Server/OI.Metrology.Server.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary", "--configuration", "Release", "--runtime", diff --git a/Tests/.vscode/tc_col_metrology-viewer-v3.http b/Tests/.vscode/tc_col_metrology-viewer-v3.http index 8d6238a..fb2a7b7 100644 --- a/Tests/.vscode/tc_col_metrology-viewer-v3.http +++ b/Tests/.vscode/tc_col_metrology-viewer-v3.http @@ -15,3 +15,6 @@ Accept: application/json ### GET {{host}}/111/header Accept: application/json + +### +GET https://oi-metrology-viewer-prod.mes.infineon.com/api/InfinityQSV3/CDE4_250520183333000/header \ No newline at end of file diff --git a/Tests/BaseTestClass.cs b/Tests/BaseTestClass.cs new file mode 100644 index 0000000..54ba849 --- /dev/null +++ b/Tests/BaseTestClass.cs @@ -0,0 +1,21 @@ +using System.Diagnostics; + +namespace OI.Metrology.Tests; + +public class BaseTestClass +{ + + private static int _FailedTests; + private readonly int _Threshold = 5; + + protected void IncrementFailedTests() + { + if (++_FailedTests >= _Threshold) + { + for (int i = 0; i < 10; i++) + Thread.Sleep(500); + Process.GetCurrentProcess().Kill(); + } + } + +} \ No newline at end of file diff --git a/Tests/Settings.xml b/Tests/Settings.xml new file mode 100644 index 0000000..3a1dfb8 --- /dev/null +++ b/Tests/Settings.xml @@ -0,0 +1,9 @@ + + + + + 0 + MethodLevel + + + \ No newline at end of file diff --git a/Tests/UnitAwaitingDispoController.cs b/Tests/UnitAwaitingDispoController.cs index ddfdeda..40082ec 100644 --- a/Tests/UnitAwaitingDispoController.cs +++ b/Tests/UnitAwaitingDispoController.cs @@ -8,14 +8,14 @@ using System.Net.Http.Json; namespace OI.Metrology.Tests; [TestClass] -public class UnitAwaitingDispoController +public class UnitAwaitingDispoController : BaseTestClass { #pragma warning disable CS8618 private static ILogger? _Logger; private static string _ControllerName; - private static string? _TestContextTestName; + public TestContext TestContext { get; set; } private static WebApplicationFactory? _WebApplicationFactory; #pragma warning restore @@ -23,19 +23,32 @@ public class UnitAwaitingDispoController [ClassInitialize] public static void ClassInitAsync(TestContext testContext) { - _TestContextTestName = testContext.TestName; _WebApplicationFactory = new WebApplicationFactory(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; _Logger = serviceProvider.GetRequiredService>(); _ControllerName = nameof(Server.ApiControllers.AwaitingDispoController)[..^10]; } + private static void NonThrowTryCatch() + { + try + { throw new Exception(); } + catch (Exception) { } + } + + [TestCleanup] + public void TestCleanup() + { + if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed) + IncrementFailedTests(); + } + [TestMethod] public void TestControllerName() { _Logger?.LogInformation("Starting Web Application"); Assert.AreEqual(IAwaitingDispoController.GetRouteName(), _ControllerName); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [Ignore] @@ -46,8 +59,8 @@ public class UnitAwaitingDispoController IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService(); IEnumerable? awaitingDispositions = metrologyRepository?.GetAwaitingDisposition(); - Assert.IsTrue(awaitingDispositions is not null); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.IsNotNull(awaitingDispositions); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [Ignore] @@ -56,10 +69,10 @@ public class UnitAwaitingDispoController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(IMetrologyRepository.GetAwaitingDisposition)}Api.json"), json); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [Ignore] @@ -70,7 +83,7 @@ public class UnitAwaitingDispoController IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService(); _ = metrologyRepository?.UpdateReviewDate(toolTypeId: 1, headerId: 1, clearDate: false); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [Ignore] @@ -79,9 +92,9 @@ public class UnitAwaitingDispoController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); _ = await httpClient.GetFromJsonAsync($"api/{_ControllerName}/markasreviewed"); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [Ignore] @@ -93,7 +106,7 @@ public class UnitAwaitingDispoController IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService(); int? dateCleared = metrologyRepository?.UpdateReviewDate(toolTypeId: 1, headerId: 1, clearDate: true); Assert.IsTrue(dateCleared <= 1); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [Ignore] @@ -102,9 +115,9 @@ public class UnitAwaitingDispoController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); _ = await httpClient.PostAsync($"api/{_ControllerName}/markasawaiting", null); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -115,7 +128,7 @@ public class UnitAwaitingDispoController IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService(); Guid? guid = metrologyRepository?.GetHeaderAttachmentID(toolTypeId: 1, headerId: 1); Assert.IsNotNull(guid); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -123,10 +136,10 @@ public class UnitAwaitingDispoController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); HttpResponseMessage httpResponseMessage = await httpClient.GetAsync($"api/{_ControllerName}/1/header-attachment-id?headerid=1"); - Assert.IsNotNull(httpResponseMessage.Content); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.IsNotNull(httpResponseMessage.Content.ToString()); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } } \ No newline at end of file diff --git a/Tests/UnitInboundController.cs b/Tests/UnitInboundController.cs index e15d4e6..d24c70c 100644 --- a/Tests/UnitInboundController.cs +++ b/Tests/UnitInboundController.cs @@ -8,14 +8,14 @@ using System.Text; namespace OI.Metrology.Tests; [TestClass] -public class UnitInboundController +public class UnitInboundController : BaseTestClass { #pragma warning disable CS8618 private static ILogger? _Logger; private static string _ControllerName; - private static string? _TestContextTestName; + public TestContext TestContext { get; set; } private static WebApplicationFactory? _WebApplicationFactory; #pragma warning restore @@ -23,7 +23,6 @@ public class UnitInboundController [ClassInitialize] public static void ClassInitAsync(TestContext testContext) { - _TestContextTestName = testContext.TestName; _WebApplicationFactory = new WebApplicationFactory(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; _Logger = serviceProvider.GetRequiredService>(); @@ -37,12 +36,19 @@ public class UnitInboundController catch (Exception) { } } + [TestCleanup] + public void TestCleanup() + { + if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed) + IncrementFailedTests(); + } + [TestMethod] public void TestControllerName() { _Logger?.LogInformation("Starting Web Application"); Assert.AreEqual(IInboundController.GetRouteName(), _ControllerName); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -58,9 +64,9 @@ public class UnitInboundController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); _ = await httpClient.PostAsync($"api/{_ControllerName}/BioRad", GetStringContent()); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -70,9 +76,9 @@ public class UnitInboundController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); _ = await httpClient.PostAsync($"api/{_ControllerName}/BioRad/attachment", GetStringContent()); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } diff --git a/Tests/UnitTestAppSettingsController.cs b/Tests/UnitTestAppSettingsController.cs index d98ce3f..aaf22bb 100644 --- a/Tests/UnitTestAppSettingsController.cs +++ b/Tests/UnitTestAppSettingsController.cs @@ -8,14 +8,14 @@ using System.Net; namespace OI.Metrology.Tests; [TestClass] -public class UnitTestAppSettingsController +public class UnitTestAppSettingsController : BaseTestClass { #pragma warning disable CS8618 private static ILogger? _Logger; private static string _ControllerName; - private static string? _TestContextTestName; + public TestContext TestContext { get; set; } private static WebApplicationFactory? _WebApplicationFactory; #pragma warning restore @@ -23,7 +23,6 @@ public class UnitTestAppSettingsController [ClassInitialize] public static void ClassInitAsync(TestContext testContext) { - _TestContextTestName = testContext.TestName; _WebApplicationFactory = new WebApplicationFactory(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; _Logger = serviceProvider.GetRequiredService>(); @@ -37,23 +36,31 @@ public class UnitTestAppSettingsController catch (Exception) { } } + [TestCleanup] + public void TestCleanup() + { + if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed) + IncrementFailedTests(); + } + [TestMethod] public void TestControllerName() { _Logger?.LogInformation("Starting Web Application"); Assert.AreEqual(IAppSettingsController.GetRouteName(), _ControllerName); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } [TestMethod] + public void TestConnectionString() { _Logger?.LogInformation("Starting Web Application"); IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; - IAppSettingsRepository? appSettingsRepository = serviceProvider?.GetRequiredService>(); - appSettingsRepository?.VerifyConnectionStrings(); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + IAppSettingsRepository? appSettingsRepository = serviceProvider?.GetRequiredService>(); + _ = Assert.ThrowsException(() => appSettingsRepository?.VerifyConnectionStrings()); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -64,7 +71,7 @@ public class UnitTestAppSettingsController IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; AppSettings? appSettings = serviceProvider?.GetRequiredService(); Assert.IsNotNull(appSettings); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -73,10 +80,10 @@ public class UnitTestAppSettingsController { _Logger?.LogInformation("Starting Web Application"); IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; - IAppSettingsRepository? appSettingsRepository = serviceProvider?.GetRequiredService>(); - Server.Models.Binder.AppSettings? appSettings = appSettingsRepository?.GetAppSettings(); - Assert.IsTrue(appSettings is not null); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + IAppSettingsRepository? appSettingsRepository = serviceProvider?.GetRequiredService>(); + AppSettings? appSettings = appSettingsRepository?.GetAppSettings(); + Assert.IsNotNull(appSettings); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -85,16 +92,17 @@ public class UnitTestAppSettingsController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string actionName = nameof(IAppSettingsController.Action.App); HttpResponseMessage? httpResponseMessage = await httpClient.GetAsync($"api/{_ControllerName}/{actionName}"); Assert.AreEqual(HttpStatusCode.OK, httpResponseMessage.StatusCode); - Assert.AreEqual("application/json; charset=utf-8", httpResponseMessage.Content.Headers.ContentType?.ToString()); - string json = await httpResponseMessage.Content.ReadAsStringAsync(); + Assert.IsNotNull(httpResponseMessage.Content.Headers.ContentType); + Assert.AreEqual("application/json; charset=utf-8", httpResponseMessage.Content.Headers.ContentType.ToString()); + string? json = await httpResponseMessage.Content.ReadAsStringAsync(); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetAppSettings)}.json"), json); Assert.IsNotNull(json); - Assert.IsTrue(json != "[]"); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.AreNotEqual("[]", json); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -103,10 +111,10 @@ public class UnitTestAppSettingsController { _Logger?.LogInformation("Starting Web Application"); IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; - IAppSettingsRepository? appSettingsRepository = serviceProvider?.GetRequiredService>(); + IAppSettingsRepository? appSettingsRepository = serviceProvider?.GetRequiredService>(); string? result = appSettingsRepository?.GetBuildNumberAndGitCommitSeven(); - Assert.IsTrue(result is not null); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.IsNotNull(result); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -115,15 +123,16 @@ public class UnitTestAppSettingsController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string actionName = nameof(IAppSettingsController.Action.DevOps); HttpResponseMessage? httpResponseMessage = await httpClient.GetAsync($"api/{_ControllerName}/{actionName}"); Assert.AreEqual(HttpStatusCode.OK, httpResponseMessage.StatusCode); - Assert.AreEqual("text/plain; charset=utf-8", httpResponseMessage.Content.Headers.ContentType?.ToString()); - string json = await httpResponseMessage.Content.ReadAsStringAsync(); + Assert.IsNotNull(httpResponseMessage.Content.Headers.ContentType); + Assert.AreEqual("text/plain; charset=utf-8", httpResponseMessage.Content.Headers.ContentType.ToString()); + string? json = await httpResponseMessage.Content.ReadAsStringAsync(); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetBuildNumberAndGitCommitSeven)}.json"), json); Assert.IsNotNull(json); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } diff --git a/Tests/UnitTestClientSettingsController.cs b/Tests/UnitTestClientSettingsController.cs index a307a6a..5a8e385 100644 --- a/Tests/UnitTestClientSettingsController.cs +++ b/Tests/UnitTestClientSettingsController.cs @@ -7,14 +7,14 @@ using System.Net; namespace OI.Metrology.Tests; [TestClass] -public class UnitTestClientSettingsController +public class UnitTestClientSettingsController : BaseTestClass { #pragma warning disable CS8618 private static ILogger? _Logger; private static string _ControllerName; - private static string? _TestContextTestName; + public TestContext TestContext { get; set; } private static WebApplicationFactory? _WebApplicationFactory; #pragma warning restore @@ -22,21 +22,37 @@ public class UnitTestClientSettingsController [ClassInitialize] public static void ClassInitAsync(TestContext testContext) { - _TestContextTestName = testContext.TestName; _WebApplicationFactory = new WebApplicationFactory(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; _Logger = serviceProvider.GetRequiredService>(); _ControllerName = nameof(Server.ApiControllers.ClientSettingsController)[..^10]; } + private static void NonThrowTryCatch() + { + try + { throw new Exception(); } + catch (Exception) { } + } + + [TestCleanup] + public void TestCleanup() + { + if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed) + IncrementFailedTests(); + } + [TestMethod] public void TestControllerName() { _Logger?.LogInformation("Starting Web Application"); Assert.AreEqual(IClientSettingsController.GetRouteName(), _ControllerName); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } +#if DEBUG + [Ignore] +#endif [TestMethod] public void GetClientSettings() { @@ -45,31 +61,33 @@ public class UnitTestClientSettingsController IClientSettingsRepository? clientSettingsRepository = serviceProvider?.GetRequiredService(); #if DEBUG List? clientSettings = clientSettingsRepository?.GetClientSettings(null); - Assert.IsTrue(clientSettings is not null); + Assert.IsNotNull(clientSettings); #endif - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } -#pragma warning disable CS1998 +#if DEBUG + [Ignore] +#endif [TestMethod] public async Task GetClientSettingsApi() { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); #if DEBUG - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string actionName = nameof(IClientSettingsController.Action.Client); HttpResponseMessage httpResponseMessage = await httpClient.GetAsync($"api/{_ControllerName}/{actionName}"); Assert.AreEqual(HttpStatusCode.OK, httpResponseMessage.StatusCode); - Assert.AreEqual("application/json; charset=utf-8", httpResponseMessage.Content.Headers.ContentType?.ToString()); - string json = await httpResponseMessage.Content.ReadAsStringAsync(); + Assert.IsNotNull(httpResponseMessage.Content.Headers.ContentType); + Assert.AreEqual("application/json; charset=utf-8", httpResponseMessage.Content.Headers.ContentType.ToString()); + string? json = await httpResponseMessage.Content.ReadAsStringAsync(); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetClientSettings)}.json"), json); Assert.IsNotNull(json); - Assert.IsTrue(json != "[]"); + Assert.AreNotEqual("[]", json); #endif - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } -#pragma warning restore CS1998 [TestMethod] public void GetIpAddress() @@ -78,8 +96,8 @@ public class UnitTestClientSettingsController IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IClientSettingsRepository? clientSettingsRepository = serviceProvider?.GetRequiredService(); string? ipAddress = clientSettingsRepository?.GetIpAddress(null); - Assert.IsTrue(ipAddress is not null); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.IsNotNull(ipAddress); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -87,15 +105,16 @@ public class UnitTestClientSettingsController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string actionName = nameof(IClientSettingsController.Action.IP); HttpResponseMessage httpResponseMessage = await httpClient.GetAsync($"api/{_ControllerName}/{actionName}"); Assert.AreEqual(HttpStatusCode.OK, httpResponseMessage.StatusCode); - Assert.AreEqual("text/plain; charset=utf-8", httpResponseMessage.Content.Headers.ContentType?.ToString()); - string json = await httpResponseMessage.Content.ReadAsStringAsync(); + Assert.IsNotNull(httpResponseMessage.Content.Headers.ContentType); + Assert.AreEqual("text/plain; charset=utf-8", httpResponseMessage.Content.Headers.ContentType.ToString()); + string? json = await httpResponseMessage.Content.ReadAsStringAsync(); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetIpAddress)}.json"), json); Assert.IsNotNull(json); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } } \ No newline at end of file diff --git a/Tests/UnitTestExportController.cs b/Tests/UnitTestExportController.cs index 47c60f7..55ad491 100644 --- a/Tests/UnitTestExportController.cs +++ b/Tests/UnitTestExportController.cs @@ -9,14 +9,14 @@ using System.Text; namespace OI.Metrology.Tests; [TestClass] -public class UnitTestExportController +public class UnitTestExportController : BaseTestClass { #pragma warning disable CS8618 private static ILogger? _Logger; private static string _ControllerName; - private static string? _TestContextTestName; + public TestContext TestContext { get; set; } private static WebApplicationFactory? _WebApplicationFactory; #pragma warning restore @@ -24,7 +24,6 @@ public class UnitTestExportController [ClassInitialize] public static void ClassInitAsync(TestContext testContext) { - _TestContextTestName = testContext.TestName; _WebApplicationFactory = new WebApplicationFactory(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; _Logger = serviceProvider.GetRequiredService>(); @@ -38,12 +37,19 @@ public class UnitTestExportController catch (Exception) { } } + [TestCleanup] + public void TestCleanup() + { + if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed) + IncrementFailedTests(); + } + [TestMethod] public void TestControllerName() { _Logger?.LogInformation("Starting Web Application"); Assert.AreEqual(IExportController.GetRouteName(), _ControllerName); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -61,7 +67,7 @@ public class UnitTestExportController IExportRepository? exportRepository = serviceProvider?.GetRequiredService(); string? result = exportRepository?.GetExport(GetHeaderCommon()); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -70,11 +76,11 @@ public class UnitTestExportController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? result = await httpClient.GetStringAsync($"api/{_ControllerName}/export"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetExport)}.txt"), result); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -83,10 +89,10 @@ public class UnitTestExportController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); HttpResponseMessage httpResponseMessage = await httpClient.PostAsync($"api/{_ControllerName}/export", GetStringContent()); - Assert.IsTrue(httpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.AreEqual(System.Net.HttpStatusCode.OK, httpResponseMessage.StatusCode); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -98,7 +104,7 @@ public class UnitTestExportController IExportRepository? exportRepository = serviceProvider?.GetRequiredService(); Result? result = exportRepository?.GetHeaders(GetHeaderCommon()); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -107,12 +113,12 @@ public class UnitTestExportController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/headers"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetHeaders)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -121,10 +127,10 @@ public class UnitTestExportController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); HttpResponseMessage httpResponseMessage = await httpClient.PostAsync($"api/{_ControllerName}/headers", GetStringContent()); - Assert.IsTrue(httpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.AreEqual(System.Net.HttpStatusCode.OK, httpResponseMessage.StatusCode); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -136,7 +142,7 @@ public class UnitTestExportController IExportRepository? exportRepository = serviceProvider?.GetRequiredService(); Result? result = exportRepository?.GetLogistics(GetHeaderCommon()); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -145,12 +151,12 @@ public class UnitTestExportController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/logistics"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetLogistics)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -159,10 +165,10 @@ public class UnitTestExportController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); HttpResponseMessage httpResponseMessage = await httpClient.PostAsync($"api/{_ControllerName}/logistics", GetStringContent()); - Assert.IsTrue(httpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.AreEqual(System.Net.HttpStatusCode.OK, httpResponseMessage.StatusCode); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -174,7 +180,7 @@ public class UnitTestExportController IExportRepository? exportRepository = serviceProvider?.GetRequiredService(); string? result = exportRepository?.GetProcessDataStandardFormat(GetHeaderCommon()); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -183,11 +189,11 @@ public class UnitTestExportController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? result = await httpClient.GetStringAsync($"api/{_ControllerName}/processDataStandardFormat"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetProcessDataStandardFormat)}.pdsf"), result); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -196,10 +202,10 @@ public class UnitTestExportController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); HttpResponseMessage httpResponseMessage = await httpClient.PostAsync($"api/{_ControllerName}/processDataStandardFormat", GetStringContent()); - Assert.IsTrue(httpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.AreEqual(System.Net.HttpStatusCode.OK, httpResponseMessage.StatusCode); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -211,11 +217,11 @@ public class UnitTestExportController IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService(); IExportRepository? exportRepository = serviceProvider?.GetRequiredService(); - Assert.IsTrue(metrologyRepository is not null); + Assert.IsNotNull(metrologyRepository); Result? result = exportRepository?.GetExportData(metrologyRepository, toolTypeId: 1, datebegin: null, dateend: null); Assert.IsNotNull(result?.Results); Assert.IsNotNull(result.Results.Rows.Count > 0); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [Ignore] @@ -224,15 +230,16 @@ public class UnitTestExportController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1/export?datebegin=&dateend="); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetExportData)}.json"), json); Result? result = Newtonsoft.Json.JsonConvert.DeserializeObject>(json); Assert.IsNotNull(result?.Results); Assert.IsNotNull(result.Results.Rows.Count > 0); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } + [Ignore] [TestMethod] public void GetCSVExport() { @@ -240,10 +247,10 @@ public class UnitTestExportController IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService(); IExportRepository? exportRepository = serviceProvider?.GetRequiredService(); - Assert.IsTrue(metrologyRepository is not null); + Assert.IsNotNull(metrologyRepository); string? result = exportRepository?.GetCSVExport(metrologyRepository, toolTypeId: 1, datebegin: null, dateend: null); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [Ignore] @@ -252,11 +259,11 @@ public class UnitTestExportController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? result = await httpClient.GetStringAsync($"api/{_ControllerName}/1/csv?datebegin=&dateend="); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetCSVExport)}.csv"), result); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } } \ No newline at end of file diff --git a/Tests/UnitTestFileShareController.cs b/Tests/UnitTestFileShareController.cs index 7058f69..b8a7bd9 100644 --- a/Tests/UnitTestFileShareController.cs +++ b/Tests/UnitTestFileShareController.cs @@ -9,14 +9,14 @@ using System.Collections.ObjectModel; namespace OI.Metrology.Tests; [TestClass] -public class UnitTestFileShareController +public class UnitTestFileShareController : BaseTestClass { #pragma warning disable CS8618 private static ILogger? _Logger; private static string _ControllerName; - private static string? _TestContextTestName; + public TestContext TestContext { get; set; } private static WebApplicationFactory? _WebApplicationFactory; #pragma warning restore @@ -24,7 +24,6 @@ public class UnitTestFileShareController [ClassInitialize] public static void ClassInitAsync(TestContext testContext) { - _TestContextTestName = testContext.TestName; _WebApplicationFactory = new WebApplicationFactory(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; _Logger = serviceProvider.GetRequiredService>(); @@ -39,12 +38,19 @@ public class UnitTestFileShareController catch (Exception) { } } + [TestCleanup] + public void TestCleanup() + { + if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed) + IncrementFailedTests(); + } + [TestMethod] public void TestControllerName() { _Logger?.LogInformation("Starting Web Application"); Assert.AreEqual(IFileShareController.GetRouteName(), _ControllerName); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -54,10 +60,10 @@ public class UnitTestFileShareController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? response = await httpClient.GetStringAsync($"api/v1/file-share/copy-file/?from=\\\\mesfs.infineon.com\\EC_Metrology_Si\\MetrologyAttachments\\CDERunHeader_\\2024\\WW11\\247233\\CDE5_240315162756858.pdsf&to=\\\\messa01ec.infineon.com\\apps\\Metrology\\MET08RESIMAPCDE\\Test\\a.pdsf"); Assert.IsNotNull(response); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -67,25 +73,29 @@ public class UnitTestFileShareController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? response = await httpClient.GetStringAsync($"api/v1/file-share/move-file/?from=\\\\mesfs.infineon.com\\EC_Metrology_Si\\MetrologyAttachments\\CDERunHeader_\\2024\\WW11\\247233\\CDE5_240315162756858.pdsf&to=\\\\messa01ec.infineon.com\\apps\\Metrology\\MET08RESIMAPCDE\\Test\\a.pdsf"); Assert.IsNotNull(response); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } + [Ignore] [TestMethod] public async Task FileWriteApi() { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? response = await httpClient.GetStringAsync($"api/v1/file-share/file-write/?path=\\\\messa01ec.infineon.com\\apps\\Metrology\\MET08RESIMAPCDE\\Test\\b.pdsf&contents=b"); Assert.IsNotNull(response); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } +#if DEBUG + [Ignore] +#endif [TestMethod] public void GetArchiveData() { @@ -94,7 +104,7 @@ public class UnitTestFileShareController CharacterizationParameters characterizationParameters; IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IFileShareRepository? fileShareRepository = serviceProvider?.GetRequiredService(); - characterizationParameters = new("FQA", "FQA-8INCH", "*.wc", null, null, "8INCH"); + characterizationParameters = new("MU", "MU-6INCH", "*.wc", null, null, "6INCH"); result = fileShareRepository?.GetArchiveData(characterizationParameters); Assert.IsNotNull(result); characterizationParameters = new(string.Empty, "BIORAD4", "BIO*.json", null, null, "8INCH"); @@ -103,22 +113,28 @@ public class UnitTestFileShareController characterizationParameters = new(string.Empty, "CDE5", "CDE*.json", null, null, "8INCH"); result = fileShareRepository?.GetArchiveData(characterizationParameters); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } +#if DEBUG + [Ignore] +#endif [TestMethod] public async Task ArchiveDataApi() { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? response = await httpClient.GetStringAsync($"api/v1/file-share/archive-data/?area=FQA&equipment-id=FQA-8INCH&search-pattern=*.wc&wafer-size=8INCH"); Assert.IsNotNull(response); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } +#if DEBUG + [Ignore] +#endif [TestMethod] public void EquipmentIds() { @@ -127,19 +143,22 @@ public class UnitTestFileShareController IFileShareRepository? fileShareRepository = serviceProvider?.GetRequiredService(); ReadOnlyCollection? result = fileShareRepository?.GetEquipmentIds(); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } +#if DEBUG + [Ignore] +#endif [TestMethod] public async Task EquipmentIdsApi() { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? response = await httpClient.GetStringAsync($"api/v1/file-share/equipment-ids"); Assert.IsNotNull(response); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } diff --git a/Tests/UnitTestISpreadingResistanceProfileController.cs b/Tests/UnitTestISpreadingResistanceProfileController.cs index 6aa41f8..2b2c40b 100644 --- a/Tests/UnitTestISpreadingResistanceProfileController.cs +++ b/Tests/UnitTestISpreadingResistanceProfileController.cs @@ -6,14 +6,14 @@ using OI.Metrology.Shared.Models.Stateless; namespace OI.Metrology.Tests; [TestClass] -public class UnitTestISpreadingResistanceProfileController +public class UnitTestISpreadingResistanceProfileController : BaseTestClass { #pragma warning disable CS8618 private static ILogger? _Logger; private static string _ControllerName; - private static string? _TestContextTestName; + public TestContext TestContext { get; set; } private static WebApplicationFactory? _WebApplicationFactory; #pragma warning restore @@ -21,7 +21,6 @@ public class UnitTestISpreadingResistanceProfileController [ClassInitialize] public static void ClassInitAsync(TestContext testContext) { - _TestContextTestName = testContext.TestName; _WebApplicationFactory = new WebApplicationFactory(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; _Logger = serviceProvider.GetRequiredService>(); @@ -35,12 +34,19 @@ public class UnitTestISpreadingResistanceProfileController catch (Exception) { } } + [TestCleanup] + public void TestCleanup() + { + if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed) + IncrementFailedTests(); + } + [TestMethod] public void TestControllerName() { _Logger?.LogInformation("Starting Web Application"); Assert.AreEqual(ISpreadingResistanceProfileController.GetRouteName(), _ControllerName); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -58,11 +64,11 @@ public class UnitTestISpreadingResistanceProfileController IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; ISpreadingResistanceProfileService? spreadingResistanceProfileService = serviceProvider?.GetRequiredService(); byte[]? bytes = spreadingResistanceProfileService?.GetImageBytes(json); - Assert.IsTrue(bytes is not null); - Assert.IsTrue(bytes.Length != 0); + Assert.IsNotNull(bytes); + Assert.AreNotEqual(0, bytes.Length); File.WriteAllBytes(Path.Combine(directory, "srp.png"), bytes); } - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } diff --git a/Tests/UnitTestInfinityQSController.cs b/Tests/UnitTestInfinityQSController.cs index bbd7c0b..ab23377 100644 --- a/Tests/UnitTestInfinityQSController.cs +++ b/Tests/UnitTestInfinityQSController.cs @@ -7,14 +7,14 @@ using OI.Metrology.Shared.Models.Stateless; namespace OI.Metrology.Tests; [TestClass] -public class UnitTestInfinityQSController +public class UnitTestInfinityQSController : BaseTestClass { #pragma warning disable CS8618 private static ILogger? _Logger; private static string _ControllerName; - private static string? _TestContextTestName; + public TestContext TestContext { get; set; } private static WebApplicationFactory? _WebApplicationFactory; #pragma warning restore @@ -22,7 +22,6 @@ public class UnitTestInfinityQSController [ClassInitialize] public static void ClassInitAsync(TestContext testContext) { - _TestContextTestName = testContext.TestName; _WebApplicationFactory = new WebApplicationFactory(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; _Logger = serviceProvider.GetRequiredService>(); @@ -36,12 +35,19 @@ public class UnitTestInfinityQSController catch (Exception) { } } + [TestCleanup] + public void TestCleanup() + { + if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed) + IncrementFailedTests(); + } + [TestMethod] public void TestControllerName() { _Logger?.LogInformation("Starting Web Application"); Assert.AreEqual(IInfinityQSController.GetRouteName(), _ControllerName); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -56,7 +62,7 @@ public class UnitTestInfinityQSController IInfinityQSRepository? infinityQSRepository = serviceProvider?.GetRequiredService(); string? result = infinityQSRepository?.GetCommandText("1677273357", "61", "CDE5", "5012", "575908", ""); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -68,11 +74,11 @@ public class UnitTestInfinityQSController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/commandText/?sub_group_id=1677273357&process=61&job=CDE5&part=5012&lot=575908&date_time=2023-02-24 15:15:00"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetCommandText)}.sql"), json); Assert.IsNotNull(json); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -86,14 +92,12 @@ public class UnitTestInfinityQSController IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IInfinityQSRepository? infinityQSRepository = serviceProvider?.GetRequiredService(); Result? result = infinityQSRepository?.GetData("1677273357"); - Assert.IsNotNull(result?.Results); - Assert.IsTrue(result?.Results.Length != 0); - Assert.IsNotNull(result?.Results[0].PR_NAME); - Assert.IsNotNull(result?.Results[0].SE_SGTM); - Assert.IsNotNull(result?.Results[0].SE_TSNO); - Assert.IsNotNull(result?.Results[0].TD_NAME); - Assert.IsNotNull(result?.Results[0].TD_TEST); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Results); + Assert.IsNotNull(result.Results[0].PR_NAME); + Assert.IsNotNull(result.Results[0].TD_NAME); + Assert.AreNotEqual(0, result.Results.Length); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -105,13 +109,13 @@ public class UnitTestInfinityQSController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); //string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357 575908_2023-02-24 14-18-05.txt/data"); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357/data"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetData)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -125,11 +129,12 @@ public class UnitTestInfinityQSController IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IInfinityQSRepository? infinityQSRepository = serviceProvider?.GetRequiredService(); Result? result = infinityQSRepository?.GetDescriptors("1677273357"); - Assert.IsNotNull(result?.Results); - Assert.IsTrue(result?.Results.Length != 0); - Assert.IsNotNull(result?.Results[0].SD_SGRP); - Assert.IsNotNull(result?.Results[0].SD_TSNO); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Results); + Assert.IsNotNull(result.Results[0].SD_SGRP); + Assert.IsNotNull(result.Results[0].SD_TSNO); + Assert.AreNotEqual(0, result.Results.Length); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -141,13 +146,13 @@ public class UnitTestInfinityQSController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); //string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357 575908_2023-02-24 14-18-05.txt/descriptors"); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357/descriptors"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetDescriptors)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -162,7 +167,7 @@ public class UnitTestInfinityQSController IInfinityQSRepository? infinityQSRepository = serviceProvider?.GetRequiredService(); Result? result = infinityQSRepository?.GetEvents("1677273357"); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -174,12 +179,12 @@ public class UnitTestInfinityQSController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357/events"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetEvents)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -194,7 +199,7 @@ public class UnitTestInfinityQSController IInfinityQSRepository? infinityQSRepository = serviceProvider?.GetRequiredService(); Result? result = infinityQSRepository?.GetHeader("1677273357"); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -206,12 +211,12 @@ public class UnitTestInfinityQSController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357/header"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetHeader)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } diff --git a/Tests/UnitTestInfinityQSV2Controller.cs b/Tests/UnitTestInfinityQSV2Controller.cs index c302a31..d47a514 100644 --- a/Tests/UnitTestInfinityQSV2Controller.cs +++ b/Tests/UnitTestInfinityQSV2Controller.cs @@ -7,14 +7,14 @@ using OI.Metrology.Shared.Models.Stateless; namespace OI.Metrology.Tests; [TestClass] -public class UnitTestInfinityQSV2Controller +public class UnitTestInfinityQSV2Controller : BaseTestClass { #pragma warning disable CS8618 private static ILogger? _Logger; private static string _ControllerName; - private static string? _TestContextTestName; + public TestContext TestContext { get; set; } private static WebApplicationFactory? _WebApplicationFactory; #pragma warning restore @@ -22,7 +22,6 @@ public class UnitTestInfinityQSV2Controller [ClassInitialize] public static void ClassInitAsync(TestContext testContext) { - _TestContextTestName = testContext.TestName; _WebApplicationFactory = new WebApplicationFactory(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; _Logger = serviceProvider.GetRequiredService>(); @@ -36,12 +35,19 @@ public class UnitTestInfinityQSV2Controller catch (Exception) { } } + [TestCleanup] + public void TestCleanup() + { + if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed) + IncrementFailedTests(); + } + [TestMethod] public void TestControllerName() { _Logger?.LogInformation("Starting Web Application"); Assert.AreEqual(IInfinityQSV2Controller.GetRouteName(), _ControllerName); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -53,7 +59,7 @@ public class UnitTestInfinityQSV2Controller IInfinityQSV2Repository? infinityQSV2Repository = serviceProvider?.GetRequiredService(); string? result = infinityQSV2Repository?.GetCommandText("1677273357", "61", "CDE5", "5012", "575908", ""); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -65,11 +71,11 @@ public class UnitTestInfinityQSV2Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357/commandText/?process=61&job=CDE5&part=5012&lot=575908&date_time=2023-02-24 15:15:00"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetCommandText)}.sql"), json); Assert.IsNotNull(json); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -83,14 +89,16 @@ public class UnitTestInfinityQSV2Controller IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IInfinityQSV2Repository? infinityQSV2Repository = serviceProvider?.GetRequiredService(); Result? result = infinityQSV2Repository?.GetData("1677273357"); - Assert.IsNotNull(result?.Results); - Assert.IsTrue(result?.Results.Length != 0); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Results); + Assert.IsNotNull(result.Results[0].Process); + Assert.AreNotEqual(0, result.Results.Length); Assert.IsNotNull(result?.Results[0].Process); Assert.IsNotNull(result?.Results[0].Variable); Assert.IsNotNull(result?.Results[0].SiteNumber); Assert.IsNotNull(result?.Results[0].VariableNumber); Assert.IsNotNull(result?.Results[0].SubGroupDateTime); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -102,13 +110,13 @@ public class UnitTestInfinityQSV2Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); //string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357 575908_2023-02-24 14-18-05.txt/data"); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357/data"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetData)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -122,11 +130,12 @@ public class UnitTestInfinityQSV2Controller IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IInfinityQSV2Repository? infinityQSV2Repository = serviceProvider?.GetRequiredService(); Result? result = infinityQSV2Repository?.GetDescriptors("1677273357"); - Assert.IsNotNull(result?.Results); - Assert.IsTrue(result?.Results.Length != 0); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Results); + Assert.AreNotEqual(0, result.Results.Length); Assert.IsNotNull(result?.Results[0].SubGroupId); Assert.IsNotNull(result?.Results[0].SiteNumber); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -138,13 +147,13 @@ public class UnitTestInfinityQSV2Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); //string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357 575908_2023-02-24 14-18-05.txt/descriptors"); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357/descriptors"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetDescriptors)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -159,7 +168,7 @@ public class UnitTestInfinityQSV2Controller IInfinityQSV2Repository? infinityQSV2Repository = serviceProvider?.GetRequiredService(); Result? result = infinityQSV2Repository?.GetEvents("1677273357"); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -171,12 +180,12 @@ public class UnitTestInfinityQSV2Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357/events"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetEvents)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -192,7 +201,7 @@ public class UnitTestInfinityQSV2Controller Result? result = infinityQSV2Repository?.GetHeader("1677273357"); Assert.IsNotNull(result?.Results); Assert.IsNotNull(result?.Results[0].Part); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -204,13 +213,13 @@ public class UnitTestInfinityQSV2Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357/header"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetHeader)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); Assert.IsNotNull(result?.Results[0].Part); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } diff --git a/Tests/UnitTestInfinityQSV3Controller.cs b/Tests/UnitTestInfinityQSV3Controller.cs index 24cf8e2..108c470 100644 --- a/Tests/UnitTestInfinityQSV3Controller.cs +++ b/Tests/UnitTestInfinityQSV3Controller.cs @@ -7,14 +7,14 @@ using OI.Metrology.Shared.Models.Stateless; namespace OI.Metrology.Tests; [TestClass] -public class UnitTestInfinityQSV3Controller +public class UnitTestInfinityQSV3Controller : BaseTestClass { #pragma warning disable CS8618 private static ILogger? _Logger; private static string _ControllerName; - private static string? _TestContextTestName; + public TestContext TestContext { get; set; } private static WebApplicationFactory? _WebApplicationFactory; #pragma warning restore @@ -22,7 +22,6 @@ public class UnitTestInfinityQSV3Controller [ClassInitialize] public static void ClassInitAsync(TestContext testContext) { - _TestContextTestName = testContext.TestName; _WebApplicationFactory = new WebApplicationFactory(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; _Logger = serviceProvider.GetRequiredService>(); @@ -36,12 +35,19 @@ public class UnitTestInfinityQSV3Controller catch (Exception) { } } + [TestCleanup] + public void TestCleanup() + { + if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed) + IncrementFailedTests(); + } + [TestMethod] public void TestControllerName() { _Logger?.LogInformation("Starting Web Application"); Assert.AreEqual(IInfinityQSV3Controller.GetRouteName(), _ControllerName); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -53,7 +59,7 @@ public class UnitTestInfinityQSV3Controller IInfinityQSV3Repository? infinityQSV3Repository = serviceProvider?.GetRequiredService(); string? result = infinityQSV3Repository?.GetCommandText("1698497987", "61", "CDE5", "5012", "575908", ""); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -62,11 +68,11 @@ public class UnitTestInfinityQSV3Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1698497987/commandText/?process=61&job=CDE5&part=5012&lot=575908&date_time=2023-02-24 15:15:00"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetCommandText)}.sql"), json); Assert.IsNotNull(json); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -77,14 +83,15 @@ public class UnitTestInfinityQSV3Controller IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IInfinityQSV3Repository? infinityQSV3Repository = serviceProvider?.GetRequiredService(); Result? result = infinityQSV3Repository?.GetData("1698497987"); - Assert.IsNotNull(result?.Results); - Assert.IsTrue(result?.Results.Length != 0); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Results); + Assert.AreNotEqual(0, result.Results.Length); Assert.IsNotNull(result?.Results[0].Process); Assert.IsNotNull(result?.Results[0].Variable); Assert.IsNotNull(result?.Results[0].SiteNumber); Assert.IsNotNull(result?.Results[0].VariableNumber); Assert.IsNotNull(result?.Results[0].SubGroupDateTime); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -93,13 +100,13 @@ public class UnitTestInfinityQSV3Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); //string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1698497987 575908_2023-02-24 14-18-05.txt/data"); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1698497987/data"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetData)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -110,11 +117,12 @@ public class UnitTestInfinityQSV3Controller IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IInfinityQSV3Repository? infinityQSV3Repository = serviceProvider?.GetRequiredService(); Result? result = infinityQSV3Repository?.GetDescriptors("1698497987"); - Assert.IsNotNull(result?.Results); - Assert.IsTrue(result?.Results.Length != 0); - Assert.IsNotNull(result?.Results[0].SubGroupId); - Assert.IsNotNull(result?.Results[0].SiteNumber); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Results); + Assert.AreNotEqual(0, result.Results.Length); + Assert.IsNotNull(result.Results[0].SubGroupId); + Assert.IsNotNull(result.Results[0].SiteNumber); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -123,13 +131,13 @@ public class UnitTestInfinityQSV3Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); //string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1698497987 575908_2023-02-24 14-18-05.txt/descriptors"); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1698497987/descriptors"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetDescriptors)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -142,7 +150,7 @@ public class UnitTestInfinityQSV3Controller Result? result = infinityQSV3Repository?.GetHeader("1698497987"); Assert.IsNotNull(result?.Results); Assert.IsNotNull(result?.Results[0].Part); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -151,13 +159,13 @@ public class UnitTestInfinityQSV3Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1698497987/header"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetHeader)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); Assert.IsNotNull(result?.Results[0].Part); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -169,7 +177,7 @@ public class UnitTestInfinityQSV3Controller IInfinityQSV3Repository? infinityQSV3Repository = serviceProvider?.GetRequiredService(); string? result = infinityQSV3Repository?.GetProductDataAverageSumOfDefectsProcessMeanProcessSigma("41", "8IN_THIN ROTR"); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -178,11 +186,11 @@ public class UnitTestInfinityQSV3Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? result = await httpClient.GetStringAsync($"api/{_ControllerName}/41/product-data-average-sum-of-defects-process-mean-process-sigma?recipe=8IN_THIN ROTR"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetProductDataAverageSumOfDefectsProcessMeanProcessSigma)}.json"), result); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -195,7 +203,7 @@ public class UnitTestInfinityQSV3Controller IInfinityQSV3Repository? infinityQSV3Repository = serviceProvider?.GetRequiredService(); List? results = infinityQSV3Repository?.GetEpiProTempVerificationRows(night); Assert.IsNotNull(results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -204,11 +212,11 @@ public class UnitTestInfinityQSV3Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? result = await httpClient.GetStringAsync($"api/{_ControllerName}/epi-pro-temp-verification-rows/?night=44&night=46&night=52&night=54"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetEpiProTempVerificationRows)}.json"), result); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -221,7 +229,7 @@ public class UnitTestInfinityQSV3Controller IInfinityQSV3Repository? infinityQSV3Repository = serviceProvider?.GetRequiredService(); string? result = infinityQSV3Repository?.GetEpiProTempVerification(night); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -230,11 +238,11 @@ public class UnitTestInfinityQSV3Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? result = await httpClient.GetStringAsync($"api/{_ControllerName}/epi-pro-temp-verification/?night=44&night=46&night=52&night=54"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetEpiProTempVerification)}.html"), result); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } diff --git a/Tests/UnitTestInfinityQSV4Controller.cs b/Tests/UnitTestInfinityQSV4Controller.cs index 1c95b73..21eeb0d 100644 --- a/Tests/UnitTestInfinityQSV4Controller.cs +++ b/Tests/UnitTestInfinityQSV4Controller.cs @@ -8,14 +8,14 @@ using OI.Metrology.Shared.Models.Stateless; namespace OI.Metrology.Tests; [TestClass] -public class UnitTestInfinityQSV4Controller +public class UnitTestInfinityQSV4Controller : BaseTestClass { #pragma warning disable CS8618 private static ILogger? _Logger; private static string _ControllerName; - private static string? _TestContextTestName; + public TestContext TestContext { get; set; } private static string _ControllerVersion; private static WebApplicationFactory? _WebApplicationFactory; @@ -24,7 +24,6 @@ public class UnitTestInfinityQSV4Controller [ClassInitialize] public static void ClassInitAsync(TestContext testContext) { - _TestContextTestName = testContext.TestName; _WebApplicationFactory = new WebApplicationFactory(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; _Logger = serviceProvider.GetRequiredService>(); @@ -39,13 +38,20 @@ public class UnitTestInfinityQSV4Controller catch (Exception) { } } + [TestCleanup] + public void TestCleanup() + { + if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed) + IncrementFailedTests(); + } + [TestMethod] public void TestControllerName() { _Logger?.LogInformation("Starting Web Application"); Assert.AreEqual(IInfinityQSV4Controller.GetRouteName(), _ControllerName); Assert.AreEqual(IInfinityQSV4Controller.GetRouteVersion(), _ControllerVersion); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -57,7 +63,7 @@ public class UnitTestInfinityQSV4Controller IInfinityQSV4Repository? infinityQSV4Repository = serviceProvider?.GetRequiredService(); string? result = infinityQSV4Repository?.GetCommandText("1718539249", "61", "CDE5", "5012", "575908", ""); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -66,11 +72,11 @@ public class UnitTestInfinityQSV4Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerVersion}/{_ControllerName}/1718539249/commandText/?process=61&job=CDE5&part=5012&lot=575908&date_time=2023-02-24 15:15:00"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetCommandText)}.sql"), json); Assert.IsNotNull(json); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -81,14 +87,15 @@ public class UnitTestInfinityQSV4Controller IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IInfinityQSV4Repository? infinityQSV4Repository = serviceProvider?.GetRequiredService(); Result? result = infinityQSV4Repository?.GetData("1718539249"); - Assert.IsNotNull(result?.Results); - Assert.IsTrue(result?.Results.Length != 0); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Results); + Assert.AreNotEqual(0, result.Results.Length); Assert.IsNotNull(result?.Results[0].Process); Assert.IsNotNull(result?.Results[0].Variable); Assert.IsNotNull(result?.Results[0].SiteNumber); Assert.IsNotNull(result?.Results[0].VariableNumber); Assert.IsNotNull(result?.Results[0].SubGroupDateTime); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -97,13 +104,13 @@ public class UnitTestInfinityQSV4Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); //string? json = await httpClient.GetStringAsync($"api/{_ControllerVersion}/{_ControllerName}/1718539249 575908_2023-02-24 14-18-05.txt/data"); string? json = await httpClient.GetStringAsync($"api/{_ControllerVersion}/{_ControllerName}/1718539249/data"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetData)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -114,11 +121,12 @@ public class UnitTestInfinityQSV4Controller IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IInfinityQSV4Repository? infinityQSV4Repository = serviceProvider?.GetRequiredService(); Result? result = infinityQSV4Repository?.GetDescriptors("1718539249"); - Assert.IsNotNull(result?.Results); - Assert.IsTrue(result?.Results.Length != 0); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Results); + Assert.AreNotEqual(0, result.Results.Length); Assert.IsNotNull(result?.Results[0].SubGroupId); Assert.IsNotNull(result?.Results[0].SiteNumber); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -127,13 +135,13 @@ public class UnitTestInfinityQSV4Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); //string? json = await httpClient.GetStringAsync($"api/{_ControllerVersion}/{_ControllerName}/1718539249 575908_2023-02-24 14-18-05.txt/descriptors"); string? json = await httpClient.GetStringAsync($"api/{_ControllerVersion}/{_ControllerName}/1718539249/descriptors"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetDescriptors)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -146,7 +154,7 @@ public class UnitTestInfinityQSV4Controller Result? result = infinityQSV4Repository?.GetHeader("1718539249"); Assert.IsNotNull(result?.Results); Assert.IsNotNull(result?.Results[0].Part); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -155,13 +163,13 @@ public class UnitTestInfinityQSV4Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerVersion}/{_ControllerName}/1718539249/header"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetHeader)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); Assert.IsNotNull(result?.Results[0].Part); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -173,7 +181,7 @@ public class UnitTestInfinityQSV4Controller IInfinityQSV4Repository? infinityQSV4Repository = serviceProvider?.GetRequiredService(); string? result = infinityQSV4Repository?.GetProductDataAverageSumOfDefectsProcessMeanProcessSigma("41", "8IN_THIN ROTR"); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -182,11 +190,11 @@ public class UnitTestInfinityQSV4Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? result = await httpClient.GetStringAsync($"api/{_ControllerVersion}/{_ControllerName}/41/product-data-average-sum-of-defects-process-mean-process-sigma?recipe=8IN_THIN ROTR"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetProductDataAverageSumOfDefectsProcessMeanProcessSigma)}.json"), result); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -199,7 +207,7 @@ public class UnitTestInfinityQSV4Controller IInfinityQSV4Repository? infinityQSV4Repository = serviceProvider?.GetRequiredService(); List? results = infinityQSV4Repository?.GetEpiProTempVerificationRows(night); Assert.IsNotNull(results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -208,11 +216,11 @@ public class UnitTestInfinityQSV4Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? result = await httpClient.GetStringAsync($"api/{_ControllerVersion}/{_ControllerName}/epi-pro-temp-verification-rows/?night=44&night=46&night=52&night=54"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetEpiProTempVerificationRows)}.json"), result); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -225,7 +233,7 @@ public class UnitTestInfinityQSV4Controller IInfinityQSV4Repository? infinityQSV4Repository = serviceProvider?.GetRequiredService(); string? result = infinityQSV4Repository?.GetEpiProTempVerification(night); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -234,11 +242,11 @@ public class UnitTestInfinityQSV4Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? result = await httpClient.GetStringAsync($"api/{_ControllerVersion}/{_ControllerName}/epi-pro-temp-verification/?night=44&night=46&night=52&night=54"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetEpiProTempVerification)}.html"), result); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -250,7 +258,7 @@ public class UnitTestInfinityQSV4Controller IInfinityQSV4Repository? infinityQSV4Repository = serviceProvider?.GetRequiredService(); List? results = infinityQSV4Repository?.GetReactors(); Assert.IsNotNull(results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -266,7 +274,7 @@ public class UnitTestInfinityQSV4Controller result = infinityQSV4Repository?.GetProductionSpecification(part); Assert.IsNotNull(result); } - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -298,7 +306,7 @@ public class UnitTestInfinityQSV4Controller result = infinityQSV4Repository?.GetProductionSpecification(part); Assert.IsNotNull(result); } - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -313,7 +321,7 @@ public class UnitTestInfinityQSV4Controller IInfinityQSV4Repository? infinityQSV4Repository = serviceProvider?.GetRequiredService(); string? result = infinityQSV4Repository?.GetLastGroupIdWithValue(process, part, test); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -325,11 +333,11 @@ public class UnitTestInfinityQSV4Controller const string process = "35"; HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? result = await httpClient.GetStringAsync($"api/{_ControllerVersion}/{_ControllerName}/{process}/last-group-id-with-value/?part={part}&test={test}"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetLastGroupIdWithValue)}.html"), result); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } diff --git a/Tests/UnitTestOpenInsightV1Controller.cs b/Tests/UnitTestOpenInsightV1Controller.cs index 742d340..b0ab0ca 100644 --- a/Tests/UnitTestOpenInsightV1Controller.cs +++ b/Tests/UnitTestOpenInsightV1Controller.cs @@ -6,14 +6,14 @@ using OI.Metrology.Shared.Models.Stateless; namespace OI.Metrology.Tests; [TestClass] -public class UnitTestOpenInsightV1Controller +public class UnitTestOpenInsightV1Controller : BaseTestClass { #pragma warning disable CS8618 private static ILogger? _Logger; private static string _ControllerName; - private static string? _TestContextTestName; + public TestContext TestContext { get; set; } private static WebApplicationFactory? _WebApplicationFactory; #pragma warning restore @@ -21,7 +21,6 @@ public class UnitTestOpenInsightV1Controller [ClassInitialize] public static void ClassInitAsync(TestContext testContext) { - _TestContextTestName = testContext.TestName; _WebApplicationFactory = new WebApplicationFactory(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; _Logger = serviceProvider.GetRequiredService>(); @@ -35,12 +34,19 @@ public class UnitTestOpenInsightV1Controller catch (Exception) { } } + [TestCleanup] + public void TestCleanup() + { + if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed) + IncrementFailedTests(); + } + [TestMethod] public void TestControllerName() { _Logger?.LogInformation("Starting Web Application"); Assert.AreEqual(IOpenInsightV1Controller.GetRouteName(), _ControllerName); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -51,7 +57,7 @@ public class UnitTestOpenInsightV1Controller IOpenInsightV1Repository? openInsightRepository = serviceProvider?.GetRequiredService(); string? result = openInsightRepository?.GetTencorRun("615071", "10/30/2023 06:48:34PM", "6IN_EPP ROTR"); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -60,11 +66,11 @@ public class UnitTestOpenInsightV1Controller { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? result = await httpClient.GetStringAsync($"api/{_ControllerName}/615071/tencor-run?insert_date=10/30/2023 06:48:34PM&recipe=6IN_EPP ROTR"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetTencorRun)}.json"), result); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } diff --git a/Tests/UnitTestPinController.cs b/Tests/UnitTestPinController.cs index d861b00..e719baa 100644 --- a/Tests/UnitTestPinController.cs +++ b/Tests/UnitTestPinController.cs @@ -7,14 +7,14 @@ using OI.Metrology.Shared.Models.Stateless; namespace OI.Metrology.Tests; [TestClass] -public class UnitTestPinController +public class UnitTestPinController : BaseTestClass { #pragma warning disable CS8618 private static ILogger? _Logger; private static string _ControllerName; - private static string? _TestContextTestName; + public TestContext TestContext { get; set; } private static WebApplicationFactory? _WebApplicationFactory; #pragma warning restore @@ -22,19 +22,32 @@ public class UnitTestPinController [ClassInitialize] public static void ClassInitAsync(TestContext testContext) { - _TestContextTestName = testContext.TestName; _WebApplicationFactory = new WebApplicationFactory(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; _Logger = serviceProvider.GetRequiredService>(); _ControllerName = nameof(Server.ApiControllers.PinController)[..^10]; } + private static void NonThrowTryCatch() + { + try + { throw new Exception(); } + catch (Exception) { } + } + + [TestCleanup] + public void TestCleanup() + { + if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed) + IncrementFailedTests(); + } + [TestMethod] public void TestControllerName() { _Logger?.LogInformation("Starting Web Application"); Assert.AreEqual(IPinController.GetRouteName(), _ControllerName); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -47,7 +60,7 @@ public class UnitTestPinController Assert.IsNotNull(metrologyRepository); Result? result = pinRepository?.GetPinnedTable(metrologyRepository, id: 1, cde_id: null, biorad_id: null, rds: null); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -60,7 +73,7 @@ public class UnitTestPinController File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetPinnedTable)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } } \ No newline at end of file diff --git a/Tests/UnitTestServiceShopOrderController.cs b/Tests/UnitTestServiceShopOrderController.cs index 2571683..de2881c 100644 --- a/Tests/UnitTestServiceShopOrderController.cs +++ b/Tests/UnitTestServiceShopOrderController.cs @@ -7,14 +7,14 @@ using OI.Metrology.Shared.ViewModels; namespace OI.Metrology.Tests; [TestClass] -public class UnitTestServiceShopOrderController +public class UnitTestServiceShopOrderController : BaseTestClass { #pragma warning disable CS8618 private static ILogger? _Logger; private static string _ControllerName; - private static string? _TestContextTestName; + public TestContext TestContext { get; set; } private static WebApplicationFactory? _WebApplicationFactory; #pragma warning restore @@ -22,19 +22,32 @@ public class UnitTestServiceShopOrderController [ClassInitialize] public static void ClassInitAsync(TestContext testContext) { - _TestContextTestName = testContext.TestName; _WebApplicationFactory = new WebApplicationFactory(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; _Logger = serviceProvider.GetRequiredService>(); _ControllerName = nameof(Server.ApiControllers.ServiceShopOrderController)[..^10]; } + private static void NonThrowTryCatch() + { + try + { throw new Exception(); } + catch (Exception) { } + } + + [TestCleanup] + public void TestCleanup() + { + if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed) + IncrementFailedTests(); + } + [TestMethod] public void TestControllerName() { _Logger?.LogInformation("Starting Web Application"); Assert.AreEqual(IServiceShopOrderController.GetRouteName(), _ControllerName); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -42,9 +55,9 @@ public class UnitTestServiceShopOrderController { if (_Logger is null) throw new NullReferenceException(nameof(_Logger)); - ServiceShopOrder[] serviceShopOrders = IServiceShopOrder.GetServiceShopOrders(null); + ServiceShopOrder[]? serviceShopOrders = IServiceShopOrder.GetServiceShopOrders(null); Assert.IsNotNull(serviceShopOrders); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -54,13 +67,13 @@ public class UnitTestServiceShopOrderController ServiceShopOrder[]? serviceShopOrders; IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IServiceShopOrderRepository? serviceShopOrderRepository = serviceProvider?.GetRequiredService(); - Assert.IsTrue(serviceShopOrderRepository is not null); + Assert.IsNotNull(serviceShopOrderRepository); serviceShopOrders = await serviceShopOrderRepository.GetAllServiceShopOrders(); - Assert.IsTrue(serviceShopOrders is not null); + Assert.IsNotNull(serviceShopOrders); serviceShopOrders = await serviceShopOrderRepository.GetServiceShopOrders("23188d3d-9b75-ed11-ab8b-0050568f2fc3"); Assert.IsTrue(serviceShopOrders is not null && serviceShopOrders.Length != 0); Assert.IsNotNull(serviceShopOrders[0].ToString()); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -68,14 +81,14 @@ public class UnitTestServiceShopOrderController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string actionName = nameof(IServiceShopOrderController.Action.All); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/{actionName}"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetAllServiceShopOrders)}.json"), json); ServiceShopOrder[]? serviceShopOrders = System.Text.Json.JsonSerializer.Deserialize(json); Assert.IsNotNull(serviceShopOrders); - Assert.IsTrue(serviceShopOrders.Length != 0); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.AreNotEqual(0, serviceShopOrders.Length); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } } \ No newline at end of file diff --git a/Tests/UnitTestToolTypesController.cs b/Tests/UnitTestToolTypesController.cs index eb6f64f..2ead59c 100644 --- a/Tests/UnitTestToolTypesController.cs +++ b/Tests/UnitTestToolTypesController.cs @@ -10,14 +10,14 @@ using System.Net.Http.Json; namespace OI.Metrology.Tests; [TestClass] -public class UnitTestToolTypesController +public class UnitTestToolTypesController : BaseTestClass { #pragma warning disable CS8618 private static ILogger? _Logger; private static string _ControllerName; - private static string? _TestContextTestName; + public TestContext TestContext { get; set; } private static WebApplicationFactory? _WebApplicationFactory; #pragma warning restore @@ -25,7 +25,6 @@ public class UnitTestToolTypesController [ClassInitialize] public static void ClassInitAsync(TestContext testContext) { - _TestContextTestName = testContext.TestName; _WebApplicationFactory = new WebApplicationFactory(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; _Logger = serviceProvider.GetRequiredService>(); @@ -39,12 +38,19 @@ public class UnitTestToolTypesController catch (Exception) { } } + [TestCleanup] + public void TestCleanup() + { + if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed) + IncrementFailedTests(); + } + [TestMethod] public void TestControllerName() { _Logger?.LogInformation("Starting Web Application"); Assert.AreEqual(IToolTypesController.GetRouteName(), _ControllerName); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -54,12 +60,12 @@ public class UnitTestToolTypesController IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService(); IToolTypesRepository? toolTypesRepository = serviceProvider?.GetRequiredService(); - Assert.IsTrue(metrologyRepository is not null); + Assert.IsNotNull(metrologyRepository); Result? result = toolTypesRepository?.Index(metrologyRepository); Assert.IsNotNull(result?.Results); - Assert.IsTrue(result.Results.Length != 0); + Assert.AreNotEqual(0, result.Results.Length); Assert.IsFalse(result.Results.All(l => l.ID == 0)); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -67,14 +73,14 @@ public class UnitTestToolTypesController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(Index)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); - Assert.IsTrue(result.Results.Length != 0); + Assert.AreNotEqual(0, result.Results.Length); Assert.IsFalse(result.Results.All(l => l.ID == 0)); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -84,13 +90,13 @@ public class UnitTestToolTypesController IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService(); IToolTypesRepository? toolTypesRepository = serviceProvider?.GetRequiredService(); - Assert.IsTrue(metrologyRepository is not null); + Assert.IsNotNull(metrologyRepository); Result? result = toolTypesRepository?.GetToolTypeMetadata(metrologyRepository, id: 1, sortby: string.Empty); Assert.IsNotNull(result?.Results); Assert.IsNotNull(result.Results.Metadata); - Assert.IsTrue(result.Results.Metadata.Length != 0); + Assert.AreNotEqual(0, result.Results.Metadata.Length); Assert.IsFalse(result.Results.Metadata.All(l => l.ToolTypeID == 0)); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -98,15 +104,15 @@ public class UnitTestToolTypesController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetToolTypeMetadata)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); Assert.IsNotNull(result.Results.Metadata); - Assert.IsTrue(result.Results.Metadata.Length != 0); + Assert.AreNotEqual(0, result.Results.Metadata.Length); Assert.IsFalse(result.Results.Metadata.All(l => l.ToolTypeID == 0)); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -116,11 +122,11 @@ public class UnitTestToolTypesController IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService(); IToolTypesRepository? toolTypesRepository = serviceProvider?.GetRequiredService(); - Assert.IsTrue(metrologyRepository is not null); + Assert.IsNotNull(metrologyRepository); Result? result = toolTypesRepository?.GetHeaders(metrologyRepository, id: 1, datebegin: null, dateend: null, page: null, pagesize: null, headerid: null); Assert.IsNotNull(result?.Results); Assert.IsNotNull(result.Results.Rows.Count > 0); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -128,13 +134,13 @@ public class UnitTestToolTypesController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1/headers"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetHeaders)}.json"), json); Result? result = Newtonsoft.Json.JsonConvert.DeserializeObject>(json); Assert.IsNotNull(result?.Results); Assert.IsNotNull(result.Results.Rows.Count > 0); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -144,11 +150,12 @@ public class UnitTestToolTypesController IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService(); IToolTypesRepository? toolTypesRepository = serviceProvider?.GetRequiredService(); - Assert.IsTrue(metrologyRepository is not null); + Assert.IsNotNull(metrologyRepository); Result? result = toolTypesRepository?.GetHeaderTitles(metrologyRepository, id: -1, page: null, pagesize: null); - Assert.IsNotNull(result?.Results); - Assert.IsTrue(result?.Results.Length != 0); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Results); + Assert.AreNotEqual(0, result.Results.Length); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -156,13 +163,13 @@ public class UnitTestToolTypesController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/-1/headertitles"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetHeaderTitles)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); - Assert.IsTrue(result.Results.Length != 0); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.AreNotEqual(0, result.Results.Length); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -172,11 +179,11 @@ public class UnitTestToolTypesController IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService(); IToolTypesRepository? toolTypesRepository = serviceProvider?.GetRequiredService(); - Assert.IsTrue(metrologyRepository is not null); + Assert.IsNotNull(metrologyRepository); Result? result = toolTypesRepository?.GetHeaderFields(metrologyRepository, id: 1, headerid: 1); Assert.IsNotNull(result?.Results); - Assert.IsTrue(result.Results.Length != 0); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.AreNotEqual(0, result.Results.Length); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -184,13 +191,13 @@ public class UnitTestToolTypesController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1/headers/1/fields"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetHeaderFields)}.json"), json); Result? result = System.Text.Json.JsonSerializer.Deserialize>(json); Assert.IsNotNull(result?.Results); - Assert.IsTrue(result.Results.Length != 0); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.AreNotEqual(0, result.Results.Length); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -200,11 +207,11 @@ public class UnitTestToolTypesController IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService(); IToolTypesRepository? toolTypesRepository = serviceProvider?.GetRequiredService(); - Assert.IsTrue(metrologyRepository is not null); + Assert.IsNotNull(metrologyRepository); Result? result = toolTypesRepository?.GetData(metrologyRepository, id: 1, headerid: 1); Assert.IsNotNull(result?.Results); Assert.IsNotNull(result.Results.Rows.Count > 0); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [TestMethod] @@ -212,13 +219,13 @@ public class UnitTestToolTypesController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1/headers/1/data"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetData)}.json"), json); Result? result = Newtonsoft.Json.JsonConvert.DeserializeObject>(json); Assert.IsNotNull(result?.Results); Assert.IsNotNull(result.Results.Rows.Count > 0); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [Ignore] @@ -227,19 +234,19 @@ public class UnitTestToolTypesController { _Logger?.LogInformation("Starting Web Application"); int toolTypeId = 1; - string tabletype = "data"; + string tableType = "data"; string filename = "data.txt"; string attachmentId = "ffdf5410-ca19-4097-bfa4-b398e236d07e"; IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IAttachmentsService? attachmentsService = serviceProvider?.GetRequiredService(); IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService(); IToolTypesRepository? toolTypesRepository = serviceProvider?.GetRequiredService(); - Assert.IsTrue(attachmentsService is not null); - Assert.IsTrue(metrologyRepository is not null); - Assert.IsTrue(toolTypesRepository is not null); - (string? message, string? _, Stream? _) = toolTypesRepository.GetAttachment(metrologyRepository, attachmentsService, toolTypeId, tabletype, attachmentId, filename); - Assert.IsTrue(message is null); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.IsNotNull(attachmentsService); + Assert.IsNotNull(metrologyRepository); + Assert.IsNotNull(toolTypesRepository); + (string? message, string? _, Stream? _) = toolTypesRepository.GetAttachment(metrologyRepository, attachmentsService, toolTypeId, tableType, attachmentId, filename); + Assert.IsNull(message); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [Ignore] @@ -248,9 +255,9 @@ public class UnitTestToolTypesController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); _ = await httpClient.GetFromJsonAsync($"api/{_ControllerName}/1/data/files/ffdf5410-ca19-4097-bfa4-b398e236d07e/data.txt"); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [Ignore] @@ -263,12 +270,12 @@ public class UnitTestToolTypesController IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService(); IToolTypesRepository? toolTypesRepository = serviceProvider?.GetRequiredService(); Server.Models.AppSettings? appSettings = serviceProvider?.GetRequiredService(); - Assert.IsTrue(appSettings is not null); - Assert.IsTrue(attachmentsService is not null); - Assert.IsTrue(metrologyRepository is not null); + Assert.IsNotNull(appSettings); + Assert.IsNotNull(attachmentsService); + Assert.IsNotNull(metrologyRepository); string? message = toolTypesRepository?.OIExport(metrologyRepository, attachmentsService, toolTypeId: 1, headerid: 1); - Assert.IsTrue(message is null); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.IsNull(message); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } [Ignore] @@ -277,9 +284,9 @@ public class UnitTestToolTypesController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); _ = await httpClient.GetFromJsonAsync($"api/{_ControllerName}/1/headers/1/export"); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); } } \ No newline at end of file diff --git a/Tests/UnitTestWaferCounterController.cs b/Tests/UnitTestWaferCounterController.cs index 98cfcc4..fe74b05 100644 --- a/Tests/UnitTestWaferCounterController.cs +++ b/Tests/UnitTestWaferCounterController.cs @@ -7,14 +7,14 @@ using OI.Metrology.Shared.Models.Stateless; namespace OI.Metrology.Tests; [TestClass] -public class UnitTestWaferCounterController +public class UnitTestWaferCounterController : BaseTestClass { #pragma warning disable CS8618 private static ILogger? _Logger; private static string _ControllerName; - private static string? _TestContextTestName; + public TestContext TestContext { get; set; } private static WebApplicationFactory? _WebApplicationFactory; #pragma warning restore @@ -22,7 +22,6 @@ public class UnitTestWaferCounterController [ClassInitialize] public static void ClassInitAsync(TestContext testContext) { - _TestContextTestName = testContext.TestName; _WebApplicationFactory = new WebApplicationFactory(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; _Logger = serviceProvider.GetRequiredService>(); @@ -36,12 +35,19 @@ public class UnitTestWaferCounterController catch (Exception) { } } + [TestCleanup] + public void TestCleanup() + { + if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed) + IncrementFailedTests(); + } + [TestMethod] public void TestControllerName() { _Logger?.LogInformation("Starting Web Application"); - Assert.AreEqual(IFileShareController.GetRouteName(), _ControllerName); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + Assert.AreEqual(IWaferCounterController.GetRouteName(), _ControllerName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -54,7 +60,7 @@ public class UnitTestWaferCounterController IWaferCounterRepository? waferCounterRepository = serviceProvider?.GetRequiredService(); WaferCounter? result = waferCounterRepository?.GetLastQuantityAndSlotMap(area: "FQA", waferSize: "8INCH", text: "Test"); Assert.IsNotNull(result); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } @@ -64,10 +70,10 @@ public class UnitTestWaferCounterController { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); - Assert.IsTrue(httpClient is not null); + Assert.IsNotNull(httpClient); string? response = await httpClient.GetStringAsync($"api/v1/{_ControllerName}/FQA/last-quantity-and-slot-map/?waferSize=8INCH&text=Test"); Assert.IsNotNull(response); - _Logger?.LogInformation("{TestName} completed", _TestContextTestName); + _Logger?.LogInformation("{TestName} completed", TestContext.TestName); NonThrowTryCatch(); } diff --git a/Wafer-Counter/.vscode/launch.json b/Wafer-Counter/.vscode/launch.json index 9937495..960a435 100644 --- a/Wafer-Counter/.vscode/launch.json +++ b/Wafer-Counter/.vscode/launch.json @@ -8,7 +8,7 @@ "name": ".NET Core Launch (web)", "type": "coreclr", "request": "launch", - "preLaunchTask": "build", + "preLaunchTask": "Build", // If you have changed target frameworks, make sure to update the program path. "program": "${workspaceFolder}/bin/Debug/net8.0/OI.Metrology.Wafer.Counter.dll", "args": [], diff --git a/Wafer-Counter/.vscode/tasks.json b/Wafer-Counter/.vscode/tasks.json index 810ef90..bbf693f 100644 --- a/Wafer-Counter/.vscode/tasks.json +++ b/Wafer-Counter/.vscode/tasks.json @@ -1,70 +1,167 @@ { - "version": "2.0.0", + "inputs": [ + { + "default": "Development", + "description": "Which ASP Net Core Environment?", + "id": "ASPNETCORE_ENVIRONMENT", + "options": [ + "Development", + "Production" + ], + "type": "pickString" + }, + { + "default": "${input:AssemblyTitle}", + "description": "What Assembly Title?", + "id": "AssemblyTitle", + "type": "promptString" + }, + { + "default": "{Build.BuildId}", + "description": "Which Build BuildId?", + "id": "Build.BuildId", + "type": "promptString" + }, + { + "default": "{Build.Reason}", + "description": "Which Build Reason?", + "id": "Build.Reason", + "type": "promptString" + }, + { + "default": "{Build.Repository.Id}", + "description": "Which Build Repository Id?", + "id": "Build.Repository.Id", + "type": "promptString" + }, + { + "default": "{Build.Repository.Name}", + "description": "Which Build Repository Name?", + "id": "Build.Repository.Name", + "type": "promptString" + }, + { + "default": "{Build.SourceVersion}", + "description": "Which Build Source Version?", + "id": "Build.SourceVersion", + "type": "promptString" + }, + { + "default": "Debug", + "description": "Which Configuration?", + "id": "Configuration", + "options": [ + "Debug", + "Release" + ], + "type": "pickString" + }, + { + "default": "net8.0", + "description": "Which Core Version?", + "id": "CoreVersion", + "options": [ + "net8.0" + ], + "type": "pickString" + }, + { + "default": "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/MSBuild/Current/Bin/MSBuild.exe", + "description": "Which MS Build?", + "id": "MSBuild", + "type": "promptString" + }, + { + "default": "https://artifactory.intra.infineon.com/artifactory/api/nuget/ngt-fi-package-main-vir/", + "description": "Which Nuget Source?", + "id": "NugetSource", + "type": "promptString" + }, + { + "default": "win-x64", + "description": "Which Runtime?", + "id": "Runtime", + "options": [ + "win-x64", + "win-x32", + "linux-x64", + "linux-x32" + ], + "type": "pickString" + }, + { + "default": "L:/", + "description": "Which System DefaultWorkingDirectory?", + "id": "System.DefaultWorkingDirectory", + "options": [ + "L:/", + "D:/", + "C:/" + ], + "type": "pickString" + }, + { + "default": "v4.8", + "description": "Which Core Target Framework Version?", + "id": "TargetFrameworkVersion", + "options": [ + "v4.8" + ], + "type": "pickString" + } + ], "tasks": [ { - "label": "dotnetRunDebug", "command": "dotnet OI.Metrology.Wafer.Counter.dll", - "dependsOn": "build", - "problemMatcher": [], - "type": "shell", + "label": "Dotnet Run Debug", "options": { - "cwd": "${workspaceFolder}/bin/Debug/net8.0" - } + "cwd": "${workspaceFolder}/bin/Debug/net8.0" + }, + "problemMatcher": [], + "type": "shell" }, { - "label": "build", + "args": [ + "build" + ], "command": "dotnet", - "type": "process", + "label": "Build", + "problemMatcher": "$msCompile", + "type": "process" + }, + { "args": [ "build", - "${workspaceFolder}/OI.Metrology.Wafer.Counter.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" + "${workspaceFolder}/../Tests/OI.Metrology.Tests.csproj" ], - "problemMatcher": "$msCompile" + "command": "dotnet", + "label": "Build Tests", + "problemMatcher": "$msCompile", + "type": "process" }, { - "label": "buildTests", - "command": "dotnet", - "type": "process", "args": [ - "build", - "${workspaceFolder}/../Tests/OI.Metrology.Tests.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" + "test", + "${workspaceFolder}/../Tests/OI.Metrology.Tests.csproj" ], - "problemMatcher": "$msCompile" + "command": "dotnet", + "label": "Test Debug", + "problemMatcher": "$msCompile", + "type": "process" }, { - "label": "testDebug", - "command": "dotnet", - "type": "process", "args": [ "test", "${workspaceFolder}/../Tests/OI.Metrology.Tests.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "testRelease", - "command": "dotnet", - "type": "process", - "args": [ - "test", - "${workspaceFolder}/../Tests/OI.Metrology.Tests.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary", "-c", "Release" ], - "problemMatcher": "$msCompile" + "command": "dotnet", + "label": "Test Release", + "problemMatcher": "$msCompile", + "type": "process" }, { - "label": "Format", - "command": "dotnet", - "type": "process", "args": [ "format", "--report", @@ -74,27 +171,24 @@ "--severity", "warn" ], - "problemMatcher": "$msCompile" + "command": "dotnet", + "label": "Format", + "problemMatcher": "$msCompile", + "type": "process" }, { - "label": "Format-Whitespace", - "command": "dotnet", - "type": "process", "args": [ "format", "whitespace" ], - "problemMatcher": "$msCompile" + "command": "dotnet", + "label": "Format Whitespace", + "problemMatcher": "$msCompile", + "type": "process" }, { - "label": "publish", - "command": "dotnet", - "type": "process", "args": [ "publish", - "${workspaceFolder}/OI.Metrology.Wafer.Counter.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary", "--configuration", "Release", "--runtime", @@ -103,17 +197,14 @@ "-o", "D:/web-sites/OI-Metrology/oo-8e5dd137-_______-OI-Metrology-Release/Wafer-Counter" ], - "problemMatcher": "$msCompile" + "command": "dotnet", + "label": "Publish", + "problemMatcher": "$msCompile", + "type": "process" }, { - "label": "Publish AOT", - "command": "dotnet", - "type": "process", "args": [ "publish", - "${workspaceFolder}/OI.Metrology.Wafer.Counter.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary", "--configuration", "Release", "--runtime", @@ -121,53 +212,206 @@ "-p:PublishAot=true", "/property:GenerateFullPaths=true" ], - "problemMatcher": "$msCompile" + "command": "dotnet", + "label": "Publish AOT", + "problemMatcher": "$msCompile", + "type": "process" }, { - "label": "old-watch", - "command": "dotnet", - "type": "process", "args": [ "watch", - "run", - "--project", - "${workspaceFolder}/OI.Metrology.Wafer.Counter.csproj" + "run" ], - "problemMatcher": "$msCompile" + "command": "dotnet", + "label": "Old Watch", + "problemMatcher": "$msCompile", + "type": "process" }, { - "label": "watch", - "command": "dotnet", - "type": "process", "args": [ "watch", "--launch-profile", "http", "run", - "--project", - "${workspaceFolder}/OI.Metrology.Wafer.Counter.csproj", "--verbose" ], - "isBackground": true, + "command": "dotnet", "dependsOn": [ - "build" + "Build" ], + "isBackground": true, + "label": "Watch", "problemMatcher": { - "fileLocation": "relative", - "pattern": { - "regexp": "^([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\):\\s+(error|warning|info)\\s+(TS\\d+)\\s*:\\s*(.*)$", - "file": 1, - "location": 2, - "severity": 3, - "code": 4, - "message": 5 - }, "background": { "activeOnStart": true, "beginsPattern": "^.*Shutdown requested.*", "endsPattern": "^.*Application started.*" + }, + "fileLocation": "relative", + "pattern": { + "code": 4, + "file": 1, + "location": 2, + "message": 5, + "regexp": "^([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\):\\s+(error|warning|info)\\s+(TS\\d+)\\s*:\\s*(.*)$", + "severity": 3 } - } + }, + "type": "process" + }, + { + "command": "echo Assembly Title: ${input:AssemblyTitle} & echo Build Id: ${input:Build.BuildId} & echo Build Reason: ${input:Build.Reason} & echo Repo Id: ${input:Build.Repository.Id} & echo Repo Name: ${input:Build.Repository.Name} & echo Source Version: ${input:Build.SourceVersion} & echo Configuration: ${input:Configuration} & echo Core Version: ${input:CoreVersion} & echo Nuget Source: ${input:NugetSource} & echo Runtime: ${input:Runtime}", + "label": "Echo Check", + "problemMatcher": [], + "type": "shell" + }, + { + "command": "dotnet user-secrets init & dotnet user-secrets set BuildNumber ${input:Build.BuildId} & dotnet user-secrets set GitCommit ${input:Build.SourceVersion} & dotnet user-secrets list", + "label": "Server - Safe storage of app secrets", + "problemMatcher": [], + "type": "shell" + }, + { + "args": [ + "build", + "--configuration", + "${input:Configuration}", + "--source", + "${input:NugetSource}" + ], + "command": "dotnet", + "label": "Wafer Counter - Build", + "problemMatcher": "$msCompile", + "type": "process" + }, + { + "args": [ + "build", + "${workspaceFolder}/../Tests/OI.Metrology.Tests.csproj", + "--configuration", + "${input:Configuration}", + "--source", + "${input:NugetSource}" + ], + "command": "dotnet", + "label": "Tests - Build", + "problemMatcher": "$msCompile", + "type": "process" + }, + { + "args": [ + "test", + "${workspaceFolder}/../Tests/OI.Metrology.Tests.csproj", + "--configuration", + "${input:Configuration}" + ], + "command": "dotnet", + "label": "Tests - Test", + "problemMatcher": "$msCompile", + "type": "process" + }, + { + "args": [ + "publish", + "--configuration", + "${input:Configuration}", + "--runtime", + "${input:Runtime}", + "--self-contained" + ], + "command": "dotnet", + "label": "Wafer-Counter - Publish", + "problemMatcher": "$msCompile", + "type": "process" + }, + { + "args": [ + "publish", + "--configuration", + "${input:Configuration}", + "--runtime", + "${input:Runtime}", + "-p:PublishAot=true" + ], + "command": "dotnet", + "label": "Wafer-Counter - AOT Publish", + "problemMatcher": "$msCompile", + "type": "process" + }, + { + "command": "(robocopy /MIR \"bin/${input:Configuration}/${input:CoreVersion}/${input:Runtime}/publish\" \"D:/${input:CoreVersion}/${input:Runtime}/${input:Build.Repository.Name}/${input:Build.BuildId}/${input:Configuration}-${input:AssemblyTitle}-AOT\") ^& IF %ERRORLEVEL% LEQ 7 exit 0", + "label": "Copy Files to: D:/", + "problemMatcher": [], + "type": "shell" + }, + { + "args": [ + "tool", + "restore" + ], + "command": "dotnet", + "label": "Tool Restore", + "problemMatcher": [], + "type": "process" + }, + { + "args": [ + "ReportGenerator", + "-reports:${input:System.DefaultWorkingDirectory}/TestResults/**/coverage.cobertura.xml", + "-targetDir:${input:Build.ArtifactStagingDirectory}/Coverage", + "-reportTypes:Html_Dark" + ], + "command": "dotnet", + "label": "Report Generator", + "problemMatcher": [], + "type": "process" + }, + { + "args": [ + "clean", + "${workspaceFolder}/../Tests/OI.Metrology.Tests.csproj", + "--configuration", + "${input:Configuration}" + ], + "command": "dotnet", + "label": "Tests - Clean", + "problemMatcher": "$msCompile", + "type": "process" + }, + { + "args": [ + "clean", + "--configuration", + "${input:Configuration}" + ], + "command": "dotnet", + "label": "Wafer Counter - Clean", + "problemMatcher": "$msCompile", + "type": "process" + }, + { + "args": [ + "Wafer-Counter - Publish", + "Tool Restore", + "Report Generator" + ], + "command": "echo", + "dependsOn": [ + "Echo Check", + "Server - Safe storage of app secrets", + "Wafer Counter - Build", + "Tests - Build", + "Tests - Test", + "Wafer-Counter - AOT Publish", + "Copy Files to: D:/", + "Tests - Clean", + "Wafer Counter - Clean" + ], + "dependsOrder": "sequence", + "label": "Pipeline", + "problemMatcher": [], + "type": "shell" } - ] + ], + "version": "2.0.0" } \ No newline at end of file diff --git a/Wafer-Counter/ApiControllers/AzureDevOpsController.cs b/Wafer-Counter/ApiControllers/AzureDevOpsController.cs deleted file mode 100644 index 814ac6f..0000000 --- a/Wafer-Counter/ApiControllers/AzureDevOpsController.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using OI.Metrology.Shared.Models; -using OI.Metrology.Shared.Models.Stateless; -using OI.Metrology.Wafer.Counter.Helper; - -namespace OI.Metrology.Wafer.Counter.ApiControllers; - -[Route("api/v1/ado")] -public class AzureDevOpsController : Controller, IAzureDevOpsController -{ - - private readonly IAzureDevOpsRepository _AzureDevOpsRepository; - - public AzureDevOpsController(IAzureDevOpsRepository azureDevOpsRepository) => - _AzureDevOpsRepository = azureDevOpsRepository; - - [HttpPost("save")] - public IResult Save() - { - PollValue? pollValue = ParameterHelper.GetPollValue(Request.HttpContext.Connection?.RemoteIpAddress, Request.Body); - ArgumentNullException.ThrowIfNull(pollValue); - _AzureDevOpsRepository.Save(pollValue); - return Results.Ok(); - } - -} \ No newline at end of file diff --git a/Wafer-Counter/Helper/ParameterHelper.cs b/Wafer-Counter/Helper/ParameterHelper.cs index 38e7b5b..fd12812 100644 --- a/Wafer-Counter/Helper/ParameterHelper.cs +++ b/Wafer-Counter/Helper/ParameterHelper.cs @@ -2,6 +2,7 @@ using OI.Metrology.Shared.Models; using System.Collections.Specialized; using System.Net; using System.Text.Json; +using System.Text.Json.Serialization; using System.Web; namespace OI.Metrology.Wafer.Counter.Helper; @@ -29,7 +30,9 @@ public class ParameterHelper { CharacterizationParameters? result; Dictionary keyValuePairs = GetKeyValuePairs(queryString); - string json = JsonSerializer.Serialize(keyValuePairs, new JsonSerializerOptions() { WriteIndented = true }); +#pragma warning disable CS8620 + string json = JsonSerializer.Serialize(keyValuePairs, DictionaryStringStringSourceGenerationContext.Default.DictionaryStringString); +#pragma warning restore CS8620 result = string.IsNullOrEmpty(json) ? null : JsonSerializer.Deserialize(json, CharacterizationParametersSourceGenerationContext.Default.CharacterizationParameters); return result; } @@ -68,7 +71,9 @@ public class ParameterHelper PollValue? result; string? queryString = GetQueryString(stream); Dictionary keyValuePairs = GetKeyValuePairs(queryString); - string json = JsonSerializer.Serialize(keyValuePairs, new JsonSerializerOptions() { WriteIndented = true }); +#pragma warning disable CS8620 + string json = JsonSerializer.Serialize(keyValuePairs, DictionaryStringStringSourceGenerationContext.Default.DictionaryStringString); +#pragma warning restore CS8620 result = string.IsNullOrEmpty(json) ? null : JsonSerializer.Deserialize(json, PollValueSourceGenerationContext.Default.PollValue); if (result is not null) { @@ -79,4 +84,10 @@ public class ParameterHelper return result; } +} + +[JsonSourceGenerationOptions(WriteIndented = true)] +[JsonSerializable(typeof(Dictionary))] +public partial class DictionaryStringStringSourceGenerationContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/Wafer-Counter/Models/AppSettings.cs b/Wafer-Counter/Models/AppSettings.cs index 9defb48..6dcf3ab 100644 --- a/Wafer-Counter/Models/AppSettings.cs +++ b/Wafer-Counter/Models/AppSettings.cs @@ -3,8 +3,7 @@ using System.Text.Json.Serialization; namespace OI.Metrology.Wafer.Counter.Models; -public record AppSettings(string AzureDevOpsDestinationDirectory, - string BuildNumber, +public record AppSettings(string BuildNumber, string Company, string EcCharacterizationSi, string EcMesaFileShareCharacterizationSi, @@ -37,7 +36,7 @@ public record AppSettings(string AzureDevOpsDestinationDirectory, public static AppSettings Get(IConfigurationRoot configurationRoot) { AppSettings result; - AppSettings? appSettings = configurationRoot.GetSection(nameof(AppSettings)).Get(); + AppSettings? appSettings = configurationRoot.Get(); #pragma warning restore IL3050, IL2026 if (appSettings is null || appSettings?.Company is null) @@ -53,8 +52,7 @@ public record AppSettings(string AzureDevOpsDestinationDirectory, } throw new NotSupportedException($"Not found!{Environment.NewLine}{string.Join(Environment.NewLine, paths.Distinct())}"); } - result = new(appSettings.AzureDevOpsDestinationDirectory, - appSettings.BuildNumber, + result = new(appSettings.BuildNumber, appSettings.Company, appSettings.EcCharacterizationSi, appSettings.EcMesaFileShareCharacterizationSi, diff --git a/Wafer-Counter/Program.cs b/Wafer-Counter/Program.cs index 19e5638..687577c 100644 --- a/Wafer-Counter/Program.cs +++ b/Wafer-Counter/Program.cs @@ -27,7 +27,6 @@ public class Program _ = webApplicationBuilder.Services.AddHttpClient(); _ = webApplicationBuilder.Services.AddSingleton(_ => appSettings); _ = webApplicationBuilder.Services.AddSingleton(); - _ = webApplicationBuilder.Services.AddSingleton(); _ = webApplicationBuilder.Services.AddSingleton(); _ = webApplicationBuilder.Services.AddSingleton>(_ => appSettingsRepository); diff --git a/Wafer-Counter/Repositories/AzureDevOpsRepository.cs b/Wafer-Counter/Repositories/AzureDevOpsRepository.cs deleted file mode 100644 index cf4a597..0000000 --- a/Wafer-Counter/Repositories/AzureDevOpsRepository.cs +++ /dev/null @@ -1,25 +0,0 @@ -using OI.Metrology.Shared.Models; -using OI.Metrology.Shared.Models.Stateless; -using OI.Metrology.Wafer.Counter.Models; - -namespace OI.Metrology.Wafer.Counter.Repository; - -public class AzureDevOpsRepository : IAzureDevOpsRepository -{ - - private readonly AppSettings _AppSettings; - - public AzureDevOpsRepository(AppSettings appSettings) => - _AppSettings = appSettings; - - void IAzureDevOpsRepository.Save(PollValue pollValue) - { - ArgumentNullException.ThrowIfNull(pollValue.Id); - ArgumentNullException.ThrowIfNull(pollValue.Page); - string directory = Path.Combine(_AppSettings.AzureDevOpsDestinationDirectory, pollValue.Page, pollValue.Id.Value.ToString()); - if (!Directory.Exists(directory)) - _ = Directory.CreateDirectory(directory); - File.WriteAllText(Path.Combine(directory, $"{pollValue.Time}.json"), pollValue.Json is null ? string.Empty : pollValue.Json); - } - -} \ No newline at end of file diff --git a/Wafer-Counter/Repositories/FileShareRepository.cs b/Wafer-Counter/Repositories/FileShareRepository.cs index 68ab648..ef6c491 100644 --- a/Wafer-Counter/Repositories/FileShareRepository.cs +++ b/Wafer-Counter/Repositories/FileShareRepository.cs @@ -107,7 +107,7 @@ public class FileShareRepository : IFileShareRepository private static ReadOnlyCollection GetValidDirectories(string equipmentDirectory, DateTime startDateTime, DateTime endDateTime) { - List results = []; + List results = [equipmentDirectory]; DateTime dateTime; string weekOfYear; Calendar calendar = new CultureInfo("en-US").Calendar; diff --git a/Wafer-Counter/wafer-counter-pipeline.yml b/Wafer-Counter/wafer-counter-pipeline.yml new file mode 100644 index 0000000..1da7876 --- /dev/null +++ b/Wafer-Counter/wafer-counter-pipeline.yml @@ -0,0 +1,158 @@ +trigger: + branches: + include: + - master + paths: + include: + - Shared + - Wafer-Counter + +variables: + runtime: 'win-x64' + coreVersion: 'net8.0' + nugetSource: 'https://artifactory.intra.infineon.com/artifactory/api/nuget/ngt-fi-package-main-vir/' + +stages: + - stage: Development + displayName: Development + pool: + name: 'OpenInsight Metrology Viewer' + demands: OpenInsight-Metrology-Viewer-Wafer-Counter-Development + variables: + ASPNETCORE_ENVIRONMENT: 'Development' + assemblyTitle: 'OI.Metrology.Wafer.Counter' + configuration: 'Debug' + jobs: + - job: DebugDotnet + steps: + - script: | + echo Assembly Title: $(AssemblyTitle) + echo Build Id: $(Build.BuildId) + echo Build Reason: $(Build.Reason) + echo Repo Id: $(Build.Repository.Id) + echo Repo Name: $(Build.Repository.Name) + echo Source Version: $(Build.SourceVersion) + echo Configuration: $(Configuration) + echo Core Version: $(CoreVersion) + echo Nuget Source: $(NugetSource) + echo Runtime: $(Runtime) + displayName: 'Echo Check' + + - script: | + dotnet user-secrets init + dotnet user-secrets set BuildNumber $(Build.BuildId) + dotnet user-secrets set GitCommit $(Build.SourceVersion) + dotnet user-secrets list + workingDirectory: Wafer-Counter + displayName: 'Wafer Counter - Safe storage of app secrets' + + - script: dotnet build --configuration $(Configuration) --source $(NugetSource) + workingDirectory: Wafer-Counter + displayName: 'Wafer Counter - Build' + + - script: dotnet build --configuration $(Configuration) --source $(NugetSource) + workingDirectory: Tests + displayName: 'Tests - Build' + + - script: dotnet test --configuration $(Configuration) + workingDirectory: Tests + displayName: 'Tests - Test' + + - script: dotnet publish --configuration $(Configuration) + workingDirectory: Wafer-Counter + displayName: 'Wafer-Counter - Publish' + enabled: false + + - script: dotnet publish --configuration $(Configuration) --runtime $(Runtime) -p:PublishAot=true + workingDirectory: Wafer-Counter + displayName: 'Wafer-Counter - AOT Publish' + + - task: CopyFiles@2 + displayName: 'Copy Files to: D:\' + inputs: + Contents: '*' + SourceFolder: 'Wafer-Counter\bin\$(Configuration)\$(CoreVersion)\$(Runtime)\publish' + TargetFolder: 'D:\$(CoreVersion)\$(Runtime)\$(Build.Repository.Name)\$(Build.BuildId)\$(Configuration)-$(AssemblyTitle)-AOT' + OverWrite: true + + - script: dotnet clean --configuration $(Configuration) + workingDirectory: Tests + displayName: 'Tests - Clean' + + - script: dotnet clean --configuration $(Configuration) + workingDirectory: Wafer-Counter + displayName: 'Wafer Counter - Clean' + + - stage: Release + displayName: Release + pool: + name: 'OpenInsight Metrology Viewer' + demands: OpenInsight-Metrology-Viewer-Wafer-Counter + variables: + ASPNETCORE_ENVIRONMENT: 'Production' + assemblyTitle: 'OI.Metrology.Wafer.Counter' + configuration: 'Release' + jobs: + - job: ReleaseDotnet + steps: + - script: | + echo Assembly Title: $(AssemblyTitle) + echo Build Id: $(Build.BuildId) + echo Build Reason: $(Build.Reason) + echo Repo Id: $(Build.Repository.Id) + echo Repo Name: $(Build.Repository.Name) + echo Source Version: $(Build.SourceVersion) + echo Configuration: $(Configuration) + echo Core Version: $(CoreVersion) + echo Nuget Source: $(NugetSource) + echo Runtime: $(Runtime) + displayName: 'Echo Check' + + - script: | + dotnet user-secrets init + dotnet user-secrets set BuildNumber $(Build.BuildId) + dotnet user-secrets set GitCommit $(Build.SourceVersion) + dotnet user-secrets list + workingDirectory: Wafer-Counter + displayName: 'Wafer Counter - Safe storage of app secrets' + + - script: dotnet build --configuration $(Configuration) --source $(NugetSource) + workingDirectory: Wafer-Counter + displayName: 'Wafer Counter - Build' + + - script: dotnet build --configuration $(Configuration) --source $(NugetSource) + workingDirectory: Tests + displayName: 'Tests - Build' + + - script: dotnet test --configuration $(Configuration) + workingDirectory: Tests + displayName: 'Tests - Test' + + - script: dotnet publish --configuration $(Configuration) + workingDirectory: Wafer-Counter + displayName: 'Wafer-Counter - Publish' + enabled: false + + - script: dotnet publish --configuration $(Configuration) --runtime $(Runtime) -p:PublishAot=true + workingDirectory: Wafer-Counter + displayName: 'Wafer-Counter - AOT Publish' + + - task: CopyFiles@2 + displayName: 'Copy Files to: D:\' + inputs: + Contents: '*' + SourceFolder: 'Wafer-Counter\bin\$(Configuration)\$(CoreVersion)\$(Runtime)\publish' + TargetFolder: 'D:\$(CoreVersion)\$(Runtime)\$(Build.Repository.Name)\$(Build.BuildId)\$(Configuration)-$(AssemblyTitle)-AOT' + OverWrite: true + + - script: dotnet clean --configuration $(Configuration) + workingDirectory: Tests + displayName: 'Tests - Clean' + + - script: dotnet clean --configuration $(Configuration) + workingDirectory: Wafer-Counter + displayName: 'Wafer Counter - Clean' + + - script: 'echo $(Build.SourceVersion)-$(Build.BuildId)>bin_x_x_\$(Configuration)\$(CoreVersion)\win-x64\$(Build.Repository.Name).txt' + displayName: 'Force Fail' + enabled: false