NE.Standard.UI.Testing
2.9.0
See the version list below for details.
dotnet add package NE.Standard.UI.Testing --version 2.9.0
NuGet\Install-Package NE.Standard.UI.Testing -Version 2.9.0
<PackageReference Include="NE.Standard.UI.Testing" Version="2.9.0" />
<PackageVersion Include="NE.Standard.UI.Testing" Version="2.9.0" />
<PackageReference Include="NE.Standard.UI.Testing" />
paket add NE.Standard.UI.Testing --version 2.9.0
#r "nuget: NE.Standard.UI.Testing, 2.9.0"
#:package NE.Standard.UI.Testing@2.9.0
#addin nuget:?package=NE.Standard.UI.Testing&version=2.9.0
#tool nuget:?package=NE.Standard.UI.Testing&version=2.9.0
NE.Standard.UI.Testing
Tests for an NE.Standard UI application without a browser. The whole UI contract of a server-driven page lives on the server — the view's bindings, its rules, its filters, authorization — so a test can check it there: boot the application's own startup, open a page through the host's real path, act on its components as a reader does and read what the page received.
await using UITestApp app = UITestApp.Create<AppStartup>(services => services.AddSingleton<IClock>(fake));
UITestPage page = await app.OpenAsync("/sign-up", session => session.SignIn("robin", roles: ["admin"]));
UITestComponent email = page.ComponentBoundTo(nameof(SignUpController.Email));
await email.SetValueAsync("not-an-email");
UITestCommandResult submit = await page.ComponentNamed("Create account").ClickAsync();
Assert.Equal("That does not look like an email address.", email.ValidationMessage);
Assert.False(submit.Sent);
Assert.False(page.Controller<SignUpController>().Submitted);
No test framework and no assertion library come with it: a page answers with plain values, and a misuse — a component
that is not there, a press on a button a reader could not press — throws InvalidOperationException. xUnit, NUnit and
MSTest read it alike.
Install
dotnet add package NE.Standard.UI.Testing
It brings its namespace, NE.Standard.UI.Testing, as a global using; a project that sets NEStandardUIImplicitUsings
to false writes its own. It needs no platform: the web host is not installed, and the application's own project is
all a test project references beside it.
The application
UITestApp.Create<TStartup>() builds the application from its UIStartupBase exactly as its host would — compiling
each route's view lazily as it is opened unless the startup configures eager compilation — with no platform under it:
the test is the platform. configureServices runs after the startup's own registrations, so a fake registered there
replaces the real service (UITestApp also registers a default /_ne/content IUIContentAddressResolver unless
overridden); configureApplication adds to the application as the startup does.
The scheduler is parked. A command's changes reach the page that asked before the command returns, and the runtime keeps
what it owes the rest — a posted action's writes, OnAttachedAsync's — for the flush, which only page.FlushAsync()
runs: what a command answered and what waits for the flush are told apart without timing. An effect pushed outside a command
(SendEffectsAsync) goes out at once, behind the values written before it.
A page
app.OpenAsync(address, session) resolves the address through the view filters and the route's authorization — a
refusal lands on the sign-in or the forbidden page, as in a browser, and page.Route says where — then attaches a
runtime and starts the page from the snapshot a connecting page is sent. An address may carry a query
("/catalogue?role=db"), read as the host reads one (+ a space, a repeated key a list); page.Address is what the
address bar shows, after every address effect the page received.
The session is the application's own: session.SignIn(userId, roles, permissions), InLanguage("ru") and
InTimeZone(...) are stored in its session store before the page opens and presented as a cookie would present them,
so the resolver, authorization and filters read them as they read a real session. WithNotificationPermission(...) is
what its pages' browser reports, and page.Session reads the session's live state after sign-in, sign-out, language,
time-zone or permission changes. page.OpenAsync(address) opens another page in the same session; page.CloseAsync()
closes one as a closed tab does and returns once OnDetachedAsync ran (the runtime stays for its retention).
A page whose view binds what names nothing — a property the controller lacks, a step the server cannot read — is refused
when it opens, naming each binding: the server only logs it, and the page would show a blank control. Advice the compile
gives (an argument the command has no parameter for, a Root binding a row's item shadows) is logged, not refused.
page.CompileWarnings lists both, each with its Kind; app.AllowsCompileWarnings = true opens such a page anyway.
Finding a component
page.Component("chat-conversation")— by the id the view gave it.page.ComponentBoundTo(nameof(SignUpController.Email))orpage.ComponentBoundTo<SignUpController>(c => c.Email)— by the controller path its value, its items or another property is bound to (and on aUITestComponent, within its subtree).page.ComponentNamed("Create account")— by what a reader knows it by: its title, accessible name or tooltip, as written or in the page's language.
A list's visible rows (after any plain-host FilterBy, SortBy and Query rules, or a windowed host's realized window)
are component.Rows and component.Row(key); a row's components are found the same way inside it (row.Component(id),
row.ComponentBoundTo("Text"), row.ComponentBoundTo<TItem>(x => x.Text)), and row.ContextMenu and
component.ContextMenu are what a right click shows. A split button's entries are the rows of component.Menu; a menu
row's sub-entries are row.Rows and row.Row(key), and menu.Row(key) reaches a unique sub-entry too.
Reading it
What a component shows is read off the change sets the page received, applied the way the client applies them:
Value, Title, Get(property), Text(property), IsVisible and IsEnabled (resolved at page.ResponsiveTier, and
an ancestor collapsed, disabled or loading counts, as does a dialog not open), and ValidationMessage — the strongest of
the field's failing rules, a value past its bounds, a message routed through ValidationInto, the controller's bound
message and the server's refusal, as the page shows it. A row's binding is read off the row's item; a reset and its
inserts keep what the page held under the rows they resend unchanged.
The client interactions a view declares run too: a part shown while a switch is on appears when the switch is written.
page.Effects and page.EffectsOf<ShowNotificationEffect>() are every effect the page received (page.ClearEffects()
clears the recorded list), run as the browser runs them: dialogs open and close with theirs, the dialog service's too
(page.IsDialogOpen(key)); the viewer's own close (CloseDialogEffect with RaisesClose) lets the edit of a form
under the dialog's key go and raises its OnClose; a show, hide or collapse writes its target's visibility; an address
effect rewrites page.Address; a discard lets a form's held edits go; a language or a theme the page switches to
reaches its session and controller. An effect naming a dialog the view does not declare throws, as the server drops it.
page.Downloads holds the files sent to it (page.ClearDownloads() clears them). page.Controller<T>() is the
controller, for what the screen does not show.
Acting on it
Each act goes through the host's own entry points, the ones the web hub calls — the gates, the bounds, the command filters and authorization all run:
SetValueAsync(value)types and leaves a field: its change rules, the interactions reading it, the write to the server (or, underOnSubmit, held for its form — row fields included — while a push waits behind the edit until aDiscardFormEffect), its change command, its blur rules. A number or a date past itsMin/Maxstays in the field, refused in words, and is not sent; a value no reader could give — a slider past its bounds, a negative where none is taken — throws. It answers aUITestCommandResult: refused for a value the page or the server refused, else what the change command did.ClickAsync()presses: a button submitting a form is refused while a field of the form is in error, as the browser refuses it, and the result says so (Sentfalse); a surface or a file tile whoseClickableis false throws, as the browser lets its click go by.RenameAsync(title)on aUITestComponentorUITestRowwrites the new caption throughRenamedTitleand runs anyOnRename/OnItemRenamecommand, respectingRenamable,CanRenameand one-shotRenameItemEffectgrants.DispatchAsync(eventName, eventKeys)raises any event a component declares; one that submits its field's form (a code field's save,IFormSubmittingComponent) sends the form's held values first.row.ClickAsync()androw.ChooseAsync()press or choose a row; an entry with an effect of its own (OnItemClick(key, effect)) runs it on the page and sends nothing.component.RequestItemWindowAsync(anchor, count, mode)loads a window of rows on a windowedUIItemSourceBasehost.page.SetResponsiveTier(tier)andpage.SetViewportWidth(widthPixels)setpage.ResponsiveTier(Xxlby default).page.GoBackAsync()andpage.GoForwardAsync()step through in-place address history (CanGoBack,CanGoForward).page.Store(UIClientStore) reads, writes and removes component preferences keyed by authored id and slot.page.DismissDialogAsync(key)closes a dialog as Escape or a press beside it does: its form's edit goes and itsOnCloseruns; one that takes neither throws.page.PressNotificationActionAsync(toast)presses a notification's action — its Undo.page.HideAsync()/ShowAsync()take the page off screen and back (HasVisibleViewers), andReportNotificationPermissionAsync(...)reports the browser's answer to the prompt.
Every act answers with a UITestCommandResult: whether a command reached the server, whether it succeeded, its error,
and the effects the page received while it ran.
What it does not model
Layout and styling; popups other than dialogs (a context menu and a flyout stand open); the trimming and debouncing a field does in the browser; what the web hub adds of its own — its call budget, a large value staged beside it. A row's item is the server's own object, so a property the server changed shows there before the flush sends it. A page's DOM, focus and keyboard are the browser's — for those, drive a browser.
Licence
The framework's: the Prosperity Public License 3.0.0 — free for noncommercial use, with a thirty-day trial for commercial use. See LICENSE.md.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- NE.Standard.UI (>= 2.9.0)
- NE.Standard.UI.Client (>= 2.9.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.