CORS, Theme, Better flow and dotnet tools

This commit is contained in:
Mike Phares 2023-01-04 09:38:00 -07:00
parent a3938d1916
commit 978e698da5
72 changed files with 528 additions and 774 deletions

20
.config/dotnet-tools.json Normal file
View File

@ -0,0 +1,20 @@
{
"version": 1,
"isRoot": true,
"tools": {
"plantumlclassdiagramgenerator": {
"version": "1.3.1",
"commands": [
"puml-gen",
"puml-gen Server .vscode/ClassDiagram/Server -dir -execludePaths bin,obj,Properties"
]
},
"dotnet-reportgenerator-globaltool": {
"version": "5.1.13",
"commands": [
"reportgenerator",
"ReportGenerator -reports:.vscode/TestResults/*/coverage.cobertura.xml -targetDir:.vscode/ReportGenerator/Html_Dark/1d194f36 -reportTypes:Html_Dark"
]
}
}
}

View File

@ -1,11 +0,0 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>

View File

@ -1,16 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.7" PrivateAssets="all" />
<PackageReference Include="MudBlazor" Version="6.0.13" />
</ItemGroup>
</Project>

View File

@ -1,25 +0,0 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31717.71
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor", "Blazor.csproj", "{8FA4FE44-D5BE-4E4E-BF73-60BF221B7214}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8FA4FE44-D5BE-4E4E-BF73-60BF221B7214}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8FA4FE44-D5BE-4E4E-BF73-60BF221B7214}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8FA4FE44-D5BE-4E4E-BF73-60BF221B7214}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8FA4FE44-D5BE-4E4E-BF73-60BF221B7214}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3EA21B75-27AE-47BA-B068-E10689118A5B}
EndGlobalSection
EndGlobal

View File

@ -1,17 +0,0 @@
@page "/counter"
<PageTitle>Counter</PageTitle>
<MudText Typo="Typo.h3" GutterBottom="true">Counter</MudText>
<MudText Class="mb-4">Current count: @currentCount</MudText>
<MudButton Color="Color.Primary" Variant="Variant.Filled" @onclick="IncrementCount">Click me</MudButton>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}

View File

@ -1,52 +0,0 @@
@page "/fetchdata"
@inject HttpClient Http
@using Blazor.Shared
<PageTitle>Weather forecast</PageTitle>
<MudText Typo="Typo.h3" GutterBottom="true">Weather forecast</MudText>
<MudText Class="mb-8">This component demonstrates fetching data from the server.</MudText>
@if (forecasts == null)
{
<MudProgressCircular Color="Color.Default" Indeterminate="true" />
}
else
{
<MudTable Items="forecasts" Hover="true" SortLabel="Sort By" Elevation="0">
<HeaderContent>
<MudTh><MudTableSortLabel InitialDirection="SortDirection.Ascending" SortBy="new Func<WeatherForecast, object>(x=>x.Date)">Date</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<WeatherForecast, object>(x=>x.TemperatureC)">Temp. (C)</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<WeatherForecast, object>(x=>x.TemperatureF)">Temp. (F)</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<WeatherForecast, object>(x=>x.Summary!)">Summary</MudTableSortLabel></MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Date">@context.Date</MudTd>
<MudTd DataLabel="Temp. (C)">@context.TemperatureC</MudTd>
<MudTd DataLabel="Temp. (F)">@context.TemperatureF</MudTd>
<MudTd DataLabel="Summary">@context.Summary</MudTd>
</RowTemplate>
<PagerContent>
<MudTablePager PageSizeOptions="new int[]{50, 100}" />
</PagerContent>
</MudTable>
}
@code {
private WeatherForecast[]? forecasts;
protected override async Task OnInitializedAsync()
{
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
}
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public string? Summary { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}

View File

@ -1,7 +0,0 @@
@page "/"
<PageTitle>Index</PageTitle>
<MudText Typo="Typo.h3" GutterBottom="true">Hello, world!</MudText>
<MudText Class="mb-8">Welcome to your new app, powered by MudBlazor!</MudText>
<MudAlert Severity="Severity.Normal">You can find documentation and examples on our website here: <MudLink Href="https://mudblazor.com" Typo="Typo.body2" Color="Color.Inherit"><b>www.mudblazor.com</b></MudLink></MudAlert>

View File

@ -1,13 +0,0 @@
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Blazor;
using MudBlazor.Services;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddMudServices();
await builder.Build().RunAsync();

View File

@ -1,34 +0,0 @@
@inherits LayoutComponentBase
<MudThemeProvider />
<MudDialogProvider />
<MudSnackbarProvider />
<MudLayout>
<MudAppBar Elevation="0">
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@((e) => DrawerToggle())" />
<MudSpacer />
<MudIconButton Icon="@Icons.Custom.Brands.MudBlazor" Color="Color.Inherit" Link="https://mudblazor.com/" Target="_blank" />
<MudIconButton Icon="@Icons.Custom.Brands.GitHub" Color="Color.Inherit" Link="https://github.com/MudBlazor/MudBlazor/" Target="_blank" />
</MudAppBar>
<MudDrawer @bind-Open="_drawerOpen" Elevation="1">
<MudDrawerHeader>
<MudText Typo="Typo.h6">Blazor</MudText>
</MudDrawerHeader>
<NavMenu />
</MudDrawer>
<MudMainContent>
<MudContainer MaxWidth="MaxWidth.Large" Class="my-16 pt-16">
@Body
</MudContainer>
</MudMainContent>
</MudLayout>
@code {
bool _drawerOpen = true;
void DrawerToggle()
{
_drawerOpen = !_drawerOpen;
}
}

View File

@ -1,5 +0,0 @@
<MudNavMenu>
<MudNavLink Href="" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Home">Home</MudNavLink>
<MudNavLink Href="counter" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.Add">Counter</MudNavLink>
<MudNavLink Href="fetchdata" Match="NavLinkMatch.Prefix" Icon="@Icons.Material.Filled.List">Fetch data</MudNavLink>
</MudNavMenu>

View File

@ -1,11 +0,0 @@
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.AspNetCore.Components.WebAssembly.Http
@using Microsoft.JSInterop
@using MudBlazor
@using Blazor
@using Blazor.Shared

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

View File

@ -1,25 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Blazor</title>
<base href="/" />
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
</head>
<body>
<div id="app">Loading...</div>
<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<script src="_framework/blazor.webassembly.js"></script>
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
</body>
</html>

View File

@ -1,27 +0,0 @@
[
{
"date": "2018-05-06",
"temperatureC": 1,
"summary": "Freezing"
},
{
"date": "2018-05-07",
"temperatureC": 14,
"summary": "Bracing"
},
{
"date": "2018-05-08",
"temperatureC": -13,
"summary": "Freezing"
},
{
"date": "2018-05-09",
"temperatureC": -16,
"summary": "Balmy"
},
{
"date": "2018-05-10",
"temperatureC": -2,
"summary": "Chilly"
}
]

View File

@ -1,6 +1,7 @@
{
"coverage-gutters.coverageBaseDir": "../.vscode/TestResults/*",
"cSpell.words": [
"ASPNETCORE",
"Blazor",
"Serilog",
"Setpoint"

View File

@ -15,6 +15,7 @@
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Runtime.WebAssembly.Sdk" Version="7.0.0" />
<PackageReference Include="MudBlazor" Version="6.0.13" />
<PackageReference Include="Serilog.AspNetCore.Ingestion" Version="1.0.0-dev-00032" />
<PackageReference Include="Serilog.Sinks.BrowserConsole" Version="1.0.0" />
<PackageReference Include="Serilog.Sinks.BrowserHttp" Version="1.0.0-dev-00032" />
<PackageReference Include="System.Net.Http.Json" Version="7.0.0" />

View File

@ -3,15 +3,5 @@
<PageTitle>Counter</PageTitle>
<MudText Typo="Typo.h3" GutterBottom="true">Counter</MudText>
<MudText Class="mb-4">Current count: @currentCount</MudText>
<MudButton Color="Color.Primary" Variant="Variant.Filled" @onclick="IncrementCount">Click me</MudButton>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
<MudText Class="mb-4">Current count: @_CurrentCount</MudText>
<MudButton Color="Color.Primary" Variant="Variant.Filled" @onclick="IncrementCount">Click me</MudButton>

View File

@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Components;
namespace Expose.MyIT.Client.Pages;
public partial class Counter
{
[Inject] protected ILogger<Counter>? Logger { get; set; }
private int _CurrentCount = 0;
private void IncrementCount()
{
if (Logger is null)
throw new NullReferenceException(nameof(Logger));
Logger.LogWarning("Someone has clicked me!");
_CurrentCount++;
}
}

View File

@ -1,5 +1,4 @@
@page "/fetchdata"
@using Expose.MyIT.Shared
@using Expose.MyIT.Shared.ViewModels
<PageTitle>Weather forecast</PageTitle>

View File

@ -1,5 +1,4 @@
@page "/fetchServiceShoporders"
@using Expose.MyIT.Shared
@using Expose.MyIT.Shared.ViewModels
<PageTitle>Service-Shop Orders</PageTitle>
@ -13,12 +12,21 @@ else
{
<MudTable Items="_ServiceShopOrders" Hover="true" SortLabel="Sort By" Elevation="0">
<HeaderContent>
<MudTh><MudTableSortLabel InitialDirection="SortDirection.Ascending" SortBy="new Func<ServiceShopOrder, object>(x=>x.CreatedDate)">CreatedDate</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ServiceShopOrder, object>(x=>x.Id)">Id</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ServiceShopOrder, object>(x=>x.Name)">Name</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ServiceShopOrder, object>(x=>x.BookingNames)">Booking Names</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ServiceShopOrder, object>(x=>x.Type)">Type</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ServiceShopOrder, object>(x=>x.State)">State</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ServiceShopOrder, object>(x=>x.ItemNumber)">Item Number</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel InitialDirection="SortDirection.Descending" SortBy="new Func<ServiceShopOrder, object>(x=>x.CreatedDate)">Created Date</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ServiceShopOrder, object>(x=>x.DecidedDate)">Decided Date</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ServiceShopOrder, object>(x=>x.Recipient)">Recipient</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<ServiceShopOrder, object>(x=>x.Requestor)">Requestor</MudTableSortLabel></MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Id">@context.Id</MudTd>
<MudTd DataLabel="Name">@context.Name</MudTd>
<MudTd DataLabel="BookingNames">@context.BookingNames</MudTd>
<MudTd DataLabel="BookingNames">@string.Join(' ', context.BookingNames)</MudTd>
<MudTd DataLabel="Type">@context.Type</MudTd>
<MudTd DataLabel="State">@context.State</MudTd>
<MudTd DataLabel="ItemNumber">@context.ItemNumber</MudTd>

View File

@ -27,6 +27,7 @@ public partial class FetchServiceShopOrders
if (Http is null)
throw new NullReferenceException(nameof(Http));
string controllerName = MyIT.Shared.Models.Stateless.Methods.IServiceShopOrderController.GetRouteName();
_ServiceShopOrders = await Http.GetFromJsonAsync<ServiceShopOrder[]>($"api/{controllerName}");
string actionName = nameof(MyIT.Shared.Models.Stateless.Methods.ISsaOrderController.GetAllSsaOrders).Substring(3, 3);
_ServiceShopOrders = await Http.GetFromJsonAsync<ServiceShopOrder[]>($"api/{controllerName}/{actionName}");
}
}

View File

@ -1,34 +0,0 @@
@page "/fetchssaorders"
@using Expose.MyIT.Shared
@using Expose.MyIT.Shared.ViewModels
<PageTitle>SSA Orders</PageTitle>
<MudText Typo="Typo.h3" GutterBottom="true">SSA Orders</MudText>
@if (_SsaOrders == null)
{
<MudProgressCircular Color="Color.Default" Indeterminate="true" />
}
else
{
<MudTable Items="_SsaOrders" Hover="true" SortLabel="Sort By" Elevation="0">
<HeaderContent>
<MudTh><MudTableSortLabel InitialDirection="SortDirection.Ascending" SortBy="new Func<SsaOrder, object>(x=>x.CreatedDate)">CreatedDate</MudTableSortLabel></MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Id">@context.Id</MudTd>
<MudTd DataLabel="Name">@context.Name</MudTd>
<MudTd DataLabel="BookingNames">@context.BookingNames</MudTd>
<MudTd DataLabel="Type">@context.Type</MudTd>
<MudTd DataLabel="State">@context.State</MudTd>
<MudTd DataLabel="ItemNumber">@context.ItemNumber</MudTd>
<MudTd DataLabel="CreatedDate">@context.CreatedDate</MudTd>
<MudTd DataLabel="DecidedDate">@context.DecidedDate</MudTd>
<MudTd DataLabel="Recipient">@context.Recipient</MudTd>
<MudTd DataLabel="Requestor">@context.Requestor</MudTd>
</RowTemplate>
<PagerContent>
<MudTablePager PageSizeOptions="new int[]{50, 100}" />
</PagerContent>
</MudTable>
}

View File

@ -1,32 +0,0 @@
using Expose.MyIT.Shared.ViewModels;
using Microsoft.AspNetCore.Components;
using System.Net.Http.Json;
namespace Expose.MyIT.Client.Pages;
public partial class FetchSsaOrders
{
[Inject] protected HttpClient? Http { get; set; }
private SsaOrder[]? _SsaOrders;
//Id
//Name
//BookingNames
//Type
//State
//ItemNumber
//CreatedDate
//DecidedDate
//Recipient
//Requestor
protected override async Task OnInitializedAsync()
{
if (Http is null)
throw new NullReferenceException(nameof(Http));
string controllerName = MyIT.Shared.Models.Stateless.Methods.ISsaOrderController.GetRouteName();
_SsaOrders = await Http.GetFromJsonAsync<SsaOrder[]>($"api/{controllerName}");
}
}

View File

@ -14,11 +14,10 @@ internal class Program
LoggingLevelSwitch levelSwitch = new();
LoggerConfiguration loggerConfiguration = new();
_ = loggerConfiguration.WriteTo.BrowserConsole();
Uri uri = new(builder.HostEnvironment.BaseAddress);
_ = loggerConfiguration.MinimumLevel.ControlledBy(levelSwitch);
// string baseAddress = builder.HostEnvironment.BaseAddress;
string baseAddress = "https://localhost:7130/";
_ = loggerConfiguration.Enrich.WithProperty("InstanceId", Guid.NewGuid().ToString("n"));
_ = loggerConfiguration.WriteTo.BrowserHttp($"{baseAddress}ingest", controlLevelSwitch: levelSwitch);
// _ = loggerConfiguration.WriteTo.BrowserHttp($"{baseAddress}ingest", controlLevelSwitch: levelSwitch);
Log.Logger = loggerConfiguration.CreateLogger();
Serilog.ILogger log = Log.ForContext<Program>();
try
@ -26,7 +25,7 @@ internal class Program
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
_ = builder.Services.AddScoped(serviceProvider => new HttpClient { BaseAddress = new Uri(baseAddress) });
_ = builder.Services.AddScoped(serviceProvider => new HttpClient { BaseAddress = new Uri($"http://{uri.Host}:50199") });
_ = builder.Services.AddMudServices();
log.Information("Building Web Host");

View File

@ -4,12 +4,15 @@
<MudDialogProvider />
<MudSnackbarProvider />
<MudThemeProvider @ref="@_MudThemeProvider" @bind-IsDarkMode="@_IsDarkMode"/>
<MudLayout>
<MudAppBar Elevation="0">
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@((e) => DrawerToggle())" />
<MudSpacer />
<MudIconButton Icon="@Icons.Custom.Brands.MudBlazor" Color="Color.Inherit" Link="https://mudblazor.com/" Target="_blank" />
<MudIconButton Icon="@Icons.Custom.Brands.GitHub" Color="Color.Inherit" Link="https://github.com/MudBlazor/MudBlazor/" Target="_blank" />
<MudSwitch @bind-Checked="@_IsDarkMode" Color="Color.Primary" Class="ma-4" T="bool" Label="Toggle Light/Dark Mode"/>
</MudAppBar>
<MudDrawer @bind-Open="_DrawerOpen" Elevation="1">
<MudDrawerHeader>

View File

@ -1,8 +1,22 @@
namespace Expose.MyIT.Client.Shared;
using MudBlazor;
namespace Expose.MyIT.Client.Shared;
public partial class MainLayout
{
bool _DrawerOpen = true;
private bool _IsDarkMode;
private MudThemeProvider? _MudThemeProvider;
void DrawerToggle() => _DrawerOpen = !_DrawerOpen;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender && _MudThemeProvider is not null)
{
_IsDarkMode = await _MudThemeProvider.GetSystemPreference();
StateHasChanged();
}
}
}

View File

@ -31,6 +31,7 @@
</div>
<script src="_framework/blazor.webassembly.js"></script>
<script src="_content/MudBlazor/MudBlazor.min.js"></script>
<script>navigator.serviceWorker.register('service-worker.js');</script>
</body>
</html>

View File

@ -4,7 +4,7 @@ VisualStudioVersion = 16.0.0.0
MinimumVisualStudioVersion = 16.0.0.0
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Expose-MyIT.Server", "Server\Expose-MyIT.Server.csproj", "{1C39B1BD-281A-47AA-AC16-B5655D9D80ED}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Expose-MyIT.Client", "Client\Expose-MyIT.Client.csproj", "{DCBD7C30-FA0E-4079-B68F-1C285C1EEA6C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Expose.MyIT.Client", "Client\Expose.MyIT.Client.csproj", "{DCBD7C30-FA0E-4079-B68F-1C285C1EEA6C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Expose-MyIT.Shared", "Shared\Expose-MyIT.Shared.csproj", "{7C35EAAB-C4D6-444A-8252-EB2ABE031267}"
EndProject

26
ReadMe.md Normal file
View File

@ -0,0 +1,26 @@
Created new directory to be matched by solution file
cd into directory
dotnet new blazorwasm --hosted --pwa
dotnet build
If new packages exist
->after at least five minutes to allow Baget-Push to update
->dotnet nuget locals all --clear
->dotnet build --source https://messa017.infineon.com/v3/index.json
->dotnet nuget locals all --clear
->dotnet build --source https://messa08ec.ec.local/v3/index.json
For now remove reference to client from Server
Add many references to server example serilog and UserSecrets
Update the Program.cs for logging
Add Models to Server
Added extra [Route("api/[controller]")]
dotnet new mstest -o Tests
In the tests add reference to abc.Shared
Add many references to test project
Add Server\appsettings***.json references to test project
Rename TestUnit1 and add some code
rename project abc.Tests.csproj
dotnet sln add Tests/abc.Tests.csproj
Add code to use the server
development - 9a93857ec10a35297faf64ab335db1997c1490aa
Separate page and code behind for fetch data
In the client add reference to abc.Client.Core

View File

@ -1,30 +1,22 @@
using Expose.MyIT.Shared.Models.Stateless.Methods;
using Expose.MyIT.Shared.Models.Stateless;
using Microsoft.AspNetCore.Mvc;
using System.Text.Json;
namespace Expose.MyIT.Server.Controllers;
[ApiController]
public class AppSettingsController : ControllerBase, IAppSettingsController
[Route("api/[controller]")]
public class AppSettingsController : ControllerBase, IAppSettingsController<ActionResult>
{
private readonly Models.AppSettings _AppSettings;
private readonly IAppSettingsRepository _AppSettingsRepository;
public AppSettingsController(Models.AppSettings appSettings) => _AppSettings = appSettings;
public AppSettingsController(IAppSettingsRepository AppSettingsRepository) => _AppSettingsRepository = AppSettingsRepository;
[Route("api/[controller]")]
[HttpGet]
public string[] GetAppSettings()
[HttpGet(nameof(IAppSettingsController<ActionResult>.Action.App))]
public ActionResult GetAppSettings()
{
List<string> results = new();
string json = JsonSerializer.Serialize(_AppSettings);
JsonElement jsonElement = JsonSerializer.Deserialize<JsonElement>(json);
JsonProperty[] jsonProperties = jsonElement.EnumerateObject().ToArray();
foreach (JsonProperty jsonProperty in jsonProperties)
results.Add(jsonProperty.Value.ToString());
if (!_AppSettings.IsDevelopment)
throw new Exception("Shouldn't expose!");
return results.ToArray();
List<string> results = _AppSettingsRepository.GetAppSettings();
return Ok(results);
}
}

View File

@ -1,40 +1,29 @@
using Expose.MyIT.Shared.Models.Stateless.Methods;
using Expose.MyIT.Shared.Models.Stateless;
using Microsoft.AspNetCore.Mvc;
namespace Expose.MyIT.Server.Controllers;
[ApiController]
public class ClientSettingsController : ControllerBase, IClientSettingsController
[Route("api/[controller]")]
public class ClientSettingsController : ControllerBase, IClientSettingsController<ActionResult>
{
private readonly Models.AppSettings _AppSettings;
private readonly IClientSettingsRepository _ClientSettingsRepository;
public ClientSettingsController(Models.AppSettings appSettings) => _AppSettings = appSettings;
public ClientSettingsController(IClientSettingsRepository clientSettingsRepository) => _ClientSettingsRepository = clientSettingsRepository;
[Route("api/[controller]")]
[HttpGet]
public string[] GetClientSettings()
[HttpGet(nameof(IClientSettingsController<ActionResult>.Action.Client))]
public ActionResult GetClientSettings()
{
List<string> results = new();
string? remoteIpAddress = Request.HttpContext.Connection?.RemoteIpAddress?.ToString();
if (!string.IsNullOrEmpty(remoteIpAddress))
results.Add(remoteIpAddress);
else
results.Add(nameof(remoteIpAddress));
if (!_AppSettings.IsDevelopment)
throw new Exception("Shouldn't expose!");
return results.ToArray();
List<string> results = _ClientSettingsRepository.GetClientSettings(Request.HttpContext.Connection?.RemoteIpAddress);
return Ok(results);
}
[Route("api/[controller]/IpAddress")]
[HttpGet]
public string GetIpAddress()
[HttpGet(nameof(IClientSettingsController<ActionResult>.Action.IP))]
public ActionResult GetIpAddress()
{
string? result;
result = Request.HttpContext.Connection?.RemoteIpAddress?.ToString();
if (string.IsNullOrEmpty(result))
result = string.Empty;
return result;
string result = _ClientSettingsRepository.GetIpAddress(Request.HttpContext.Connection?.RemoteIpAddress);
return Ok(result);
}
}

View File

@ -1,33 +1,23 @@
using Expose.MyIT.Shared.Models.Methods;
using Expose.MyIT.Shared.Models.Stateless.Methods;
using Expose.MyIT.Shared.Models.Stateless;
using Microsoft.AspNetCore.Mvc;
namespace Expose.MyIT.Server.Controllers;
[ApiController]
[Route("api/[controller]")]
public class ServiceShopOrderController : ControllerBase, IServiceShopOrderController
public class ServiceShopOrderController : ControllerBase, IServiceShopOrderController<ActionResult>
{
private readonly IServiceShopOrderController _ServiceShopOrderController;
private readonly IServiceShopOrderRepository _ServiceShopOrderRepository;
public ServiceShopOrderController(IServiceShopOrderRepository ServiceShopOrderRepository)
{
_ServiceShopOrderController = this;
_ServiceShopOrderRepository = ServiceShopOrderRepository;
}
public ServiceShopOrderController(IServiceShopOrderRepository ServiceShopOrderRepository) => _ServiceShopOrderRepository = ServiceShopOrderRepository;
async Task<Shared.ViewModels.ServiceShopOrder[]> IServiceShopOrderController.GetAllServiceShopOrders() => await _ServiceShopOrderRepository.GetAllServiceShopOrders();
async Task<Shared.ViewModels.ServiceShopOrder[]> IServiceShopOrderController.GetServiceShopOrders(string id) => await _ServiceShopOrderRepository.GetServiceShopOrders(id);
[HttpGet(nameof(Shared.Models.Stateless.IServiceShopOrderController.Action.All))]
[HttpGet(nameof(IServiceShopOrderController<ActionResult>.Action.All))]
public async Task<ActionResult> GetAllServiceShopOrders()
{
try
{
Shared.ViewModels.ServiceShopOrder[] results = await _ServiceShopOrderController.GetAllServiceShopOrders();
Shared.ViewModels.ServiceShopOrder[] results = await _ServiceShopOrderRepository.GetAllServiceShopOrders();
return Ok(results);
}
catch (Exception)
@ -43,7 +33,7 @@ public class ServiceShopOrderController : ControllerBase, IServiceShopOrderContr
{
try
{
Shared.ViewModels.ServiceShopOrder[] results = await _ServiceShopOrderController.GetServiceShopOrders(id);
Shared.ViewModels.ServiceShopOrder[] results = await _ServiceShopOrderRepository.GetServiceShopOrders(id);
return Ok(results);
}
catch (Exception)

View File

@ -1,33 +1,23 @@
using Expose.MyIT.Shared.Models.Methods;
using Expose.MyIT.Shared.Models.Stateless.Methods;
using Expose.MyIT.Shared.Models.Stateless;
using Microsoft.AspNetCore.Mvc;
namespace Expose.MyIT.Server.Controllers;
[ApiController]
[Route("api/[controller]")]
public class SsaOrderController : ControllerBase, ISsaOrderController
public class SsaOrderController : ControllerBase, ISsaOrderController<ActionResult>
{
private readonly ISsaOrderController _SsaOrderController;
private readonly ISsaOrderRepository _SsaOrderRepository;
public SsaOrderController(ISsaOrderRepository SsaOrderRepository)
{
_SsaOrderController = this;
_SsaOrderRepository = SsaOrderRepository;
}
public SsaOrderController(ISsaOrderRepository SsaOrderRepository) => _SsaOrderRepository = SsaOrderRepository;
async Task<Shared.ViewModels.SsaOrder[]> ISsaOrderController.GetAllSsaOrders() => await _SsaOrderRepository.GetAllSsaOrders();
async Task<Shared.ViewModels.SsaOrder[]> ISsaOrderController.GetSsaOrders(string id) => await _SsaOrderRepository.GetSsaOrders(id);
[HttpGet(nameof(Shared.Models.Stateless.ISsaOrderController.Action.All))]
[HttpGet(nameof(ISsaOrderController<ActionResult>.Action.All))]
public async Task<ActionResult> GetAllSsaOrders()
{
try
{
Shared.ViewModels.SsaOrder[] results = await _SsaOrderController.GetAllSsaOrders();
Shared.ViewModels.SsaOrder[] results = await _SsaOrderRepository.GetAllSsaOrders();
return Ok(results);
}
catch (Exception)
@ -43,7 +33,7 @@ public class SsaOrderController : ControllerBase, ISsaOrderController
{
try
{
Shared.ViewModels.SsaOrder[] results = await _SsaOrderController.GetSsaOrders(id);
Shared.ViewModels.SsaOrder[] results = await _SsaOrderRepository.GetSsaOrders(id);
return Ok(results);
}
catch (Exception)

View File

@ -1,4 +1,4 @@
using Expose.MyIT.Shared.Models.Stateless.Methods;
using Expose.MyIT.Shared.Models.Stateless;
using Expose.MyIT.Shared.ViewModels;
using Microsoft.AspNetCore.Mvc;
@ -7,7 +7,7 @@ namespace Expose.MyIT.Server.Controllers;
[ApiController]
[Route("[controller]")]
[Route("api/[controller]")]
public class WeatherForecastController : ControllerBase, IWeatherForecastController
public class WeatherForecastController : ControllerBase, IWeatherForecastController<WeatherForecast[]>
{
private static readonly string[] _Summaries = new[]
{
@ -18,8 +18,6 @@ public class WeatherForecastController : ControllerBase, IWeatherForecastControl
public WeatherForecastController(ILogger<WeatherForecastController> logger) => _Logger = logger;
Task<WeatherForecast[]> IWeatherForecastController.Get() => throw new NotImplementedException();
[HttpGet]
public WeatherForecast[] Get()
{

View File

@ -1,46 +1,19 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Expose.MyIT.Server.Models;
public class AppSettings
public record AppSettings(string BuildNumber,
string Company,
string ConnectionString,
string GitCommitSeven,
bool IsDevelopment,
bool IsStaging,
string MonAResource,
string MonASite,
string Urls,
string WorkingDirectoryName)
{
public string BuildNumber { init; get; }
public string Company { init; get; }
public string ConnectionString { init; get; }
public string GitCommitSeven { init; get; }
public bool IsDevelopment { init; get; }
public bool IsStaging { init; get; }
public string MonAResource { init; get; }
public string MonASite { init; get; }
public string URLs { init; get; }
public string WorkingDirectoryName { init; get; }
[JsonConstructor]
public AppSettings(string buildNumber,
string company,
string connectionString,
string gitCommitSeven,
bool isDevelopment,
bool isStaging,
string monAResource,
string monASite,
string urls,
string workingDirectoryName)
{
BuildNumber = buildNumber;
Company = company;
ConnectionString = connectionString;
GitCommitSeven = gitCommitSeven;
IsDevelopment = isDevelopment;
IsStaging = isStaging;
MonAResource = monAResource;
MonASite = monASite;
URLs = urls;
WorkingDirectoryName = workingDirectoryName;
}
public override string ToString()
{
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });

View File

@ -0,0 +1,28 @@
using Expose.MyIT.Shared.Models.Stateless;
using System.Text.Json;
namespace Expose.MyIT.Server.Models;
public class AppSettingsRepository : IAppSettingsRepository
{
private readonly AppSettings _AppSettings;
public AppSettingsRepository(AppSettings appSettings) => _AppSettings = appSettings;
public List<string> GetAppSettings()
{
List<string> results = new();
string json = JsonSerializer.Serialize(_AppSettings);
JsonElement jsonElement = JsonSerializer.Deserialize<JsonElement>(json);
JsonProperty[] jsonProperties = jsonElement.EnumerateObject().ToArray();
foreach (JsonProperty jsonProperty in jsonProperties)
results.Add(jsonProperty.Value.ToString());
if (!_AppSettings.IsDevelopment)
throw new Exception("Shouldn't expose!");
return results;
}
List<string> IAppSettingsRepository.GetAppSettings() => GetAppSettings();
}

View File

@ -0,0 +1,35 @@
using Expose.MyIT.Shared.Models.Stateless;
using System.Net;
namespace Expose.MyIT.Server.Models;
public class ClientSettingsRepository : IClientSettingsRepository
{
private readonly AppSettings _AppSettings;
public ClientSettingsRepository(AppSettings appSettings) => _AppSettings = appSettings;
public List<string> GetClientSettings(IPAddress? remoteIpAddress)
{
List<string> results = new();
if (remoteIpAddress is null)
results.Add(nameof(remoteIpAddress));
else
results.Add(remoteIpAddress.ToString());
if (!_AppSettings.IsDevelopment)
throw new Exception("Shouldn't expose!");
return results;
}
List<string> IClientSettingsRepository.GetClientSettings(IPAddress? remoteIpAddress) => GetClientSettings(remoteIpAddress);
public string GetIpAddress(IPAddress? remoteIpAddress)
{
string result = remoteIpAddress is null ? string.Empty : remoteIpAddress.ToString();
return result;
}
string IClientSettingsRepository.GetIpAddress(IPAddress? remoteIpAddress) => GetIpAddress(remoteIpAddress);
}

View File

@ -1,4 +1,4 @@
using Expose.MyIT.Shared.Models.Methods;
using Expose.MyIT.Shared.Models.Stateless;
using Expose.MyIT.Shared.ViewModels;
using Serilog.Context;
using System.Text.Json;
@ -12,16 +12,21 @@ public class ServiceShopOrderRepository : IServiceShopOrderRepository
public ServiceShopOrderRepository() => _Log = Serilog.Log.ForContext<ServiceShopOrderRepository>();
private static ServiceShopOrder[] GetServiceShopOrders(Shared.Models.ServiceShop? ServiceShop)
private static ServiceShopOrder[] GetServiceShopOrders(Shared.Models.ServiceShop? serviceShop)
{
ServiceShopOrder[] result = Shared.Models.Stateless.Methods.IServiceShopOrder.GetServiceShopOrders(ServiceShop);
ServiceShopOrder[] result = IServiceShopOrder.GetServiceShopOrders(serviceShop);
return result;
}
private static Shared.Models.ServiceShop? GetServiceShopOrders()
{
Shared.Models.ServiceShop? result;
string jsonFile = Path.Combine(AppContext.BaseDirectory, "service-shop.json");
string jsonFile;
string checkDirectory = Path.Combine(AppContext.BaseDirectory, "Data/Mike");
if (Directory.Exists(checkDirectory))
jsonFile = Path.Combine(checkDirectory, "service-shop.json");
else
jsonFile = Path.Combine(AppContext.BaseDirectory, "service-shop.json");
string json = File.ReadAllText(jsonFile);
result = JsonSerializer.Deserialize<Shared.Models.ServiceShop>(json);
return result;
@ -30,12 +35,12 @@ public class ServiceShopOrderRepository : IServiceShopOrderRepository
async Task<ServiceShopOrder[]> IServiceShopOrderRepository.GetAllServiceShopOrders()
{
ServiceShopOrder[] results;
string? methodName = Shared.Models.Stateless.Methods.IMethodName.GetActualAsyncMethodName();
string? methodName = IMethodName.GetActualAsyncMethodName();
using (LogContext.PushProperty("MethodName", methodName))
{
_Log.Debug("() => ...");
Shared.Models.ServiceShop? ServiceShop = await Task.Run(GetServiceShopOrders);
results = GetServiceShopOrders(ServiceShop);
Shared.Models.ServiceShop? serviceShop = await Task.Run(GetServiceShopOrders);
results = GetServiceShopOrders(serviceShop);
}
return results.ToArray();
}
@ -43,8 +48,8 @@ public class ServiceShopOrderRepository : IServiceShopOrderRepository
async Task<ServiceShopOrder[]> IServiceShopOrderRepository.GetServiceShopOrders(string id)
{
ServiceShopOrder[] results;
Shared.Models.ServiceShop? ServiceShop = await Task.Run(GetServiceShopOrders);
results = GetServiceShopOrders(ServiceShop).Where(l => l.Id == id).ToArray();
Shared.Models.ServiceShop? serviceShop = await Task.Run(GetServiceShopOrders);
results = GetServiceShopOrders(serviceShop).Where(l => l.Id == id).ToArray();
return results;
}

View File

@ -1,4 +1,4 @@
using Expose.MyIT.Shared.Models.Methods;
using Expose.MyIT.Shared.Models.Stateless;
using Expose.MyIT.Shared.ViewModels;
using Serilog.Context;
using System.Text.Json;
@ -12,29 +12,34 @@ public class SsaOrderRepository : ISsaOrderRepository
public SsaOrderRepository() => _Log = Serilog.Log.ForContext<SsaOrderRepository>();
private static SsaOrder[] GetSsaOrders(Shared.Models.SSA? ssa)
private static SsaOrder[] GetSsaOrders(Shared.Models.Ssa? ssa)
{
SsaOrder[] result = Shared.Models.Stateless.Methods.ISsaOrder.GetSsaOrders(ssa);
SsaOrder[] result = ISsaOrder.GetSsaOrders(ssa);
return result;
}
private static Shared.Models.SSA? GetSsaOrders()
private static Shared.Models.Ssa? GetSsaOrders()
{
Shared.Models.SSA? result;
string jsonFile = Path.Combine(AppContext.BaseDirectory, "ssa.json");
Shared.Models.Ssa? result;
string jsonFile;
string checkDirectory = Path.Combine(AppContext.BaseDirectory, "Data/Mike");
if (Directory.Exists(checkDirectory))
jsonFile = Path.Combine(checkDirectory, "ssa.json");
else
jsonFile = Path.Combine(AppContext.BaseDirectory, "ssa.json");
string json = File.ReadAllText(jsonFile);
result = JsonSerializer.Deserialize<Shared.Models.SSA>(json);
result = JsonSerializer.Deserialize<Shared.Models.Ssa>(json);
return result;
}
async Task<SsaOrder[]> ISsaOrderRepository.GetAllSsaOrders()
{
SsaOrder[] results;
string? methodName = Shared.Models.Stateless.Methods.IMethodName.GetActualAsyncMethodName();
string? methodName = IMethodName.GetActualAsyncMethodName();
using (LogContext.PushProperty("MethodName", methodName))
{
_Log.Debug("() => ...");
Shared.Models.SSA? ssa = await Task.Run(GetSsaOrders);
Shared.Models.Ssa? ssa = await Task.Run(GetSsaOrders);
results = GetSsaOrders(ssa);
}
return results.ToArray();
@ -43,7 +48,7 @@ public class SsaOrderRepository : ISsaOrderRepository
async Task<SsaOrder[]> ISsaOrderRepository.GetSsaOrders(string id)
{
SsaOrder[] results;
Shared.Models.SSA? ssa = await Task.Run(GetSsaOrders);
Shared.Models.Ssa? ssa = await Task.Run(GetSsaOrders);
results = GetSsaOrders(ssa).Where(l => l.Id == id).ToArray();
return results;
}

View File

@ -1,5 +1,5 @@
using Expose.MyIT.Server.Models;
using Expose.MyIT.Shared.Models.Methods;
using Expose.MyIT.Shared.Models.Stateless;
using Serilog;
namespace Expose.MyIT.Server;
@ -23,9 +23,13 @@ public class Program
try
{
// Add services to the container.
AppSettingsRepository appSettingsRepository = new(appSettings);
ClientSettingsRepository clientSettingsRepository = new(appSettings);
_ = builder.Services.AddSingleton<AppSettings, AppSettings>(_ => appSettings);
_ = builder.Services.AddSingleton(_ => appSettings);
_ = builder.Services.AddSingleton<ISsaOrderRepository, SsaOrderRepository>();
_ = builder.Services.AddSingleton<IAppSettingsRepository>(_ => appSettingsRepository);
_ = builder.Services.AddSingleton<IClientSettingsRepository>(_ => clientSettingsRepository);
_ = builder.Services.AddSingleton<IServiceShopOrderRepository, ServiceShopOrderRepository>();
_ = builder.Services.AddControllersWithViews();
_ = builder.Services.AddRazorPages();
@ -40,7 +44,7 @@ public class Program
}
else
{
_ = app.UseCors(corsPolicyBuilder => corsPolicyBuilder.WithOrigins("https://localhost:7130", "http://localhost:5055"));
_ = app.UseCors(corsPolicyBuilder => corsPolicyBuilder.WithOrigins("https://localhost:7130", "http://localhost:5055", "http://mestsa008.infineon.com:50199", "http://mestsa008.infineon.com:5055"));
_ = app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
_ = app.UseHsts();

View File

@ -1,11 +0,0 @@
namespace Expose.MyIT.Shared.Models.Stateless;
public interface IServiceShopOrderController
{
enum Action : int
{
All = 0
}
}

View File

@ -1,11 +0,0 @@
namespace Expose.MyIT.Shared.Models.Stateless;
public interface ISsaOrderController
{
enum Action : int
{
All = 0
}
}

View File

@ -1,9 +0,0 @@
using System.Text.Json.Serialization;
namespace Expose.MyIT.Shared.Models;
public record Order2(
[property: JsonPropertyName("Id")] string Id,
[property: JsonPropertyName("Name")] string Name,
[property: JsonPropertyName("TypeId")] int TypeId
);

View File

@ -2,7 +2,7 @@ using System.Text.Json.Serialization;
namespace Expose.MyIT.Shared.Models;
public record SSA(
public record Ssa(
[property: JsonPropertyName("Orders")] IReadOnlyList<Order> Orders,
[property: JsonPropertyName("Total")] int Total
);

View File

@ -0,0 +1,14 @@
namespace Expose.MyIT.Shared.Models.Stateless;
public interface IAppSettingsController<T>
{
enum Action : int
{
App = 0
}
static string GetRouteName() => nameof(IAppSettingsController<T>)[1..^10];
T GetAppSettings();
}

View File

@ -0,0 +1,8 @@
namespace Expose.MyIT.Shared.Models.Stateless;
public interface IAppSettingsRepository
{
List<string> GetAppSettings();
}

View File

@ -0,0 +1,16 @@
namespace Expose.MyIT.Shared.Models.Stateless;
public interface IClientSettingsController<T>
{
enum Action : int
{
Client = 0,
IP = 1
}
static string GetRouteName() => nameof(IClientSettingsController<T>)[1..^10];
T GetClientSettings();
T GetIpAddress();
}

View File

@ -0,0 +1,11 @@
using System.Net;
namespace Expose.MyIT.Shared.Models.Stateless;
public interface IClientSettingsRepository
{
List<string> GetClientSettings(IPAddress? remoteIpAddress);
string GetIpAddress(IPAddress? remoteIpAddress);
}

View File

@ -1,6 +1,6 @@
using System.Runtime.CompilerServices;
namespace Expose.MyIT.Shared.Models.Stateless.Methods;
namespace Expose.MyIT.Shared.Models.Stateless;
public interface IMethodName
{

View File

@ -1,4 +1,4 @@
namespace Expose.MyIT.Shared.Models.Stateless.Methods;
namespace Expose.MyIT.Shared.Models.Stateless;
public interface IServiceShopOrder
{
@ -6,6 +6,6 @@ public interface IServiceShopOrder
ViewModels.ServiceShopOrder[] TestStatic_GetServiceShopOrders(ServiceShop? serviceShop) =>
GetServiceShopOrders(serviceShop);
static ViewModels.ServiceShopOrder[] GetServiceShopOrders(ServiceShop? serviceShop) =>
ServiceShopOrder.GetServiceShopOrders(serviceShop);
ServiceShopOrder.GetServiceShopOrders(serviceShop);
}

View File

@ -0,0 +1,15 @@
namespace Expose.MyIT.Shared.Models.Stateless;
public interface IServiceShopOrderController<T>
{
enum Action : int
{
All = 0
}
static string GetRouteName() => nameof(IServiceShopOrderController<T>)[1..^10];
Task<T> GetAllServiceShopOrders();
Task<T> GetServiceShopOrders(string id);
}

View File

@ -1,4 +1,4 @@
namespace Expose.MyIT.Shared.Models.Methods;
namespace Expose.MyIT.Shared.Models.Stateless;
public interface IServiceShopOrderRepository
{

View File

@ -0,0 +1,11 @@
namespace Expose.MyIT.Shared.Models.Stateless;
public interface ISsaOrder
{
ViewModels.SsaOrder[] TestStatic_GetSsaOrders(Ssa? ssa) =>
GetSsaOrders(ssa);
static ViewModels.SsaOrder[] GetSsaOrders(Ssa? ssa) =>
SsaOrder.GetSsaOrders(ssa);
}

View File

@ -0,0 +1,15 @@
namespace Expose.MyIT.Shared.Models.Stateless;
public interface ISsaOrderController<T>
{
enum Action : int
{
All = 0
}
static string GetRouteName() => nameof(ISsaOrderController<T>)[1..^10];
Task<T> GetAllSsaOrders();
Task<T> GetSsaOrders(string id);
}

View File

@ -1,4 +1,4 @@
namespace Expose.MyIT.Shared.Models.Methods;
namespace Expose.MyIT.Shared.Models.Stateless;
public interface ISsaOrderRepository
{

View File

@ -0,0 +1,9 @@
namespace Expose.MyIT.Shared.Models.Stateless;
public interface IWeatherForecastController<T>
{
static string GetRouteName() => nameof(IWeatherForecastController<T>)[1..^10];
T Get();
}

View File

@ -1,9 +0,0 @@
namespace Expose.MyIT.Shared.Models.Stateless.Methods;
public interface IAppSettingsController
{
static string GetRouteName() => nameof(IAppSettingsController)[1..^10];
string[] GetAppSettings();
}

View File

@ -1,10 +0,0 @@
namespace Expose.MyIT.Shared.Models.Stateless.Methods;
public interface IClientSettingsController
{
static string GetRouteName() => nameof(IClientSettingsController)[1..^10];
string[] GetClientSettings();
string GetIpAddress();
}

View File

@ -1,10 +0,0 @@
namespace Expose.MyIT.Shared.Models.Stateless.Methods;
public interface IServiceShopOrderController
{
static string GetRouteName() => nameof(IServiceShopOrderController)[1..^10];
Task<ViewModels.ServiceShopOrder[]> GetAllServiceShopOrders();
Task<ViewModels.ServiceShopOrder[]> GetServiceShopOrders(string id);
}

View File

@ -1,11 +0,0 @@
namespace Expose.MyIT.Shared.Models.Stateless.Methods;
public interface ISsaOrder
{
ViewModels.SsaOrder[] TestStatic_GetSsaOrders(SSA? ssa) =>
GetSsaOrders(ssa);
static ViewModels.SsaOrder[] GetSsaOrders(SSA? ssa) =>
SsaOrder.GetSsaOrders(ssa);
}

View File

@ -1,10 +0,0 @@
namespace Expose.MyIT.Shared.Models.Stateless.Methods;
public interface ISsaOrderController
{
static string GetRouteName() => nameof(ISsaOrderController)[1..^10];
Task<ViewModels.SsaOrder[]> GetAllSsaOrders();
Task<ViewModels.SsaOrder[]> GetSsaOrders(string id);
}

View File

@ -1,9 +0,0 @@
namespace Expose.MyIT.Shared.Models.Stateless.Methods;
public interface IWeatherForecastController
{
static string GetRouteName() => nameof(IWeatherForecastController)[1..^10];
Task<ViewModels.WeatherForecast[]> Get();
}

View File

@ -1,6 +1,6 @@
namespace Expose.MyIT.Shared.Models.Stateless.Methods;
namespace Expose.MyIT.Shared.Models.Stateless;
internal class ServiceShopOrder
internal abstract class ServiceShopOrder
{
internal static ViewModels.ServiceShopOrder[] GetServiceShopOrders(ServiceShop? serviceShop)

View File

@ -1,9 +1,9 @@
namespace Expose.MyIT.Shared.Models.Stateless.Methods;
namespace Expose.MyIT.Shared.Models.Stateless;
internal class SsaOrder
internal abstract class SsaOrder
{
internal static ViewModels.SsaOrder[] GetSsaOrders(SSA? ssa)
internal static ViewModels.SsaOrder[] GetSsaOrders(Ssa? ssa)
{
ViewModels.SsaOrder[] results;
if (ssa is null || !ssa.Orders.Any())

View File

@ -2,34 +2,18 @@ using System.Text.Json;
namespace Expose.MyIT.Shared.ViewModels;
public class ServiceShopOrder
public record ServiceShopOrder(string Id,
string Name,
string[] BookingNames,
string Type,
string State,
string ItemNumber,
DateTime CreatedDate,
DateTime DecidedDate,
string Recipient,
string Requestor)
{
public string Id { init; get; }
public string Name { init; get; }
public string[] BookingNames { init; get; }
public string Type { init; get; }
public string State { init; get; }
public string ItemNumber { init; get; }
public DateTime CreatedDate { init; get; }
public DateTime DecidedDate { init; get; }
public string Recipient { init; get; }
public string Requestor { init; get; }
public ServiceShopOrder(string id, string name, string[] bookingNames, string type, string state, string itemNumber, DateTime createdDate, DateTime decidedDate, string recipient, string requestor)
{
Id = id;
Name = name;
BookingNames = bookingNames;
Type = type;
State = state;
ItemNumber = itemNumber;
CreatedDate = createdDate;
DecidedDate = decidedDate;
Recipient = recipient;
Requestor = requestor;
}
public ServiceShopOrder(Models.Order order) :
this(order.Id,
order.Name,

View File

@ -2,34 +2,18 @@ using System.Text.Json;
namespace Expose.MyIT.Shared.ViewModels;
public class SsaOrder
public record SsaOrder(string Id,
string Name,
string[] BookingNames,
string Type,
string State,
string ItemNumber,
DateTime CreatedDate,
DateTime DecidedDate,
string Recipient,
string Requestor)
{
public string Id { init; get; }
public string Name { init; get; }
public string[] BookingNames { init; get; }
public string Type { init; get; }
public string State { init; get; }
public string ItemNumber { init; get; }
public DateTime CreatedDate { init; get; }
public DateTime DecidedDate { init; get; }
public string Recipient { init; get; }
public string Requestor { init; get; }
public SsaOrder(string id, string name, string[] bookingNames, string type, string state, string itemNumber, DateTime createdDate, DateTime decidedDate, string recipient, string requestor)
{
Id = id;
Name = name;
BookingNames = bookingNames;
Type = type;
State = state;
ItemNumber = itemNumber;
CreatedDate = createdDate;
DecidedDate = decidedDate;
Recipient = recipient;
Requestor = requestor;
}
public SsaOrder(Models.Order order) :
this(order.Id,
order.Name,

View File

@ -1,25 +1,14 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Expose.MyIT.Shared.ViewModels;
public class WeatherForecast
public record WeatherForecast
{
public DateOnly Date { init; get; }
public int TemperatureC { init; get; }
public string? Summary { init; get; }
public int TemperatureF { init; get; }
public WeatherForecast(DateOnly date, int temperatureC, string? summary, int temperatureF)
{
Date = date;
TemperatureC = temperatureC;
Summary = summary;
TemperatureF = temperatureF;
}
[JsonConstructor]
public WeatherForecast(DateOnly Date, int TemperatureC, string? Summary, int TemperatureF)
{ }
public WeatherForecast(Models.WeatherForecast weatherForecast) :
this(weatherForecast.Date,

View File

@ -1,3 +1,4 @@
using Expose.MyIT.Shared.Models.Stateless;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
@ -9,10 +10,14 @@ namespace Expose.MyIT.Tests;
public class UnitTestAppSettingsController
{
private static ILogger? _Logger;
private static string? _ControllerName;
private static TestContext? _TestContext;
private static WebApplicationFactory<Server.Program>? _WebApplicationFactory;
#pragma warning disable CS8618
private static ILogger _Logger;
private static string _ControllerName;
private static TestContext _TestContext;
private static WebApplicationFactory<Server.Program> _WebApplicationFactory;
#pragma warning restore
[ClassInitialize]
public static void ClassInitAsync(TestContext testContext)
@ -26,40 +31,45 @@ public class UnitTestAppSettingsController
[TestMethod]
public void TestControllerName()
{
if (_Logger is null)
throw new NullReferenceException(nameof(_Logger));
if (_ControllerName is null)
throw new NullReferenceException(nameof(_ControllerName));
if (_WebApplicationFactory is null)
throw new NullReferenceException(nameof(_WebApplicationFactory));
_Logger.Information("Starting Web Application");
Assert.AreEqual(Shared.Models.Stateless.Methods.IAppSettingsController.GetRouteName(), _ControllerName);
Assert.AreEqual(IAppSettingsController<object>.GetRouteName(), _ControllerName);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task Get_ShouldReturn()
public void AppSettings()
{
if (_Logger is null)
throw new NullReferenceException(nameof(_Logger));
if (_ControllerName is null)
throw new NullReferenceException(nameof(_ControllerName));
if (_WebApplicationFactory is null)
throw new NullReferenceException(nameof(_WebApplicationFactory));
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
Server.Models.AppSettings appSettings = serviceProvider.GetRequiredService<Server.Models.AppSettings>();
Assert.IsNotNull(appSettings);
if (appSettings.IsDevelopment)
{
HttpResponseMessage httpResponseMessage = await httpClient.GetAsync($"api/{_ControllerName}/");
Assert.AreEqual(HttpStatusCode.OK, httpResponseMessage.StatusCode);
Assert.AreEqual("application/json; charset=utf-8", httpResponseMessage.Content.Headers.ContentType?.ToString());
string result = await httpResponseMessage.Content.ReadAsStringAsync();
Assert.IsTrue(result.Contains(appSettings.Company));
httpClient.Dispose();
}
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public void GetAppSettings()
{
_Logger.Information("Starting Web Application");
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
IAppSettingsRepository appSettingsRepository = serviceProvider.GetRequiredService<IAppSettingsRepository>();
List<string> collection = appSettingsRepository.GetAppSettings();
Assert.IsTrue(collection is not null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetAppSettingsApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
string actionName = nameof(IAppSettingsController<object>.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 result = await httpResponseMessage.Content.ReadAsStringAsync();
httpClient.Dispose();
Assert.IsNotNull(result);
Assert.IsTrue(result != "[]");
_Logger.Information($"{_TestContext?.TestName} completed");
}

View File

@ -1,4 +1,6 @@
using Expose.MyIT.Shared.Models.Stateless;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using System.Net;
@ -8,10 +10,14 @@ namespace Expose.MyIT.Tests;
public class UnitTestClientSettingsController
{
private static ILogger? _Logger;
private static string? _ControllerName;
private static TestContext? _TestContext;
private static WebApplicationFactory<Server.Program>? _WebApplicationFactory;
#pragma warning disable CS8618
private static ILogger _Logger;
private static string _ControllerName;
private static TestContext _TestContext;
private static WebApplicationFactory<Server.Program> _WebApplicationFactory;
#pragma warning restore
[ClassInitialize]
public static void ClassInitAsync(TestContext testContext)
@ -25,34 +31,61 @@ public class UnitTestClientSettingsController
[TestMethod]
public void TestControllerName()
{
if (_Logger is null)
throw new NullReferenceException(nameof(_Logger));
if (_ControllerName is null)
throw new NullReferenceException(nameof(_ControllerName));
if (_WebApplicationFactory is null)
throw new NullReferenceException(nameof(_WebApplicationFactory));
_Logger.Information("Starting Web Application");
Assert.AreEqual(Shared.Models.Stateless.Methods.IClientSettingsController.GetRouteName(), _ControllerName);
Assert.AreEqual(IClientSettingsController<object>.GetRouteName(), _ControllerName);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task Get_ShouldReturn()
public void GetClientSettings()
{
_Logger.Information("Starting Web Application");
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
IClientSettingsRepository clientSettingsRepository = serviceProvider.GetRequiredService<IClientSettingsRepository>();
List<string> clientSettings = clientSettingsRepository.GetClientSettings(null);
Assert.IsTrue(clientSettings is not null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetClientSettingsApi()
{
if (_Logger is null)
throw new NullReferenceException(nameof(_Logger));
if (_ControllerName is null)
throw new NullReferenceException(nameof(_ControllerName));
if (_WebApplicationFactory is null)
throw new NullReferenceException(nameof(_WebApplicationFactory));
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
HttpResponseMessage httpResponseMessage = await httpClient.GetAsync($"api/{_ControllerName}");
string actionName = nameof(IClientSettingsController<object>.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 result = await httpResponseMessage.Content.ReadAsStringAsync();
Assert.IsNotNull(result);
httpClient.Dispose();
Assert.IsNotNull(result);
Assert.IsTrue(result != "[]");
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public void GetIpAddress()
{
_Logger.Information("Starting Web Application");
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
IClientSettingsRepository clientSettingsRepository = serviceProvider.GetRequiredService<IClientSettingsRepository>();
string? ipAddress = clientSettingsRepository.GetIpAddress(null);
Assert.IsTrue(ipAddress is not null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetIpAddressApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
string actionName = nameof(IClientSettingsController<object>.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 result = await httpResponseMessage.Content.ReadAsStringAsync();
httpClient.Dispose();
Assert.IsNotNull(result);
_Logger.Information($"{_TestContext?.TestName} completed");
}

View File

@ -1,5 +1,4 @@
using Expose.MyIT.Shared.Models.Methods;
using Expose.MyIT.Shared.Models.Stateless.Methods;
using Expose.MyIT.Shared.Models.Stateless;
using Expose.MyIT.Shared.ViewModels;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
@ -9,13 +8,17 @@ using System.Net;
namespace Expose.MyIT.Tests;
[TestClass]
public class UnitTestServiceShopOrderController : IServiceShopOrder
public class UnitTestServiceShopOrderController
{
private static ILogger? _Logger;
private static string? _ControllerName;
private static TestContext? _TestContext;
private static WebApplicationFactory<Server.Program>? _WebApplicationFactory;
#pragma warning disable CS8618
private static ILogger _Logger;
private static string _ControllerName;
private static TestContext _TestContext;
private static WebApplicationFactory<Server.Program> _WebApplicationFactory;
#pragma warning restore
[ClassInitialize]
public static void ClassInitAsync(TestContext testContext)
@ -29,67 +32,49 @@ public class UnitTestServiceShopOrderController : IServiceShopOrder
[TestMethod]
public void TestControllerName()
{
if (_Logger is null)
throw new NullReferenceException(nameof(_Logger));
if (_ControllerName is null)
throw new NullReferenceException(nameof(_ControllerName));
if (_WebApplicationFactory is null)
throw new NullReferenceException(nameof(_WebApplicationFactory));
_Logger.Information("Starting Web Application");
Assert.AreEqual(IServiceShopOrderController.GetRouteName(), _ControllerName);
Assert.AreEqual(IServiceShopOrderController<string>.GetRouteName(), _ControllerName);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public void TestStatic_GetServiceShopOrders()
public void GetServiceShopOrders()
{
if (_Logger is null)
throw new NullReferenceException(nameof(_Logger));
IServiceShopOrder serviceShopOrder = this;
ServiceShopOrder[] serviceShopOrders = serviceShopOrder.TestStatic_GetServiceShopOrders(null);
ServiceShopOrder[] serviceShopOrders = IServiceShopOrder.GetServiceShopOrders(null);
Assert.IsNotNull(serviceShopOrders);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetAllServiceShopOrders_ShouldReturn()
public async Task GetAllServiceShopOrders()
{
if (_Logger is null)
throw new NullReferenceException(nameof(_Logger));
if (_ControllerName is null)
throw new NullReferenceException(nameof(_ControllerName));
if (_WebApplicationFactory is null)
throw new NullReferenceException(nameof(_WebApplicationFactory));
_Logger.Information("Starting Web Application");
ServiceShopOrder[] serviceShopOrders;
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
IServiceShopOrderRepository ServiceShopOrderRepository = serviceProvider.GetRequiredService<IServiceShopOrderRepository>();
serviceShopOrders = await ServiceShopOrderRepository.GetAllServiceShopOrders();
IServiceShopOrderRepository serviceShopOrderRepository = serviceProvider.GetRequiredService<IServiceShopOrderRepository>();
serviceShopOrders = await serviceShopOrderRepository.GetAllServiceShopOrders();
Assert.IsTrue(serviceShopOrders is not null);
serviceShopOrders = await ServiceShopOrderRepository.GetServiceShopOrders("23188d3d-9b75-ed11-ab8b-0050568f2fc3");
serviceShopOrders = await serviceShopOrderRepository.GetServiceShopOrders("23188d3d-9b75-ed11-ab8b-0050568f2fc3");
Assert.IsTrue(serviceShopOrders is not null && serviceShopOrders.Any());
Assert.IsNotNull(serviceShopOrders[0].ToString());
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetAllServiceShopOrders_API_ShouldReturn()
public async Task GetAllServiceShopOrdersApi()
{
if (_Logger is null)
throw new NullReferenceException(nameof(_Logger));
if (_ControllerName is null)
throw new NullReferenceException(nameof(_ControllerName));
if (_WebApplicationFactory is null)
throw new NullReferenceException(nameof(_WebApplicationFactory));
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
string actionName = nameof(Server.Controllers.ServiceShopOrderController.GetAllServiceShopOrders)[3..];
string actionName = nameof(IServiceShopOrderController<object>.Action.All);
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 result = await httpResponseMessage.Content.ReadAsStringAsync();
Assert.IsNotNull(result);
httpClient.Dispose();
Assert.IsNotNull(result);
Assert.IsTrue(result != "[]");
_Logger.Information($"{_TestContext?.TestName} completed");
}

View File

@ -1,5 +1,4 @@
using Expose.MyIT.Shared.Models.Methods;
using Expose.MyIT.Shared.Models.Stateless.Methods;
using Expose.MyIT.Shared.Models.Stateless;
using Expose.MyIT.Shared.ViewModels;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
@ -9,13 +8,17 @@ using System.Net;
namespace Expose.MyIT.Tests;
[TestClass]
public class UnitTestSsaOrderController : ISsaOrder
public class UnitTestSsaOrderController
{
private static ILogger? _Logger;
private static string? _ControllerName;
private static TestContext? _TestContext;
private static WebApplicationFactory<Server.Program>? _WebApplicationFactory;
#pragma warning disable CS8618
private static ILogger _Logger;
private static string _ControllerName;
private static TestContext _TestContext;
private static WebApplicationFactory<Server.Program> _WebApplicationFactory;
#pragma warning restore
[ClassInitialize]
public static void ClassInitAsync(TestContext testContext)
@ -29,67 +32,49 @@ public class UnitTestSsaOrderController : ISsaOrder
[TestMethod]
public void TestControllerName()
{
if (_Logger is null)
throw new NullReferenceException(nameof(_Logger));
if (_ControllerName is null)
throw new NullReferenceException(nameof(_ControllerName));
if (_WebApplicationFactory is null)
throw new NullReferenceException(nameof(_WebApplicationFactory));
_Logger.Information("Starting Web Application");
Assert.AreEqual(ISsaOrderController.GetRouteName(), _ControllerName);
Assert.AreEqual(ISsaOrderController<string>.GetRouteName(), _ControllerName);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public void TestStatic_GetSsaOrders()
public void GetSsaOrders()
{
if (_Logger is null)
throw new NullReferenceException(nameof(_Logger));
ISsaOrder ssaOrder = this;
SsaOrder[] ssaOrders = ssaOrder.TestStatic_GetSsaOrders(null);
SsaOrder[] ssaOrders = ISsaOrder.GetSsaOrders(null);
Assert.IsNotNull(ssaOrders);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetAllSsaOrders_ShouldReturn()
public async Task GetAllSsaOrders()
{
if (_Logger is null)
throw new NullReferenceException(nameof(_Logger));
if (_ControllerName is null)
throw new NullReferenceException(nameof(_ControllerName));
if (_WebApplicationFactory is null)
throw new NullReferenceException(nameof(_WebApplicationFactory));
_Logger.Information("Starting Web Application");
SsaOrder[] ssaOrders;
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
ISsaOrderRepository SsaOrderRepository = serviceProvider.GetRequiredService<ISsaOrderRepository>();
ssaOrders = await SsaOrderRepository.GetAllSsaOrders();
ISsaOrderRepository ssaOrderRepository = serviceProvider.GetRequiredService<ISsaOrderRepository>();
ssaOrders = await ssaOrderRepository.GetAllSsaOrders();
Assert.IsTrue(ssaOrders is not null);
ssaOrders = await SsaOrderRepository.GetSsaOrders("f0998fc8-c724-ed11-a98b-0050568f497f");
ssaOrders = await ssaOrderRepository.GetSsaOrders("f0998fc8-c724-ed11-a98b-0050568f497f");
Assert.IsTrue(ssaOrders is not null && ssaOrders.Any());
Assert.IsNotNull(ssaOrders[0].ToString());
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetAllSsaOrders_API_ShouldReturn()
public async Task GetAllSsaOrdersApi()
{
if (_Logger is null)
throw new NullReferenceException(nameof(_Logger));
if (_ControllerName is null)
throw new NullReferenceException(nameof(_ControllerName));
if (_WebApplicationFactory is null)
throw new NullReferenceException(nameof(_WebApplicationFactory));
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
string actionName = nameof(Server.Controllers.SsaOrderController.GetAllSsaOrders)[3..];
string actionName = nameof(ISsaOrderController<object>.Action.All);
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 result = await httpResponseMessage.Content.ReadAsStringAsync();
Assert.IsNotNull(result);
httpClient.Dispose();
Assert.IsNotNull(result);
Assert.IsTrue(result != "[]");
_Logger.Information($"{_TestContext?.TestName} completed");
}

View File

@ -8,10 +8,14 @@ namespace Expose.MyIT.Tests;
public class UnitTestWeatherForecastController
{
private static ILogger? _Logger;
private static string? _ControllerName;
private static TestContext? _TestContext;
private static WebApplicationFactory<Server.Program>? _WebApplicationFactory;
#pragma warning disable CS8618
private static ILogger _Logger;
private static string _ControllerName;
private static TestContext _TestContext;
private static WebApplicationFactory<Server.Program> _WebApplicationFactory;
#pragma warning restore
[ClassInitialize]
public static void ClassInitAsync(TestContext testContext)
@ -25,26 +29,14 @@ public class UnitTestWeatherForecastController
[TestMethod]
public void TestControllerName()
{
if (_Logger is null)
throw new NullReferenceException(nameof(_Logger));
if (_ControllerName is null)
throw new NullReferenceException(nameof(_ControllerName));
if (_WebApplicationFactory is null)
throw new NullReferenceException(nameof(_WebApplicationFactory));
_Logger.Information("Starting Web Application");
Assert.AreEqual(Shared.Models.Stateless.Methods.IWeatherForecastController.GetRouteName(), _ControllerName);
Assert.AreEqual(Shared.Models.Stateless.IWeatherForecastController<object>.GetRouteName(), _ControllerName);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetReactors_ShouldReturnAllWeatherForecast()
{
if (_Logger is null)
throw new NullReferenceException(nameof(_Logger));
if (_ControllerName is null)
throw new NullReferenceException(nameof(_ControllerName));
if (_WebApplicationFactory is null)
throw new NullReferenceException(nameof(_WebApplicationFactory));
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
HttpResponseMessage httpResponseMessage = await httpClient.GetAsync($"api/{_ControllerName}");