Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-46: Use WebApplicationFactory directly instead of running the tested app with the dotnet CLI #186

Merged
merged 67 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
42895f7
Basics of WebApplicationFactory usage
Piedone Oct 21, 2021
ff4045e
Merge branch 'dev' of https://github.com/Lombiq/UI-Testing-Toolbox in…
dministro Jul 13, 2022
771a74d
Adding minimal WebDriverFactory implementation
dministro Jul 18, 2022
cc9064b
Injecting FakeStore
dministro Jul 18, 2022
5395805
Merge branch 'dev' of https://github.com/Lombiq/UI-Testing-Toolbox in…
dministro Jul 18, 2022
3aa72e2
Clearing SQLite connection pool
dministro Jul 20, 2022
969e178
Fixing ObjectDisposedException in case of restarting Orchard application
dministro Jul 24, 2022
e78d5d9
Merge branch 'dev' of https://github.com/Lombiq/UI-Testing-Toolbox in…
dministro Jul 24, 2022
b163e42
Fixing CA1063: Provide an overridable implementation of Dispose(bool)
dministro Jul 24, 2022
de828ed
Fixing the cause of failing tests:
dministro Jul 25, 2022
b1f0054
Maybe fixing failing test:
dministro Jul 25, 2022
1b182eb
Adding Migration.md
dministro Jul 29, 2022
fd35bb0
Merge branch 'dev' of https://github.com/Lombiq/UI-Testing-Toolbox in…
dministro Jul 29, 2022
bc5026f
Merge branch 'dev' of https://github.com/Lombiq/UI-Testing-Toolbox in…
dministro Aug 7, 2022
cb826ba
Merge branch 'dev' into issue/OSOE-46
BenedekFarkas Aug 24, 2022
39fac97
Merge branch 'issue/OSOE-46' of https://github.com/Lombiq/UI-Testing-…
dministro Aug 28, 2022
055071d
Merge branch 'dev' of https://github.com/Lombiq/UI-Testing-Toolbox in…
dministro Aug 28, 2022
cdbb3c1
Fixing after merge
dministro Aug 28, 2022
eada331
Fixing command line arg
dministro Aug 28, 2022
4f6061d
Merge branch 'dev' of https://github.com/Lombiq/UI-Testing-Toolbox in…
dministro Aug 30, 2022
ef656a8
Renaming AddValue to AddWithValue
dministro Sep 2, 2022
cffa7c6
Disabling tests
dministro Sep 3, 2022
0cbaea6
Adding logger configuration
dministro Sep 6, 2022
36ceb18
Enabling Lombiq.Tests.UI.Samples tests
dministro Sep 6, 2022
6d5f683
Fixing MonkeyTests
dministro Sep 6, 2022
fc57cba
Fixing MonkeyTests again
dministro Sep 6, 2022
579c8e1
Coding style
dministro Sep 8, 2022
8c6fdc9
Removing OrchardCoreUITestBase.AppAssemblyPath
dministro Sep 8, 2022
d90c1d9
Using OC services directly instead of Shortcut Controllers where poss…
dministro Sep 9, 2022
9f6b50d
Merge branch 'dev' of https://github.com/Lombiq/UI-Testing-Toolbox in…
dministro Sep 9, 2022
eb78527
Using OC services directly instead of Shortcut Controllers where poss…
dministro Sep 9, 2022
7a161fd
Removing unused variable
dministro Sep 9, 2022
475a224
Injecting fake HttpContext before calling OC services directly
dministro Sep 9, 2022
e7492cd
Merge branch 'dev' of https://github.com/Lombiq/UI-Testing-Toolbox in…
dministro Sep 9, 2022
b80d70c
Using OC services directly instead of Shortcut Controllers where poss…
dministro Sep 9, 2022
447a7ff
Fixing docs
dministro Sep 9, 2022
8ed64e1
Using Lombiq.Tests.UI.Samples test classes from Lombiq.OSOCE.Tests.UI…
dministro Sep 11, 2022
b6b4400
Removing test sdk from Lombiq.Tests.UI.Samples.csproj
dministro Sep 11, 2022
efef0d7
Adding Lombiq.Tests as a NuGet package
dministro Sep 11, 2022
a8e5fd1
Revert "Removing test sdk from Lombiq.Tests.UI.Samples.csproj"
dministro Sep 12, 2022
3f4e254
Moving OrchardCoreBuilderExtensions to Lombiq.Tests.UI
dministro Sep 14, 2022
ec38239
Fixing docs
dministro Sep 14, 2022
2f8adc0
Fixing docs
dministro Sep 14, 2022
53fcbab
Removing possible dead-lock
dministro Sep 15, 2022
6c4a662
Fixing razor runtime compilation related issue
dministro Sep 15, 2022
2120dda
Just for a test
dministro Sep 15, 2022
8956d2d
Fixing possible dead lock
dministro Sep 19, 2022
48834f8
Removing unnecessary workaround for razor runtime compilation
dministro Sep 19, 2022
37741b5
Merge branch 'dev' of https://github.com/Lombiq/UI-Testing-Toolbox in…
dministro Sep 19, 2022
88b72a1
Merge branch 'dev' of https://github.com/Lombiq/UI-Testing-Toolbox in…
dministro Sep 20, 2022
649f996
Updating docs
dministro Sep 20, 2022
78886c3
Possible fix of real deadlock
dministro Sep 21, 2022
91aa9f3
Adding IServiceProviderInstance to fake HttpContext
dministro Sep 21, 2022
b2571ac
Trying to avoid adding razor runtime view compilation
dministro Sep 26, 2022
25a3aa7
Updating docs
dministro Sep 26, 2022
0e7fdce
Update Lombiq.Tests.UI/Docs/Migration.md
dministro Sep 29, 2022
f8ed3d8
Update Lombiq.Tests.UI/Docs/Migration.md
dministro Sep 29, 2022
7bff85a
Update Lombiq.Tests.UI/Docs/Migration.md
dministro Sep 29, 2022
af768a3
Update Lombiq.Tests.UI/Docs/Migration.md
dministro Sep 29, 2022
5bda8a0
Update Lombiq.Tests.UI/Docs/Migration.md
dministro Sep 29, 2022
d154b4c
Update Lombiq.Tests.UI/Docs/Migration.md
dministro Sep 29, 2022
0962edd
Update Lombiq.Tests.UI/Docs/TestableOrchardCoreApps.md
dministro Sep 29, 2022
f7b4816
Merge branch 'dev' of https://github.com/Lombiq/UI-Testing-Toolbox in…
dministro Sep 29, 2022
33e252f
Updating docs
dministro Sep 29, 2022
a87ade6
Updating Lombiq.Tests Nuget package version
dministro Sep 29, 2022
62fb81e
Update Lombiq.Tests.UI/Models/InstanceCommandLineArgs.cs
sarahelsaig Oct 14, 2022
dc810d2
Update Lombiq.Tests.UI/Services/OrchardCoreHosting/OrchardApplication…
sarahelsaig Oct 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lombiq.Tests.UI.Samples/Lombiq.Tests.UI.Samples.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand Down Expand Up @@ -43,6 +43,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Lombiq.OSOCE.Web\Lombiq.OSOCE.Web.csproj" />
<ProjectReference Include="..\Lombiq.Tests.UI\Lombiq.Tests.UI.csproj" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Lombiq.Tests.UI.Samples/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ For general details about and on using the Toolbox see the [root Readme](../Read
## Tutorial

1. Be sure to read the [root Readme](../Readme.md) first to understand how the UI Testing Toolbox works and how you can use it with an Orchard Core app.
2. The web app under test also needs a bit of configuration. For an example of this, check out [the `Program` class of Lombiq's Open-Source Orchard Core Extensions](https://github.com/Lombiq/Open-Source-Orchard-Core-Extensions/blob/dev/src/Lombiq.OSOCE.Web/Program.cs). This project assumes it's running in that solution.
2. The web app under test also needs a bit of configuration. For an example of this, check out [the `Program` class of Lombiq's Open-Source Orchard Core Extensions](https://github.com/Lombiq/Open-Source-Orchard-Core-Extensions/blob/dev/src/Lombiq.OSOCE.Web/Program.cs). This project assumes it's running in that solution, so it depends on `Lombiq.OSOCE.Web` to be present at the correct path to be able to build it.
3. Note that the project includes an _xunit.runner.json_ file. This is [xUnit's configuration file](https://xunit.net/docs/configuration-files). You don't necessarily need to include one if you're OK with [the default one](https://github.com/Lombiq/UI-Testing-Toolbox/blob/dev/Lombiq.Tests.UI/xunit.runner.json).
4. Now that we have the basics out of the way start the tutorial in the [_GlobalSuppressions.cs_](GlobalSuppressions.cs) file.

Expand Down
5 changes: 2 additions & 3 deletions Lombiq.Tests.UI.Samples/Tests/ErrorHandlingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Lombiq.Tests.UI.Pages;
using Lombiq.Tests.UI.Samples.Helpers;
using Lombiq.Tests.UI.Services;
using Microsoft.SqlServer.Management.Dmf;
using Shouldly;
using System;
using System.Linq;
Expand Down Expand Up @@ -108,7 +107,7 @@ public Task BrowserLogsShouldPersist(Browser browser) =>
public Task ErrorDuringSetupShouldHaltTest(Browser browser) =>
Should.ThrowAsync<PageChangeAssertionException>(() =>
ExecuteTestAfterSetupAsync(
_ => throw new InvalidOperandException("This point shouldn't be reachable because setup fails."),
_ => throw new InvalidOperationException("This point shouldn't be reachable because setup fails."),
browser,
configuration =>
{
Expand All @@ -127,7 +126,7 @@ await context.GoToSetupPageAndSetupOrchardCoreAsync(
ConnectionString = "An invalid connection string which causes an error during setup.",
});

throw new InvalidOperandException(
throw new InvalidOperationException(
"This point shouldn't be reachable if the logs are properly kept.");
};
}));
Expand Down
14 changes: 13 additions & 1 deletion Lombiq.Tests.UI.Samples/Tests/MonkeyTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Atata;
using Lombiq.Tests.UI.Attributes;
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.MonkeyTesting;
Expand All @@ -10,6 +11,7 @@
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using LogLevel = OpenQA.Selenium.LogLevel;

namespace Lombiq.Tests.UI.Samples.Tests;

Expand Down Expand Up @@ -87,7 +89,17 @@ public Task TestAdminBackgroundTasksAsMonkeyRecursivelyShouldWorkWithAdminUser(B
await context.SignInDirectlyAndGoToRelativeUrlAsync("/Admin/BackgroundTasks");
await context.TestCurrentPageAsMonkeyRecursivelyAsync(monkeyTestingOptions);
},
browser);
browser,
configuration => configuration.AssertBrowserLog = (logs) => logs
.Where(message =>
!message
.Message
.Contains("An invalid form control with name='LockTimeout' is not focusable.")
&& !message
.Message
.Contains("An invalid form control with name='LockExpiration' is not focusable.")
&& message.Level != LogLevel.Info)
.ShouldBeEmpty());

// Monkey testing has its own configuration too. Check out the docs of the options too.
private static MonkeyTestingOptions CreateMonkeyTestingOptions() =>
Expand Down
11 changes: 2 additions & 9 deletions Lombiq.Tests.UI.Samples/UITestBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Lombiq.Tests.UI.Constants;
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Helpers;
using Lombiq.Tests.UI.Samples.Helpers;
using Lombiq.Tests.UI.Services;
using Shouldly;
Expand All @@ -12,13 +11,8 @@ namespace Lombiq.Tests.UI.Samples;

// This will be the base class for our UI test classes. Here we'll set up some common configuration. Inheriting test
// classes is not mandatory but the approach is simple and effective.
public class UITestBase : OrchardCoreUITestBase
public class UITestBase : OrchardCoreUITestBase<Program>
{
// We somehow need to tell the UI Testing Toolbox where the assemblies of the app under test is (since it'll run the
// app from the command line). We use a helper for that.
protected override string AppAssemblyPath => WebAppConfigHelper
.GetAbsoluteApplicationAssemblyPath("Lombiq.OSOCE.Web", "net6.0");

protected UITestBase(ITestOutputHelper testOutputHelper)
: base(testOutputHelper)
{
Expand Down Expand Up @@ -76,8 +70,7 @@ protected override Task ExecuteTestAsync(
(_, argumentsBuilder) =>
{
argumentsBuilder
.Add("--OrchardCore:OrchardCore_Admin:AdminUrlPrefix")
.Add("Admin");
.AddWithValue("OrchardCore:OrchardCore_Admin:AdminUrlPrefix", "Admin");

return Task.CompletedTask;
};
Expand Down
51 changes: 1 addition & 50 deletions Lombiq.Tests.UI.Shortcuts/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
using Lombiq.HelpfulLibraries.AspNetCore.Mvc;
using Lombiq.Tests.UI.Shortcuts.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using OrchardCore.Entities;
using OrchardCore.Settings;
using OrchardCore.Users;
using OrchardCore.Users.Models;
using OrchardCore.Users.Services;
using System.Threading.Tasks;

namespace Lombiq.Tests.UI.Shortcuts.Controllers;
Expand All @@ -17,19 +12,11 @@ public class AccountController : Controller
{
private readonly UserManager<IUser> _userManager;
private readonly SignInManager<IUser> _userSignInManager;
private readonly ISiteService _siteService;
private readonly IUserService _userService;

public AccountController(
UserManager<IUser> userManager,
SignInManager<IUser> userSignInManager,
ISiteService siteService,
IUserService userService)
public AccountController(UserManager<IUser> userManager, SignInManager<IUser> userSignInManager)
{
_userManager = userManager;
_userSignInManager = userSignInManager;
_siteService = siteService;
_userService = userService;
}

[AllowAnonymous]
Expand All @@ -50,40 +37,4 @@ public async Task<IActionResult> SignOutDirectly()

return Ok();
}

[AllowAnonymous]
public async Task<ActionResult> SetUserRegistrationType(UserRegistrationType type)
{
var settings = await _siteService.LoadSiteSettingsAsync();

settings.Alter<RegistrationSettings>(
nameof(RegistrationSettings),
registrationSettings => registrationSettings.UsersCanRegister = type);

await _siteService.UpdateSiteSettingsAsync(settings);

return Ok();
}

[AllowAnonymous]
public async Task<ActionResult> CreateUser([FromJsonQueryString] CreateUserRequest userData)
{
var user = await _userService.CreateUserAsync(
new User
{
UserName = userData.UserName,
Email = userData.Email,
EmailConfirmed = true,
IsEnabled = true,
},
userData.Password,
(key, error) => ModelState.AddModelError(key, error));

if (user == null)
{
return BadRequest(ModelState);
}

return Ok("Success");
}
}
55 changes: 0 additions & 55 deletions Lombiq.Tests.UI.Shortcuts/Controllers/RecipeController.cs

This file was deleted.

79 changes: 0 additions & 79 deletions Lombiq.Tests.UI.Shortcuts/Controllers/SecurityController.cs

This file was deleted.

50 changes: 0 additions & 50 deletions Lombiq.Tests.UI.Shortcuts/Controllers/ShellFeaturesController.cs

This file was deleted.

Loading