You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/site/docs/test-doubles/emulating-ijsruntime.md
-2Lines changed: 0 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,8 +84,6 @@ Since the .NET 5 release of Blazor, it has been possible to import JavaScript mo
84
84
The `SetupModule` methods return a module JSInterop, which can be configured to handle JavaScript calls using the `Setup` and `SetupVoid` methods. For example, to configure bUnit's JSInterop to handle an import of the JavaScript module `hello.js`, and a call to the function `world()` in that model, do the following:
The highlighted line shows how `AddTestAuthorization()` is used to add the test-specific implementation of Blazor's authentication and authorization types to the `Services` collection, which makes the authentication state available to other services as well as components used throughout the test that require it.
40
40
@@ -44,23 +44,23 @@ After calling `AddTestAuthorization()`, the default authentication state is unau
44
44
45
45
To set the state to authenticating and authorizing, do the following:
After calling `AddTestAuthorization()`, the returned <xref:Bunit.TestDoubles.TestAuthorizationContext> is used to set the authenticating and authorizing state through the <xref:Bunit.TestDoubles.TestAuthorizationContext.SetAuthorizing> method.
50
50
51
51
### Authenticated and unauthorized state
52
52
53
53
To set the state to authenticated and unauthorized, do the following:
After calling `AddTestAuthorization()`, the returned <xref:Bunit.TestDoubles.TestAuthorizationContext> is used to set the authenticated and unauthorized state through the <xref:Bunit.TestDoubles.TestAuthorizationContext.SetAuthorized(System.String,Bunit.TestDoubles.AuthorizationState)> method.
58
58
59
59
### Authenticated and authorized state
60
60
61
61
To set the state to authenticated and authorized, do the following:
After calling `AddTestAuthorization()`, the returned <xref:Bunit.TestDoubles.TestAuthorizationContext> is used to set the authenticated and authorized state through the <xref:Bunit.TestDoubles.TestAuthorizationContext.SetAuthorized(System.String,Bunit.TestDoubles.AuthorizationState)> method.
66
66
@@ -78,17 +78,17 @@ The examples will use the `<UserRights>` component listed below. It uses the `<A
78
78
79
79
To specify one or more roles for the authenticated and authorized user, do the following:
The highlighted line shows how the <xref:Bunit.TestDoubles.TestAuthorizationContext.SetRoles(System.String[])> method is used to specify a single role. To specify multiple roles, do the following:
The highlighted line shows how the <xref:Bunit.TestDoubles.TestAuthorizationContext.SetPolicies(System.String[])> method is used to specify one policy. To specify multiple policies, do the following:
94
94
@@ -98,22 +98,22 @@ The highlighted line shows how the <xref:Bunit.TestDoubles.TestAuthorizationCont
98
98
99
99
To specify one or more claims for the authenticated and authorized user, do the following:
The highlighted line shows how the <xref:Bunit.TestDoubles.TestAuthorizationContext.SetClaims(System.Security.Claims.Claim[])> method is used to pass two instances of the `Claim` type.
104
104
105
105
### Example of passing both roles, claims, and policies
106
106
107
107
Let’s try to combine all the possibilities shown in the previous examples into one. The following example specifies two roles, one claim, and one policy for the authenticated and authorized user:
With this example done, all auth-related test scenarios should be covered. If you find that one is missing, please let us know in the [bUnit discussion forum](https://github.com/egil/bUnit/discussions).
112
112
113
113
### Authentication types
114
114
115
115
To specify a authentication type for the authenticated and authorized user, do the following:
The highlighted line shows how the <xref:Bunit.TestDoubles.TestAuthorizationContext.SetAuthenticationType(System.String)> method is used to change the `Identity.AuthenticationType` of the user.
Copy file name to clipboardExpand all lines: docs/site/docs/verification/semantic-html-comparison.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -143,4 +143,4 @@ Let’s look at a few examples where we use the semantic comparison options list
143
143
144
144
In this case, we want to verify that the markup is rendered correctly, using something such as RegEx to verify the `id` attribute (it might be generated) and ignoring the `<small>` element. In tests we can do this like so with the `MarkupMatches()` method:
You can perform standard string assertions against the markup string, like checking whether it contains a value or is empty.
36
36
@@ -70,13 +70,13 @@ In the following examples, the `<Heading>` component listed below will be used a
70
70
71
71
To use the `MarkupMatches()` method to perform a semantic comparison of the output of the `<Heading>` component through its <xref:Bunit.IRenderedFragment>, do the following:
The highlighted line shows the call to the `MarkupMatches()` method. This test passes even though the insignificant whitespace is not exactly the same between the expected HTML string and the raw markup produced by the `<Heading>` component. It even works when the CSS class list is not in the same order on the `<small>` element.
76
76
77
77
The `MarkupMatches()` method is also available on `INode` and `INodeList` types, for example:
Here we use the `Find(string cssSelector)` method to find the `<small>` element, and only verify it and its content and attributes.
82
82
@@ -85,7 +85,7 @@ Here we use the `Find(string cssSelector)` method to find the `<small>` element,
85
85
86
86
Text content can also be verified with the `MarkupMatches()` method, e.g. the text inside the `<small>` element. It has the advantage over regular string comparison in that it removes insignificant whitespace in the text automatically - even between words - where a normal string `Trim()` method isn't enough. For example:
The semantic HTML comparer can be customized to make a test case even more stable and easier to maintain. For example, it is possible to ignore an element or attribute during comparison, or provide a regular expression to the comparer when comparing a specific element or attribute to make the comparer work with generated data.
91
91
@@ -112,11 +112,11 @@ Let's see some examples of using the [`Find(string cssSelector)`](xref:Bunit.Ren
112
112
113
113
To find the `<caption>` element and the first `<td>` elements in each row, do the following:
0 commit comments