-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#115 test: added mock web project to test os agnostic stuff
+ This makes possible to completely mock the output of linux commands for e2e tests
- Loading branch information
1 parent
65797d1
commit 509b2a8
Showing
12 changed files
with
224 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@using Linguard.Web.Shared | ||
|
||
<Router AppAssembly="@typeof(App).Assembly"> | ||
<Found Context="routeData"> | ||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/> | ||
<FocusOnNavigate RouteData="@routeData" Selector="h1"/> | ||
</Found> | ||
<NotFound> | ||
<PageTitle>Not found</PageTitle> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p role="alert">Oops, it looks like there's nothing here.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Linguard.Core.OS; | ||
using Moq; | ||
|
||
namespace WebMock; | ||
|
||
public class CommandRunnerMock : Mock<ICommandRunner> { | ||
public CommandRunnerMock() { | ||
Setup(o => o.Run(It.IsAny<string>())) | ||
.Returns(new CommandResult(string.Empty, string.Empty, true)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Linguard.Core.Managers; | ||
using Linguard.Web.Services; | ||
using Moq; | ||
|
||
namespace WebMock; | ||
|
||
public class LifetimeServiceMock : Mock<ILifetimeService> { | ||
public LifetimeServiceMock(IConfigurationManager manager) { | ||
Setup(o => o.OnAppStarted()).Callback(manager.LoadDefaults); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using Core.Test.Mocks; | ||
using FluentValidation; | ||
using Linguard.Core.Models.Wireguard; | ||
using Linguard.Core.Models.Wireguard.Validators; | ||
using Linguard.Core.Services; | ||
using Linguard.Core.Utils; | ||
using Linguard.Log; | ||
using Linguard.Web.Services; | ||
using QRCoder; | ||
using Radzen; | ||
using WebMock; | ||
using ILogger = Linguard.Log.ILogger; | ||
|
||
var root = Path.Combine(new DirectoryInfo(Directory.GetCurrentDirectory()).Parent!.FullName, "Web", | ||
"wwwroot"); | ||
var builder = WebApplication.CreateBuilder(new WebApplicationOptions { | ||
WebRootPath = root, | ||
Args = args, | ||
ApplicationName = AssemblyInfo.Product | ||
}); | ||
|
||
//var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
builder.Services.AddRazorPages(); | ||
builder.Services.AddServerSideBlazor(); | ||
|
||
var manager = new DefaultConfigurationManager().Object; | ||
builder.Services.AddSingleton(manager); | ||
builder.Services.AddTransient<ILogger, NLogLogger>(); | ||
builder.Services.AddSingleton(new CommandRunnerMock().Object); | ||
builder.Services.AddTransient<IWireguardService, WireguardService>(); | ||
builder.Services.AddTransient<IInterfaceGenerator, DefaultInterfaceGenerator>(); | ||
builder.Services.AddTransient<IClientGenerator, DefaultClientGenerator>(); | ||
builder.Services.AddTransient<AbstractValidator<Interface>, InterfaceValidator>(); | ||
builder.Services.AddTransient<AbstractValidator<Client>, ClientValidator>(); | ||
|
||
builder.Services.AddTransient<IWebService, WebService>(); | ||
builder.Services.AddTransient<QRCodeGenerator, QRCodeGenerator>(); | ||
builder.Services.AddSingleton(new LifetimeServiceMock(manager).Object); | ||
|
||
builder.Services.AddScoped<DialogService>(); | ||
builder.Services.AddScoped<NotificationService>(); | ||
builder.Services.AddScoped<TooltipService>(); | ||
builder.Services.AddScoped<ContextMenuService>(); | ||
|
||
var app = builder.Build(); | ||
|
||
app.Lifetime.ApplicationStarted.Register(() => { | ||
app.Services.GetService<ILifetimeService>()?.OnAppStarted(); | ||
}); | ||
|
||
app.Lifetime.ApplicationStopping.Register(() => { | ||
app.Services.GetService<ILifetimeService>()?.OnAppStopping(); | ||
}); | ||
|
||
app.Lifetime.ApplicationStopped.Register(() => { | ||
app.Services.GetService<ILifetimeService>()?.OnAppStopped(); | ||
}); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) { | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
else { | ||
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(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseStaticFiles(); | ||
|
||
app.UseRouting(); | ||
app.MapBlazorHub(); | ||
app.MapFallbackToPage("/_Host"); | ||
|
||
app.Run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:37000", | ||
"sslPort": 44355 | ||
} | ||
}, | ||
"profiles": { | ||
"WebMock": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "https://localhost:7167;http://localhost:5167", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<_ContentIncludedByDefault Remove="Pages\Error.cshtml" /> | ||
<_ContentIncludedByDefault Remove="Pages\_Host.cshtml" /> | ||
<_ContentIncludedByDefault Remove="Pages\_Layout.cshtml" /> | ||
<_ContentIncludedByDefault Remove="Pages\Counter.razor" /> | ||
<_ContentIncludedByDefault Remove="Pages\FetchData.razor" /> | ||
<_ContentIncludedByDefault Remove="Pages\Index.razor" /> | ||
<_ContentIncludedByDefault Remove="Shared\MainLayout.razor" /> | ||
<_ContentIncludedByDefault Remove="Shared\NavMenu.razor" /> | ||
<_ContentIncludedByDefault Remove="Shared\SurveyPrompt.razor" /> | ||
<_ContentIncludedByDefault Remove="wwwroot\css\bootstrap\bootstrap.min.css" /> | ||
<_ContentIncludedByDefault Remove="wwwroot\css\bootstrap\bootstrap.min.css.map" /> | ||
<_ContentIncludedByDefault Remove="wwwroot\css\open-iconic\FONT-LICENSE" /> | ||
<_ContentIncludedByDefault Remove="wwwroot\css\open-iconic\font\css\open-iconic-bootstrap.min.css" /> | ||
<_ContentIncludedByDefault Remove="wwwroot\css\open-iconic\font\fonts\open-iconic.eot" /> | ||
<_ContentIncludedByDefault Remove="wwwroot\css\open-iconic\font\fonts\open-iconic.otf" /> | ||
<_ContentIncludedByDefault Remove="wwwroot\css\open-iconic\font\fonts\open-iconic.svg" /> | ||
<_ContentIncludedByDefault Remove="wwwroot\css\open-iconic\font\fonts\open-iconic.ttf" /> | ||
<_ContentIncludedByDefault Remove="wwwroot\css\open-iconic\font\fonts\open-iconic.woff" /> | ||
<_ContentIncludedByDefault Remove="wwwroot\css\open-iconic\ICON-LICENSE" /> | ||
<_ContentIncludedByDefault Remove="wwwroot\css\open-iconic\README.md" /> | ||
<_ContentIncludedByDefault Remove="wwwroot\css\site.css" /> | ||
<_ContentIncludedByDefault Remove="wwwroot\favicon.ico" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Core.Test\Core.Test.csproj" /> | ||
<ProjectReference Include="..\Web\Web.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Moq" Version="4.16.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@using System.Net.Http | ||
@using Microsoft.AspNetCore.Authorization | ||
@using Microsoft.AspNetCore.Components.Authorization | ||
@using Microsoft.AspNetCore.Components.Forms | ||
@using Microsoft.AspNetCore.Components.Routing | ||
@using Microsoft.AspNetCore.Components.Web | ||
@using Microsoft.AspNetCore.Components.Web.Virtualization | ||
@using Microsoft.JSInterop | ||
@using Linguard.Web | ||
@using Linguard.Web.Shared | ||
@using Radzen | ||
@using Radzen.Blazor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"DetailedErrors": true, | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |