From 978e698da59e559f1e723f2340b20c00696ff076 Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Wed, 4 Jan 2023 09:38:00 -0700 Subject: [PATCH] CORS, Theme, Better flow and dotnet tools --- .config/dotnet-tools.json | 20 +++++ Blazor/App.razor | 11 --- Blazor/Blazor.csproj | 16 ---- Blazor/Blazor.sln | 25 ------ Blazor/Pages/Counter.razor | 17 ---- Blazor/Pages/FetchData.razor | 52 ------------- Blazor/Pages/Index.razor | 7 -- Blazor/Program.cs | 13 ---- Blazor/Shared/MainLayout.razor | 34 -------- Blazor/Shared/NavMenu.razor | 5 -- Blazor/_Imports.razor | 11 --- Blazor/wwwroot/favicon.ico | Bin 15086 -> 0 bytes Blazor/wwwroot/index.html | 25 ------ Blazor/wwwroot/sample-data/weather.json | 27 ------- Client/.vscode/settings.json | 1 + Client/Expose.MyIT.Client.csproj | 1 + Client/Pages/Counter.razor | 14 +--- Client/Pages/Counter.razor.cs | 20 +++++ Client/Pages/FetchData.razor | 1 - Client/Pages/FetchServiceShopOrders.razor | 14 +++- Client/Pages/FetchServiceShopOrders.razor.cs | 3 +- Client/Pages/FetchSsaOrders.razor | 34 -------- Client/Pages/FetchSsaOrders.razor.cs | 32 -------- Client/Program.cs | 7 +- Client/Shared/MainLayout.razor | 3 + Client/Shared/MainLayout.razor.cs | 16 +++- Client/wwwroot/index.html | 1 + Expose-MyIT.sln | 2 +- ReadMe.md | 26 +++++++ Server/Controllers/AppSettingsController.cs | 26 +++---- .../Controllers/ClientSettingsController.cs | 37 ++++----- .../Controllers/ServiceShopOrderController.cs | 22 ++---- Server/Controllers/SsaOrderController.cs | 22 ++---- .../Controllers/WeatherForecastController.cs | 6 +- Server/Models/AppSettings.cs | 47 +++-------- Server/Models/AppSettingsRepository.cs | 28 +++++++ Server/Models/ClientSettingsRepository.cs | 35 +++++++++ Server/Models/ServiceShopOrderRepository.cs | 23 +++--- Server/Models/SsaOrderRepository.cs | 25 +++--- Server/Program.cs | 10 ++- Shared/Models/IServiceShopOrderController.cs | 11 --- Shared/Models/ISsaOrderController.cs | 11 --- Shared/Models/Order2.cs | 9 --- Shared/Models/SSA.cs | 2 +- .../Stateless/IAppSettingsController.cs | 14 ++++ .../Stateless/IAppSettingsRepository.cs | 8 ++ .../Stateless/IClientSettingsController.cs | 16 ++++ .../Stateless/IClientSettingsRepository.cs | 11 +++ .../Stateless/{Methods => }/IMethodName.cs | 2 +- .../{Methods => }/IServiceShopOrder.cs | 4 +- .../Stateless/IServiceShopOrderController.cs | 15 ++++ .../IServiceShopOrderRepository.cs | 2 +- Shared/Models/Stateless/ISsaOrder.cs | 11 +++ .../Models/Stateless/ISsaOrderController.cs | 15 ++++ .../ISsaOrderRepository.cs | 2 +- .../Stateless/IWeatherForecastController.cs | 9 +++ .../Methods/IAppSettingsController.cs | 9 --- .../Methods/IClientSettingsController.cs | 10 --- .../Methods/IServiceShopOrderController.cs | 10 --- Shared/Models/Stateless/Methods/ISsaOrder.cs | 11 --- .../Stateless/Methods/ISsaOrderController.cs | 10 --- .../Methods/IWeatherForecastController.cs | 9 --- .../{Methods => }/ServiceShopOrder.cs | 4 +- .../Stateless/{Methods => }/SsaOrder.cs | 6 +- Shared/ViewModels/ServiceShopOrder.cs | 36 +++------ Shared/ViewModels/SsaOrder.cs | 36 +++------ Shared/ViewModels/WeatherForecast.cs | 21 ++--- Tests/UnitTestAppSettingsController.cs | 66 +++++++++------- Tests/UnitTestClientSettingsController.cs | 73 +++++++++++++----- Tests/UnitTestServiceShopOrderController.cs | 57 +++++--------- Tests/UnitTestSsaOrderController.cs | 57 +++++--------- Tests/UnitTestWeatherForecastController.cs | 26 +++---- 72 files changed, 528 insertions(+), 774 deletions(-) create mode 100644 .config/dotnet-tools.json delete mode 100644 Blazor/App.razor delete mode 100644 Blazor/Blazor.csproj delete mode 100644 Blazor/Blazor.sln delete mode 100644 Blazor/Pages/Counter.razor delete mode 100644 Blazor/Pages/FetchData.razor delete mode 100644 Blazor/Pages/Index.razor delete mode 100644 Blazor/Program.cs delete mode 100644 Blazor/Shared/MainLayout.razor delete mode 100644 Blazor/Shared/NavMenu.razor delete mode 100644 Blazor/_Imports.razor delete mode 100644 Blazor/wwwroot/favicon.ico delete mode 100644 Blazor/wwwroot/index.html delete mode 100644 Blazor/wwwroot/sample-data/weather.json create mode 100644 Client/Pages/Counter.razor.cs delete mode 100644 Client/Pages/FetchSsaOrders.razor delete mode 100644 Client/Pages/FetchSsaOrders.razor.cs create mode 100644 ReadMe.md create mode 100644 Server/Models/AppSettingsRepository.cs create mode 100644 Server/Models/ClientSettingsRepository.cs delete mode 100644 Shared/Models/IServiceShopOrderController.cs delete mode 100644 Shared/Models/ISsaOrderController.cs delete mode 100644 Shared/Models/Order2.cs create mode 100644 Shared/Models/Stateless/IAppSettingsController.cs create mode 100644 Shared/Models/Stateless/IAppSettingsRepository.cs create mode 100644 Shared/Models/Stateless/IClientSettingsController.cs create mode 100644 Shared/Models/Stateless/IClientSettingsRepository.cs rename Shared/Models/Stateless/{Methods => }/IMethodName.cs (75%) rename Shared/Models/Stateless/{Methods => }/IServiceShopOrder.cs (70%) create mode 100644 Shared/Models/Stateless/IServiceShopOrderController.cs rename Shared/Models/{Methods => Stateless}/IServiceShopOrderRepository.cs (80%) create mode 100644 Shared/Models/Stateless/ISsaOrder.cs create mode 100644 Shared/Models/Stateless/ISsaOrderController.cs rename Shared/Models/{Methods => Stateless}/ISsaOrderRepository.cs (76%) create mode 100644 Shared/Models/Stateless/IWeatherForecastController.cs delete mode 100644 Shared/Models/Stateless/Methods/IAppSettingsController.cs delete mode 100644 Shared/Models/Stateless/Methods/IClientSettingsController.cs delete mode 100644 Shared/Models/Stateless/Methods/IServiceShopOrderController.cs delete mode 100644 Shared/Models/Stateless/Methods/ISsaOrder.cs delete mode 100644 Shared/Models/Stateless/Methods/ISsaOrderController.cs delete mode 100644 Shared/Models/Stateless/Methods/IWeatherForecastController.cs rename Shared/Models/Stateless/{Methods => }/ServiceShopOrder.cs (82%) rename Shared/Models/Stateless/{Methods => }/SsaOrder.cs (66%) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..daf83f6 --- /dev/null +++ b/.config/dotnet-tools.json @@ -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" + ] + } + } +} \ No newline at end of file diff --git a/Blazor/App.razor b/Blazor/App.razor deleted file mode 100644 index b80db76..0000000 --- a/Blazor/App.razor +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - Not found - -

Sorry, there's nothing at this address.

-
-
-
\ No newline at end of file diff --git a/Blazor/Blazor.csproj b/Blazor/Blazor.csproj deleted file mode 100644 index a9ac2ac..0000000 --- a/Blazor/Blazor.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - - - - \ No newline at end of file diff --git a/Blazor/Blazor.sln b/Blazor/Blazor.sln deleted file mode 100644 index 8c9decb..0000000 --- a/Blazor/Blazor.sln +++ /dev/null @@ -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 \ No newline at end of file diff --git a/Blazor/Pages/Counter.razor b/Blazor/Pages/Counter.razor deleted file mode 100644 index 0cc164c..0000000 --- a/Blazor/Pages/Counter.razor +++ /dev/null @@ -1,17 +0,0 @@ -@page "/counter" - -Counter - -Counter -Current count: @currentCount -Click me - - -@code { - private int currentCount = 0; - - private void IncrementCount() - { - currentCount++; - } -} diff --git a/Blazor/Pages/FetchData.razor b/Blazor/Pages/FetchData.razor deleted file mode 100644 index f41da93..0000000 --- a/Blazor/Pages/FetchData.razor +++ /dev/null @@ -1,52 +0,0 @@ -@page "/fetchdata" -@inject HttpClient Http -@using Blazor.Shared - -Weather forecast - -Weather forecast -This component demonstrates fetching data from the server. -@if (forecasts == null) -{ - -} -else -{ - - - Date - Temp. (C) - Temp. (F) - Summary - - - @context.Date - @context.TemperatureC - @context.TemperatureF - @context.Summary - - - - - -} - - -@code { - private WeatherForecast[]? forecasts; - - protected override async Task OnInitializedAsync() - { - forecasts = await Http.GetFromJsonAsync("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); - } -} diff --git a/Blazor/Pages/Index.razor b/Blazor/Pages/Index.razor deleted file mode 100644 index 7994d54..0000000 --- a/Blazor/Pages/Index.razor +++ /dev/null @@ -1,7 +0,0 @@ -@page "/" - -Index - -Hello, world! -Welcome to your new app, powered by MudBlazor! -You can find documentation and examples on our website here: www.mudblazor.com diff --git a/Blazor/Program.cs b/Blazor/Program.cs deleted file mode 100644 index f0c9ceb..0000000 --- a/Blazor/Program.cs +++ /dev/null @@ -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"); -builder.RootComponents.Add("head::after"); - -builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); -builder.Services.AddMudServices(); - -await builder.Build().RunAsync(); diff --git a/Blazor/Shared/MainLayout.razor b/Blazor/Shared/MainLayout.razor deleted file mode 100644 index 42ac8b5..0000000 --- a/Blazor/Shared/MainLayout.razor +++ /dev/null @@ -1,34 +0,0 @@ -@inherits LayoutComponentBase - - - - - - - - - - - - - - - Blazor - - - - - - @Body - - - - -@code { - bool _drawerOpen = true; - - void DrawerToggle() - { - _drawerOpen = !_drawerOpen; - } -} \ No newline at end of file diff --git a/Blazor/Shared/NavMenu.razor b/Blazor/Shared/NavMenu.razor deleted file mode 100644 index 0772484..0000000 --- a/Blazor/Shared/NavMenu.razor +++ /dev/null @@ -1,5 +0,0 @@ - - Home - Counter - Fetch data - diff --git a/Blazor/_Imports.razor b/Blazor/_Imports.razor deleted file mode 100644 index e8843f2..0000000 --- a/Blazor/_Imports.razor +++ /dev/null @@ -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 diff --git a/Blazor/wwwroot/favicon.ico b/Blazor/wwwroot/favicon.ico deleted file mode 100644 index 12392236657563eb8cc764f235e66d568b3a0fbb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15086 zcmd5@3vgXU89or@;sb&xh>sx^P*g@JAPS{Yd_tiueWi_Q(uStVO_SUgeWuMhXESw* zFTgS?1+faFJmjS?j^l{KW$MUNQRF4GG;Mi{HEn^W?Ir8??>T$U?zwwz&J9WFoo@fL zyZ>{a|NgtNtV66CYy5Z%aGZ6^r!DJCmSv3_=jV^Itmjd76d=`iyvMTE0^zg30g2Uu zMCIalk_Qgt|D3VIc-Fau=bfv0&e@3c9MWc_Cwb1k2g%_DMkXCpKVB%j4?3hAp%_Srwg;P_+2y@BU?Pv%*BDe&H|fIGkot3MH^3zhSx?rD75 zr91frjXX%R7CjY56EpVr@J#QCl7_}E{D^Lm!enjQR-q7jt3+IJx zuIf(TGg~)l1bznc;fu-f>BFpjW)zp#*Vh2=*>YUHJz?kkGMp&?oO_kZpEqSE#J0P% zgZhOrc)0oxvfhZudq&3yb4K0r?zJI?=+6ZDJ1+>Re%|QK9>(ij!P__hvr7>m0uDvUuIehDNu5kpji^qxqY%+;3t~DV*EYI+m@{f`DkNOx2dtq(|=~`W=&R> zP0;Dtd0KtWxk;@1i&uU~EAM0<1l{X`Hfy(Qb; zLjSZnc6gr64C@U2l5_h!{nqcd5a zA<7W`cvsJdQU4-ev7$CCO}u{6_}GKAOOc_E899F?q%kz3wO^A}u)pHdzoF{KbJ2Mr z`ZcZ6(zof1n0)>^1CYHhvHq<~NdGOW4*r>uV~l@CE6=+>Fz|gq#fkf_LjRW_Bf59S z_d)k+jGsmN{B2=}gU59oQ0jv{>QI!uV9=lQ%h+cmUK~uUKb?=gcv8I1a_mT0pME?} zt}Mqm`kGO9;t}a5Nu$CF{Im0oRbN*tINoDBE&x6lU0@=iGMJ%73^Zf)o3M&0Db57NNFVFTOVz2*r zd;5FQ@AoB;D|zkaU90PKE?y2i9vOzu{^%K=`V%zfHCv9I5N^R5H(8uT#F>yy1TDq( zrEW>#X7v4RzJz^5_|z1K$+}l0;PaapyDtE3(*7qM_ai0WzpJ+|rXB1roAjqL=yN4f z4BbIco^|ey(_QHA?fusuq&Dp3`QFb}(qGoWf1Cyz{&sNL;jWSTC54<~e5c6<~Nlvw8h?jmG`)ecy?p|)sC)qb z5$v}t*N2k`7A>pJhlu`(Ji$rD;&Ca!adsDMn01Hp%=C_B`P+9u{qU9EUO zu0-+Skbko87e-?}75iW^c_#g^w)dV~t<5Sv?A|&8+f`kjPB32|RN?b2P8mvscOCpBoi^6vLUd7h0!dBm5n|BPke5Ze1S z8rgSwHeKUAyK@4cI)AVBK4DhdqZ$tF$&#M#SCsjU`OlO(_+NHj(xTkdK2MN-LjUHD zWBJqtx@@|epSob5384*8UyA5iz*u-<8t`k~A$KkKaJbJM5sdEI)9GGlYRbMbVT zv$!YZW8dfV-=*G*1ohsX`I`bKZ!ZeUW98d_;tLAv6rIDiXB6;dC}PTvvob^eZhFH8Bd`wYCVl6X;AK|bvx|3Na_-;MVHbJBqyj5hs7 zXnWaR$iJd;Wxj%Z@>w5_l}~!j>sl}Qs1P*pF(P{B*%>O1{05#m{w(IRh+moQC;n~A z9LYyQx(^0V!~S1>7f&?6-Cm}v(B1CEp8N&W>GNN;t8;Z(zhVq@oB840f^uIP=xbho zX^lSD*YB1Xesqq$TJjON-uv}J(~NdBY8Q|zmTeNy!A9udnYUz6_C zhQE`dF+ErGk$6WC%+W|6+rsUax`HMh+Xh~Ll!mE~@Q;j5wNGiEio81!?cn__Lp6Lx zh^xQLk!|4Xa52W$J+RfZXOB>x(iY?kCydv6XIpj#`f@sSS_PdD7tmq_)#`({pZ000 zz14n;x2!qm!4Zsw5}lQ*kq7){$f3Em8S%=Al9v2elvSg{9?Y9Ll0FFp|LA;pMSaua z#g*gMHKo6E&Zd#Xi6Osy&BooJsyo``R3n}@*WMCw5XAdbnxx+`?fcCrJ@&+-(Y8y` zSHHp-{hb$!!8=u~JyG0h^7MBB(1HA2dP}p5)?vB#R>NmFT+Y{UK7=q!$(qCm5mFei zYLQY%H9H6HU(>&HV_$LW_CB_KJ7e2-GpiLTeJ-=wCowCF-VdI{d!jXI=y=O5)mgk$_W&QN!4JMK#^Oq!H^nlS z!;f0W>75v*$$0bG*f}0Jjle;ix#t)`kF&YR!;b=77SiKARCh0YPv6c4ynAivYR0^7 zLD{|jTjOOO58O3*=j4#yJDY}nF1-hC>}&=7BC)pTj zvpe!P0ra - - - - - - Blazor - - - - - - -
Loading...
- -
- An unhandled error has occurred. - Reload - 🗙 -
- - - - - \ No newline at end of file diff --git a/Blazor/wwwroot/sample-data/weather.json b/Blazor/wwwroot/sample-data/weather.json deleted file mode 100644 index 06463c0..0000000 --- a/Blazor/wwwroot/sample-data/weather.json +++ /dev/null @@ -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" - } -] diff --git a/Client/.vscode/settings.json b/Client/.vscode/settings.json index 84167fe..e1d83b6 100644 --- a/Client/.vscode/settings.json +++ b/Client/.vscode/settings.json @@ -1,6 +1,7 @@ { "coverage-gutters.coverageBaseDir": "../.vscode/TestResults/*", "cSpell.words": [ + "ASPNETCORE", "Blazor", "Serilog", "Setpoint" diff --git a/Client/Expose.MyIT.Client.csproj b/Client/Expose.MyIT.Client.csproj index 0f7214d..3cfec0a 100644 --- a/Client/Expose.MyIT.Client.csproj +++ b/Client/Expose.MyIT.Client.csproj @@ -15,6 +15,7 @@ + diff --git a/Client/Pages/Counter.razor b/Client/Pages/Counter.razor index 0cc164c..5cc100e 100644 --- a/Client/Pages/Counter.razor +++ b/Client/Pages/Counter.razor @@ -3,15 +3,5 @@ Counter Counter -Current count: @currentCount -Click me - - -@code { - private int currentCount = 0; - - private void IncrementCount() - { - currentCount++; - } -} +Current count: @_CurrentCount +Click me \ No newline at end of file diff --git a/Client/Pages/Counter.razor.cs b/Client/Pages/Counter.razor.cs new file mode 100644 index 0000000..8edd726 --- /dev/null +++ b/Client/Pages/Counter.razor.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Components; + +namespace Expose.MyIT.Client.Pages; + +public partial class Counter +{ + + [Inject] protected ILogger? 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++; + } + +} \ No newline at end of file diff --git a/Client/Pages/FetchData.razor b/Client/Pages/FetchData.razor index 57cd3fd..4f04d81 100644 --- a/Client/Pages/FetchData.razor +++ b/Client/Pages/FetchData.razor @@ -1,5 +1,4 @@ @page "/fetchdata" -@using Expose.MyIT.Shared @using Expose.MyIT.Shared.ViewModels Weather forecast diff --git a/Client/Pages/FetchServiceShopOrders.razor b/Client/Pages/FetchServiceShopOrders.razor index cb8f460..4d5d53a 100644 --- a/Client/Pages/FetchServiceShopOrders.razor +++ b/Client/Pages/FetchServiceShopOrders.razor @@ -1,5 +1,4 @@ @page "/fetchServiceShoporders" -@using Expose.MyIT.Shared @using Expose.MyIT.Shared.ViewModels Service-Shop Orders @@ -13,12 +12,21 @@ else { - CreatedDate + Id + Name + Booking Names + Type + State + Item Number + Created Date + Decided Date + Recipient + Requestor @context.Id @context.Name - @context.BookingNames + @string.Join(' ', context.BookingNames) @context.Type @context.State @context.ItemNumber diff --git a/Client/Pages/FetchServiceShopOrders.razor.cs b/Client/Pages/FetchServiceShopOrders.razor.cs index 144f172..1f19b80 100644 --- a/Client/Pages/FetchServiceShopOrders.razor.cs +++ b/Client/Pages/FetchServiceShopOrders.razor.cs @@ -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($"api/{controllerName}"); + string actionName = nameof(MyIT.Shared.Models.Stateless.Methods.ISsaOrderController.GetAllSsaOrders).Substring(3, 3); + _ServiceShopOrders = await Http.GetFromJsonAsync($"api/{controllerName}/{actionName}"); } } \ No newline at end of file diff --git a/Client/Pages/FetchSsaOrders.razor b/Client/Pages/FetchSsaOrders.razor deleted file mode 100644 index 101bd38..0000000 --- a/Client/Pages/FetchSsaOrders.razor +++ /dev/null @@ -1,34 +0,0 @@ -@page "/fetchssaorders" -@using Expose.MyIT.Shared -@using Expose.MyIT.Shared.ViewModels - -SSA Orders - -SSA Orders -@if (_SsaOrders == null) -{ - -} -else -{ - - - CreatedDate - - - @context.Id - @context.Name - @context.BookingNames - @context.Type - @context.State - @context.ItemNumber - @context.CreatedDate - @context.DecidedDate - @context.Recipient - @context.Requestor - - - - - -} \ No newline at end of file diff --git a/Client/Pages/FetchSsaOrders.razor.cs b/Client/Pages/FetchSsaOrders.razor.cs deleted file mode 100644 index b153b13..0000000 --- a/Client/Pages/FetchSsaOrders.razor.cs +++ /dev/null @@ -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($"api/{controllerName}"); - } -} \ No newline at end of file diff --git a/Client/Program.cs b/Client/Program.cs index 80f7b35..5cfdcee 100644 --- a/Client/Program.cs +++ b/Client/Program.cs @@ -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(); try @@ -26,7 +25,7 @@ internal class Program builder.RootComponents.Add("#app"); builder.RootComponents.Add("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"); diff --git a/Client/Shared/MainLayout.razor b/Client/Shared/MainLayout.razor index 48897ff..a0b8193 100644 --- a/Client/Shared/MainLayout.razor +++ b/Client/Shared/MainLayout.razor @@ -4,12 +4,15 @@ + + + diff --git a/Client/Shared/MainLayout.razor.cs b/Client/Shared/MainLayout.razor.cs index 7b689d4..a319ead 100644 --- a/Client/Shared/MainLayout.razor.cs +++ b/Client/Shared/MainLayout.razor.cs @@ -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(); + } + } + } \ No newline at end of file diff --git a/Client/wwwroot/index.html b/Client/wwwroot/index.html index 80935b6..357210a 100644 --- a/Client/wwwroot/index.html +++ b/Client/wwwroot/index.html @@ -31,6 +31,7 @@ + diff --git a/Expose-MyIT.sln b/Expose-MyIT.sln index 7b1b1f5..19a6b61 100644 --- a/Expose-MyIT.sln +++ b/Expose-MyIT.sln @@ -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 diff --git a/ReadMe.md b/ReadMe.md new file mode 100644 index 0000000..cf75e08 --- /dev/null +++ b/ReadMe.md @@ -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 \ No newline at end of file diff --git a/Server/Controllers/AppSettingsController.cs b/Server/Controllers/AppSettingsController.cs index b7610d9..4d65d87 100644 --- a/Server/Controllers/AppSettingsController.cs +++ b/Server/Controllers/AppSettingsController.cs @@ -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 { - 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.Action.App))] + public ActionResult GetAppSettings() { - List results = new(); - string json = JsonSerializer.Serialize(_AppSettings); - JsonElement jsonElement = JsonSerializer.Deserialize(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 results = _AppSettingsRepository.GetAppSettings(); + return Ok(results); } } \ No newline at end of file diff --git a/Server/Controllers/ClientSettingsController.cs b/Server/Controllers/ClientSettingsController.cs index 9fe1ca6..c8f6759 100644 --- a/Server/Controllers/ClientSettingsController.cs +++ b/Server/Controllers/ClientSettingsController.cs @@ -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 { - 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.Action.Client))] + public ActionResult GetClientSettings() { - List 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 results = _ClientSettingsRepository.GetClientSettings(Request.HttpContext.Connection?.RemoteIpAddress); + return Ok(results); } - [Route("api/[controller]/IpAddress")] - [HttpGet] - public string GetIpAddress() + [HttpGet(nameof(IClientSettingsController.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); } } \ No newline at end of file diff --git a/Server/Controllers/ServiceShopOrderController.cs b/Server/Controllers/ServiceShopOrderController.cs index 2bd162f..e843ecc 100644 --- a/Server/Controllers/ServiceShopOrderController.cs +++ b/Server/Controllers/ServiceShopOrderController.cs @@ -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 { - private readonly IServiceShopOrderController _ServiceShopOrderController; private readonly IServiceShopOrderRepository _ServiceShopOrderRepository; - public ServiceShopOrderController(IServiceShopOrderRepository ServiceShopOrderRepository) - { - _ServiceShopOrderController = this; - _ServiceShopOrderRepository = ServiceShopOrderRepository; - } + public ServiceShopOrderController(IServiceShopOrderRepository ServiceShopOrderRepository) => _ServiceShopOrderRepository = ServiceShopOrderRepository; - async Task IServiceShopOrderController.GetAllServiceShopOrders() => await _ServiceShopOrderRepository.GetAllServiceShopOrders(); - - async Task IServiceShopOrderController.GetServiceShopOrders(string id) => await _ServiceShopOrderRepository.GetServiceShopOrders(id); - - [HttpGet(nameof(Shared.Models.Stateless.IServiceShopOrderController.Action.All))] + [HttpGet(nameof(IServiceShopOrderController.Action.All))] public async Task 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) diff --git a/Server/Controllers/SsaOrderController.cs b/Server/Controllers/SsaOrderController.cs index 8cf11f2..4b3aaa7 100644 --- a/Server/Controllers/SsaOrderController.cs +++ b/Server/Controllers/SsaOrderController.cs @@ -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 { - private readonly ISsaOrderController _SsaOrderController; private readonly ISsaOrderRepository _SsaOrderRepository; - public SsaOrderController(ISsaOrderRepository SsaOrderRepository) - { - _SsaOrderController = this; - _SsaOrderRepository = SsaOrderRepository; - } + public SsaOrderController(ISsaOrderRepository SsaOrderRepository) => _SsaOrderRepository = SsaOrderRepository; - async Task ISsaOrderController.GetAllSsaOrders() => await _SsaOrderRepository.GetAllSsaOrders(); - - async Task ISsaOrderController.GetSsaOrders(string id) => await _SsaOrderRepository.GetSsaOrders(id); - - [HttpGet(nameof(Shared.Models.Stateless.ISsaOrderController.Action.All))] + [HttpGet(nameof(ISsaOrderController.Action.All))] public async Task 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) diff --git a/Server/Controllers/WeatherForecastController.cs b/Server/Controllers/WeatherForecastController.cs index 3afa1bb..f6fb27b 100644 --- a/Server/Controllers/WeatherForecastController.cs +++ b/Server/Controllers/WeatherForecastController.cs @@ -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 { private static readonly string[] _Summaries = new[] { @@ -18,8 +18,6 @@ public class WeatherForecastController : ControllerBase, IWeatherForecastControl public WeatherForecastController(ILogger logger) => _Logger = logger; - Task IWeatherForecastController.Get() => throw new NotImplementedException(); - [HttpGet] public WeatherForecast[] Get() { diff --git a/Server/Models/AppSettings.cs b/Server/Models/AppSettings.cs index 21710ad..09f6fe8 100644 --- a/Server/Models/AppSettings.cs +++ b/Server/Models/AppSettings.cs @@ -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 }); diff --git a/Server/Models/AppSettingsRepository.cs b/Server/Models/AppSettingsRepository.cs new file mode 100644 index 0000000..aa8f709 --- /dev/null +++ b/Server/Models/AppSettingsRepository.cs @@ -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 GetAppSettings() + { + List results = new(); + string json = JsonSerializer.Serialize(_AppSettings); + JsonElement jsonElement = JsonSerializer.Deserialize(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 IAppSettingsRepository.GetAppSettings() => GetAppSettings(); + +} \ No newline at end of file diff --git a/Server/Models/ClientSettingsRepository.cs b/Server/Models/ClientSettingsRepository.cs new file mode 100644 index 0000000..af2e7ac --- /dev/null +++ b/Server/Models/ClientSettingsRepository.cs @@ -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 GetClientSettings(IPAddress? remoteIpAddress) + { + List 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 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); + +} \ No newline at end of file diff --git a/Server/Models/ServiceShopOrderRepository.cs b/Server/Models/ServiceShopOrderRepository.cs index 8e67289..2e8d544 100644 --- a/Server/Models/ServiceShopOrderRepository.cs +++ b/Server/Models/ServiceShopOrderRepository.cs @@ -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(); - 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(json); return result; @@ -30,12 +35,12 @@ public class ServiceShopOrderRepository : IServiceShopOrderRepository async Task 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 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; } diff --git a/Server/Models/SsaOrderRepository.cs b/Server/Models/SsaOrderRepository.cs index 0a9448e..eea0aa1 100644 --- a/Server/Models/SsaOrderRepository.cs +++ b/Server/Models/SsaOrderRepository.cs @@ -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(); - 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(json); + result = JsonSerializer.Deserialize(json); return result; } async Task 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 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; } diff --git a/Server/Program.cs b/Server/Program.cs index 22350bf..7a226c9 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -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); + _ = builder.Services.AddSingleton(_ => appSettings); _ = builder.Services.AddSingleton(); + _ = builder.Services.AddSingleton(_ => appSettingsRepository); + _ = builder.Services.AddSingleton(_ => clientSettingsRepository); _ = builder.Services.AddSingleton(); _ = 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(); diff --git a/Shared/Models/IServiceShopOrderController.cs b/Shared/Models/IServiceShopOrderController.cs deleted file mode 100644 index ebff491..0000000 --- a/Shared/Models/IServiceShopOrderController.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Expose.MyIT.Shared.Models.Stateless; - -public interface IServiceShopOrderController -{ - - enum Action : int - { - All = 0 - } - -} \ No newline at end of file diff --git a/Shared/Models/ISsaOrderController.cs b/Shared/Models/ISsaOrderController.cs deleted file mode 100644 index f35b8fd..0000000 --- a/Shared/Models/ISsaOrderController.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Expose.MyIT.Shared.Models.Stateless; - -public interface ISsaOrderController -{ - - enum Action : int - { - All = 0 - } - -} \ No newline at end of file diff --git a/Shared/Models/Order2.cs b/Shared/Models/Order2.cs deleted file mode 100644 index 18f104c..0000000 --- a/Shared/Models/Order2.cs +++ /dev/null @@ -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 - ); \ No newline at end of file diff --git a/Shared/Models/SSA.cs b/Shared/Models/SSA.cs index a87aa23..1d50118 100644 --- a/Shared/Models/SSA.cs +++ b/Shared/Models/SSA.cs @@ -2,7 +2,7 @@ using System.Text.Json.Serialization; namespace Expose.MyIT.Shared.Models; -public record SSA( +public record Ssa( [property: JsonPropertyName("Orders")] IReadOnlyList Orders, [property: JsonPropertyName("Total")] int Total ); \ No newline at end of file diff --git a/Shared/Models/Stateless/IAppSettingsController.cs b/Shared/Models/Stateless/IAppSettingsController.cs new file mode 100644 index 0000000..9a97e94 --- /dev/null +++ b/Shared/Models/Stateless/IAppSettingsController.cs @@ -0,0 +1,14 @@ +namespace Expose.MyIT.Shared.Models.Stateless; + +public interface IAppSettingsController +{ + + enum Action : int + { + App = 0 + } + + static string GetRouteName() => nameof(IAppSettingsController)[1..^10]; + T GetAppSettings(); + +} \ No newline at end of file diff --git a/Shared/Models/Stateless/IAppSettingsRepository.cs b/Shared/Models/Stateless/IAppSettingsRepository.cs new file mode 100644 index 0000000..e48e1ea --- /dev/null +++ b/Shared/Models/Stateless/IAppSettingsRepository.cs @@ -0,0 +1,8 @@ +namespace Expose.MyIT.Shared.Models.Stateless; + +public interface IAppSettingsRepository +{ + + List GetAppSettings(); + +} \ No newline at end of file diff --git a/Shared/Models/Stateless/IClientSettingsController.cs b/Shared/Models/Stateless/IClientSettingsController.cs new file mode 100644 index 0000000..d548db1 --- /dev/null +++ b/Shared/Models/Stateless/IClientSettingsController.cs @@ -0,0 +1,16 @@ +namespace Expose.MyIT.Shared.Models.Stateless; + +public interface IClientSettingsController +{ + + enum Action : int + { + Client = 0, + IP = 1 + } + + static string GetRouteName() => nameof(IClientSettingsController)[1..^10]; + T GetClientSettings(); + T GetIpAddress(); + +} \ No newline at end of file diff --git a/Shared/Models/Stateless/IClientSettingsRepository.cs b/Shared/Models/Stateless/IClientSettingsRepository.cs new file mode 100644 index 0000000..e767ef4 --- /dev/null +++ b/Shared/Models/Stateless/IClientSettingsRepository.cs @@ -0,0 +1,11 @@ +using System.Net; + +namespace Expose.MyIT.Shared.Models.Stateless; + +public interface IClientSettingsRepository +{ + + List GetClientSettings(IPAddress? remoteIpAddress); + string GetIpAddress(IPAddress? remoteIpAddress); + +} \ No newline at end of file diff --git a/Shared/Models/Stateless/Methods/IMethodName.cs b/Shared/Models/Stateless/IMethodName.cs similarity index 75% rename from Shared/Models/Stateless/Methods/IMethodName.cs rename to Shared/Models/Stateless/IMethodName.cs index 43643fd..b5a28fa 100644 --- a/Shared/Models/Stateless/Methods/IMethodName.cs +++ b/Shared/Models/Stateless/IMethodName.cs @@ -1,6 +1,6 @@ using System.Runtime.CompilerServices; -namespace Expose.MyIT.Shared.Models.Stateless.Methods; +namespace Expose.MyIT.Shared.Models.Stateless; public interface IMethodName { diff --git a/Shared/Models/Stateless/Methods/IServiceShopOrder.cs b/Shared/Models/Stateless/IServiceShopOrder.cs similarity index 70% rename from Shared/Models/Stateless/Methods/IServiceShopOrder.cs rename to Shared/Models/Stateless/IServiceShopOrder.cs index e9fc405..385765f 100644 --- a/Shared/Models/Stateless/Methods/IServiceShopOrder.cs +++ b/Shared/Models/Stateless/IServiceShopOrder.cs @@ -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); } \ No newline at end of file diff --git a/Shared/Models/Stateless/IServiceShopOrderController.cs b/Shared/Models/Stateless/IServiceShopOrderController.cs new file mode 100644 index 0000000..db454eb --- /dev/null +++ b/Shared/Models/Stateless/IServiceShopOrderController.cs @@ -0,0 +1,15 @@ +namespace Expose.MyIT.Shared.Models.Stateless; + +public interface IServiceShopOrderController +{ + + enum Action : int + { + All = 0 + } + + static string GetRouteName() => nameof(IServiceShopOrderController)[1..^10]; + Task GetAllServiceShopOrders(); + Task GetServiceShopOrders(string id); + +} \ No newline at end of file diff --git a/Shared/Models/Methods/IServiceShopOrderRepository.cs b/Shared/Models/Stateless/IServiceShopOrderRepository.cs similarity index 80% rename from Shared/Models/Methods/IServiceShopOrderRepository.cs rename to Shared/Models/Stateless/IServiceShopOrderRepository.cs index 77b5b44..ca927b4 100644 --- a/Shared/Models/Methods/IServiceShopOrderRepository.cs +++ b/Shared/Models/Stateless/IServiceShopOrderRepository.cs @@ -1,4 +1,4 @@ -namespace Expose.MyIT.Shared.Models.Methods; +namespace Expose.MyIT.Shared.Models.Stateless; public interface IServiceShopOrderRepository { diff --git a/Shared/Models/Stateless/ISsaOrder.cs b/Shared/Models/Stateless/ISsaOrder.cs new file mode 100644 index 0000000..08e2ddb --- /dev/null +++ b/Shared/Models/Stateless/ISsaOrder.cs @@ -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); + +} \ No newline at end of file diff --git a/Shared/Models/Stateless/ISsaOrderController.cs b/Shared/Models/Stateless/ISsaOrderController.cs new file mode 100644 index 0000000..bf2f2b9 --- /dev/null +++ b/Shared/Models/Stateless/ISsaOrderController.cs @@ -0,0 +1,15 @@ +namespace Expose.MyIT.Shared.Models.Stateless; + +public interface ISsaOrderController +{ + + enum Action : int + { + All = 0 + } + + static string GetRouteName() => nameof(ISsaOrderController)[1..^10]; + Task GetAllSsaOrders(); + Task GetSsaOrders(string id); + +} \ No newline at end of file diff --git a/Shared/Models/Methods/ISsaOrderRepository.cs b/Shared/Models/Stateless/ISsaOrderRepository.cs similarity index 76% rename from Shared/Models/Methods/ISsaOrderRepository.cs rename to Shared/Models/Stateless/ISsaOrderRepository.cs index 80412dd..0d99942 100644 --- a/Shared/Models/Methods/ISsaOrderRepository.cs +++ b/Shared/Models/Stateless/ISsaOrderRepository.cs @@ -1,4 +1,4 @@ -namespace Expose.MyIT.Shared.Models.Methods; +namespace Expose.MyIT.Shared.Models.Stateless; public interface ISsaOrderRepository { diff --git a/Shared/Models/Stateless/IWeatherForecastController.cs b/Shared/Models/Stateless/IWeatherForecastController.cs new file mode 100644 index 0000000..5635c90 --- /dev/null +++ b/Shared/Models/Stateless/IWeatherForecastController.cs @@ -0,0 +1,9 @@ +namespace Expose.MyIT.Shared.Models.Stateless; + +public interface IWeatherForecastController +{ + + static string GetRouteName() => nameof(IWeatherForecastController)[1..^10]; + T Get(); + +} \ No newline at end of file diff --git a/Shared/Models/Stateless/Methods/IAppSettingsController.cs b/Shared/Models/Stateless/Methods/IAppSettingsController.cs deleted file mode 100644 index ac1c7f6..0000000 --- a/Shared/Models/Stateless/Methods/IAppSettingsController.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Expose.MyIT.Shared.Models.Stateless.Methods; - -public interface IAppSettingsController -{ - - static string GetRouteName() => nameof(IAppSettingsController)[1..^10]; - string[] GetAppSettings(); - -} \ No newline at end of file diff --git a/Shared/Models/Stateless/Methods/IClientSettingsController.cs b/Shared/Models/Stateless/Methods/IClientSettingsController.cs deleted file mode 100644 index 1d415b1..0000000 --- a/Shared/Models/Stateless/Methods/IClientSettingsController.cs +++ /dev/null @@ -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(); - -} \ No newline at end of file diff --git a/Shared/Models/Stateless/Methods/IServiceShopOrderController.cs b/Shared/Models/Stateless/Methods/IServiceShopOrderController.cs deleted file mode 100644 index c0d957d..0000000 --- a/Shared/Models/Stateless/Methods/IServiceShopOrderController.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Expose.MyIT.Shared.Models.Stateless.Methods; - -public interface IServiceShopOrderController -{ - - static string GetRouteName() => nameof(IServiceShopOrderController)[1..^10]; - Task GetAllServiceShopOrders(); - Task GetServiceShopOrders(string id); - -} \ No newline at end of file diff --git a/Shared/Models/Stateless/Methods/ISsaOrder.cs b/Shared/Models/Stateless/Methods/ISsaOrder.cs deleted file mode 100644 index b8b399e..0000000 --- a/Shared/Models/Stateless/Methods/ISsaOrder.cs +++ /dev/null @@ -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); - -} \ No newline at end of file diff --git a/Shared/Models/Stateless/Methods/ISsaOrderController.cs b/Shared/Models/Stateless/Methods/ISsaOrderController.cs deleted file mode 100644 index 681026d..0000000 --- a/Shared/Models/Stateless/Methods/ISsaOrderController.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Expose.MyIT.Shared.Models.Stateless.Methods; - -public interface ISsaOrderController -{ - - static string GetRouteName() => nameof(ISsaOrderController)[1..^10]; - Task GetAllSsaOrders(); - Task GetSsaOrders(string id); - -} \ No newline at end of file diff --git a/Shared/Models/Stateless/Methods/IWeatherForecastController.cs b/Shared/Models/Stateless/Methods/IWeatherForecastController.cs deleted file mode 100644 index 691dc76..0000000 --- a/Shared/Models/Stateless/Methods/IWeatherForecastController.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Expose.MyIT.Shared.Models.Stateless.Methods; - -public interface IWeatherForecastController -{ - - static string GetRouteName() => nameof(IWeatherForecastController)[1..^10]; - Task Get(); - -} \ No newline at end of file diff --git a/Shared/Models/Stateless/Methods/ServiceShopOrder.cs b/Shared/Models/Stateless/ServiceShopOrder.cs similarity index 82% rename from Shared/Models/Stateless/Methods/ServiceShopOrder.cs rename to Shared/Models/Stateless/ServiceShopOrder.cs index 979591d..e921d8c 100644 --- a/Shared/Models/Stateless/Methods/ServiceShopOrder.cs +++ b/Shared/Models/Stateless/ServiceShopOrder.cs @@ -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) diff --git a/Shared/Models/Stateless/Methods/SsaOrder.cs b/Shared/Models/Stateless/SsaOrder.cs similarity index 66% rename from Shared/Models/Stateless/Methods/SsaOrder.cs rename to Shared/Models/Stateless/SsaOrder.cs index 9967767..c85105d 100644 --- a/Shared/Models/Stateless/Methods/SsaOrder.cs +++ b/Shared/Models/Stateless/SsaOrder.cs @@ -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()) diff --git a/Shared/ViewModels/ServiceShopOrder.cs b/Shared/ViewModels/ServiceShopOrder.cs index 8472ce8..b0f15e7 100644 --- a/Shared/ViewModels/ServiceShopOrder.cs +++ b/Shared/ViewModels/ServiceShopOrder.cs @@ -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, diff --git a/Shared/ViewModels/SsaOrder.cs b/Shared/ViewModels/SsaOrder.cs index 495e694..f4166e2 100644 --- a/Shared/ViewModels/SsaOrder.cs +++ b/Shared/ViewModels/SsaOrder.cs @@ -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, diff --git a/Shared/ViewModels/WeatherForecast.cs b/Shared/ViewModels/WeatherForecast.cs index 6062fa5..9a8d1e1 100644 --- a/Shared/ViewModels/WeatherForecast.cs +++ b/Shared/ViewModels/WeatherForecast.cs @@ -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, diff --git a/Tests/UnitTestAppSettingsController.cs b/Tests/UnitTestAppSettingsController.cs index 5fc978f..cbbdc28 100644 --- a/Tests/UnitTestAppSettingsController.cs +++ b/Tests/UnitTestAppSettingsController.cs @@ -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? _WebApplicationFactory; +#pragma warning disable CS8618 + + private static ILogger _Logger; + private static string _ControllerName; + private static TestContext _TestContext; + private static WebApplicationFactory _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.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(); 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(); + List 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.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"); } diff --git a/Tests/UnitTestClientSettingsController.cs b/Tests/UnitTestClientSettingsController.cs index 4044604..dfd7b03 100644 --- a/Tests/UnitTestClientSettingsController.cs +++ b/Tests/UnitTestClientSettingsController.cs @@ -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? _WebApplicationFactory; +#pragma warning disable CS8618 + + private static ILogger _Logger; + private static string _ControllerName; + private static TestContext _TestContext; + private static WebApplicationFactory _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.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(); + List 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.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(); + 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.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"); } diff --git a/Tests/UnitTestServiceShopOrderController.cs b/Tests/UnitTestServiceShopOrderController.cs index 610e912..37aba96 100644 --- a/Tests/UnitTestServiceShopOrderController.cs +++ b/Tests/UnitTestServiceShopOrderController.cs @@ -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? _WebApplicationFactory; +#pragma warning disable CS8618 + + private static ILogger _Logger; + private static string _ControllerName; + private static TestContext _TestContext; + private static WebApplicationFactory _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.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(); - serviceShopOrders = await ServiceShopOrderRepository.GetAllServiceShopOrders(); + IServiceShopOrderRepository serviceShopOrderRepository = serviceProvider.GetRequiredService(); + 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.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"); } diff --git a/Tests/UnitTestSsaOrderController.cs b/Tests/UnitTestSsaOrderController.cs index dc242bc..3b30e21 100644 --- a/Tests/UnitTestSsaOrderController.cs +++ b/Tests/UnitTestSsaOrderController.cs @@ -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? _WebApplicationFactory; +#pragma warning disable CS8618 + + private static ILogger _Logger; + private static string _ControllerName; + private static TestContext _TestContext; + private static WebApplicationFactory _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.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(); - ssaOrders = await SsaOrderRepository.GetAllSsaOrders(); + ISsaOrderRepository ssaOrderRepository = serviceProvider.GetRequiredService(); + 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.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"); } diff --git a/Tests/UnitTestWeatherForecastController.cs b/Tests/UnitTestWeatherForecastController.cs index 4b97f50..200dc2b 100644 --- a/Tests/UnitTestWeatherForecastController.cs +++ b/Tests/UnitTestWeatherForecastController.cs @@ -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? _WebApplicationFactory; +#pragma warning disable CS8618 + + private static ILogger _Logger; + private static string _ControllerName; + private static TestContext _TestContext; + private static WebApplicationFactory _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.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}");