Skip to content

Commit c5402c4

Browse files
committed
refactor: Rename Fake to Bunit
1 parent 8a2396e commit c5402c4

37 files changed

+250
-246
lines changed

MIGRATION.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ The `bunit.core` and `bunit.web` packages have been merged into a single `bunit`
3333

3434
### `WebTestRender` merged into `TestRender`
3535
The `WebTestRender` class has been merged into the `TestRender` class. If you used `WebTestRender`, you should replace it with `TestRender`.
36+
37+
## Renamed `Fake` to `Bunit` in many test doubles
38+
The `Fake` prefix has been replaced with `Bunit` in many test doubles. For example, `FakeNavigationManager` is now `BunitNavigationManager`. If you reference any of these types explicitly, you need to update your code.
39+
40+
### Renamed `AddTestAuthorization` to `AddAuthorization`
41+
The `AddTestAuthorization` method on `TestContext` has been renamed to `AddAuthorization`. If you used `AddTestAuthorization`, you should replace it with `AddAuthorization`.

docs/samples/tests/xunit/InjectAuthServiceTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class InjectAuthServiceTest : TestContext
1010
public void Test001()
1111
{
1212
// arrange
13-
var authContext = this.AddTestAuthorization();
13+
var authContext = this.AddAuthorization();
1414
authContext.SetAuthorized("TestUserName", AuthorizationState.Authorized);
1515

1616
// act
@@ -24,7 +24,7 @@ public void Test001()
2424
public void Test002()
2525
{
2626
// arrange
27-
var authContext = this.AddTestAuthorization();
27+
var authContext = this.AddAuthorization();
2828

2929
// act
3030
var cut = RenderComponent<InjectAuthService>();

docs/samples/tests/xunit/UserInfoTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class UserInfoTest : TestContext
99
public void Test001()
1010
{
1111
// Arrange
12-
this.AddTestAuthorization();
12+
this.AddAuthorization();
1313

1414
// Act
1515
var cut = RenderComponent<UserInfo>();
@@ -23,7 +23,7 @@ public void Test001()
2323
public void Test004()
2424
{
2525
// Arrange
26-
var authContext = this.AddTestAuthorization();
26+
var authContext = this.AddAuthorization();
2727
authContext.SetAuthorizing();
2828

2929
// Act
@@ -38,7 +38,7 @@ public void Test004()
3838
public void Test002()
3939
{
4040
// Arrange
41-
var authContext = this.AddTestAuthorization();
41+
var authContext = this.AddAuthorization();
4242
authContext.SetAuthorized("TEST USER", AuthorizationState.Unauthorized);
4343

4444
// Act
@@ -53,7 +53,7 @@ public void Test002()
5353
public void Test003()
5454
{
5555
// Arrange
56-
var authContext = this.AddTestAuthorization();
56+
var authContext = this.AddAuthorization();
5757
authContext.SetAuthorized("TEST USER");
5858

5959
// Act

docs/samples/tests/xunit/UserRightsTest.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class UserRightsTest : TestContext
1111
public void Test001()
1212
{
1313
// Arrange
14-
var authContext = this.AddTestAuthorization();
14+
var authContext = this.AddAuthorization();
1515
authContext.SetAuthorized("TEST USER");
1616

1717
// Act
@@ -26,7 +26,7 @@ public void Test001()
2626
public void Test002()
2727
{
2828
// Arrange
29-
var authContext = this.AddTestAuthorization();
29+
var authContext = this.AddAuthorization();
3030
authContext.SetAuthorized("TEST USER");
3131
authContext.SetRoles("superuser");
3232

@@ -44,7 +44,7 @@ public void Test002()
4444
public void Test003()
4545
{
4646
// Arrange
47-
var authContext = this.AddTestAuthorization();
47+
var authContext = this.AddAuthorization();
4848
authContext.SetAuthorized("TEST USER");
4949
authContext.SetRoles("admin", "superuser");
5050

@@ -63,7 +63,7 @@ public void Test003()
6363
public void Test004()
6464
{
6565
// Arrange
66-
var authContext = this.AddTestAuthorization();
66+
var authContext = this.AddAuthorization();
6767
authContext.SetAuthorized("TEST USER");
6868
authContext.SetPolicies("content-editor");
6969

@@ -81,7 +81,7 @@ public void Test004()
8181
public void Test0041()
8282
{
8383
// Arrange
84-
var authContext = this.AddTestAuthorization();
84+
var authContext = this.AddAuthorization();
8585
authContext.SetAuthorized("TEST USER");
8686
authContext.SetPolicies("content-editor", "approver");
8787

@@ -99,7 +99,7 @@ public void Test0041()
9999
public void Test006()
100100
{
101101
// Arrange
102-
var authContext = this.AddTestAuthorization();
102+
var authContext = this.AddAuthorization();
103103
authContext.SetAuthorized("TEST USER");
104104
authContext.SetClaims(
105105
new Claim(ClaimTypes.Email, "[email protected]"),
@@ -121,7 +121,7 @@ public void Test006()
121121
public void Test005()
122122
{
123123
// Arrange
124-
var authContext = this.AddTestAuthorization();
124+
var authContext = this.AddAuthorization();
125125
authContext.SetAuthorized("TEST USER");
126126
authContext.SetRoles("admin", "superuser");
127127
authContext.SetPolicies("content-editor");
@@ -144,7 +144,7 @@ public void Test005()
144144
public void Test007()
145145
{
146146
// Arrange
147-
var authContext = this.AddTestAuthorization();
147+
var authContext = this.AddAuthorization();
148148
authContext.SetAuthorized("TEST USER");
149149
authContext.SetAuthenticationType("custom-auth-type");
150150

docs/site/docs/providing-input/passing-parameters-to-components.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ When rendering a `RenderFragment` using the <xref:Bunit.TestContext.Render(Micro
469469
## Passing query parameters (`SupplyParameterFromQuery`) to a component
470470
In .NET 6 and later, components can receive parameters from a query string if the parameter is annotated with the `[SupplyParameterFromQuery]` attribute in addition to the `[Parameter]` attribute.
471471

472-
In .NET 8 however, the `[Parameter]` attribute is no longer required, which means a value cannot be passed to the component during testing using the normal methods, e.g. the <xref:Bunit.ComponentParameterCollectionBuilder`1>'s `Add` method, if a component parameter is only annotated with the `[SupplyParameterFromQuery]` attribute. Instead, pass a query string parameters by setting it using the <xref:Bunit.TestDoubles.FakeNavigationManager>.
472+
In .NET 8 however, the `[Parameter]` attribute is no longer required, which means a value cannot be passed to the component during testing using the normal methods, e.g. the <xref:Bunit.ComponentParameterCollectionBuilder`1>'s `Add` method, if a component parameter is only annotated with the `[SupplyParameterFromQuery]` attribute. Instead, pass a query string parameters by setting it using the <xref:Bunit.TestDoubles.BunitNavigationManager>.
473473

474474
For example:
475475

docs/site/docs/test-doubles/faking-auth.md renamed to docs/site/docs/test-doubles/auth.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
uid: faking-auth
3-
title: Faking authentication and authorization
2+
uid: bunit-auth
3+
title: Adding authentication and authorization
44
---
55

6-
# Faking authentication and authorization
6+
# Adding authentication and authorization
77

88
bUnit comes with test-specific implementations of Blazor's authentication and authorization types, making it easy to test components that use Blazor's `<AuthorizeView>`, `<CascadingAuthenticationState>` and `<AuthorizeRouteView>` components, as well as the `AuthenticationStateProvider` type.
99

@@ -15,10 +15,10 @@ The test implementation of Blazor's authentication and authorization can be put
1515
- **Authenticated** and **authorized**
1616
- **Authenticated** and **authorized** with one or more **roles**, **claims**, and/or **policies**
1717

18-
bUnit's authentication and authorization implementation is easily available by calling [`AddTestAuthorization()`](xref:Bunit.TestDoubles.FakeAuthorizationExtensions.AddTestAuthorization(Bunit.TestContextBase)) on a test context. This adds the necessary services to the `Services` collection and the `CascadingAuthenticationState` component to the [root render tree](xref:root-render-tree). The method returns an instance of the <xref:Bunit.TestDoubles.TestAuthorizationContext> type that allows you to control the authentication and authorization state for a test.
18+
bUnit's authentication and authorization implementation is easily available by calling [`AddAuthorization()`](xref:Bunit.TestDoubles.BunitAuthorizationExtensions.AddAuthorization(Bunit.TestContextBase)) on a test context. This adds the necessary services to the `Services` collection and the `CascadingAuthenticationState` component to the [root render tree](xref:root-render-tree). The method returns an instance of the <xref:Bunit.TestDoubles.TestAuthorizationContext> type that allows you to control the authentication and authorization state for a test.
1919

2020
> [!NOTE]
21-
> If your test class inherits directly from bUnit's <xref:Bunit.TestContext> then you need to call the [`AddTestAuthorization()`](xref:Bunit.TestDoubles.FakeAuthorizationExtensions.AddTestAuthorization(Bunit.TestContextBase)) method on `this`, since `AddTestAuthorization()` is an extension method, otherwise it wont be available. E.g.: `this.AddTestAuthorization()`.
21+
> If your test class inherits directly from bUnit's <xref:Bunit.TestContext> then you need to call the [`AddAuthorization()`](xref:Bunit.TestDoubles.BunitAuthorizationExtensions.AddAuthorization(Bunit.TestContextBase)) method on `this`, since `AddAuthorization()` is an extension method, otherwise it wont be available. E.g.: `this.AddAuthorization()`.
2222
2323
The following sections show how to set each of these states in a test.
2424

@@ -36,33 +36,33 @@ To set the state to unauthenticated and unauthorized, do the following:
3636

3737
[!code-csharp[UserInfoTest.cs](../../../samples/tests/xunit/UserInfoTest.cs?start=11&end=19&highlight=2)]
3838

39-
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.
39+
The highlighted line shows how `AddAuthorization()` 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.
4040

41-
After calling `AddTestAuthorization()`, the default authentication state is unauthenticated and unauthorized.
41+
After calling `AddAuthorization()`, the default authentication state is unauthenticated and unauthorized.
4242

4343
### Authenticating and authorizing state
4444

4545
To set the state to authenticating and authorizing, do the following:
4646

4747
[!code-csharp[UserInfoTest.cs](../../../samples/tests/xunit/UserInfoTest.cs?start=25&end=34&highlight=3)]
4848

49-
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.
49+
After calling `AddAuthorization()`, the returned <xref:Bunit.TestDoubles.TestAuthorizationContext> is used to set the authenticating and authorizing state through the <xref:Bunit.TestDoubles.TestAuthorizationContext.SetAuthorizing> method.
5050

5151
### Authenticated and unauthorized state
5252

5353
To set the state to authenticated and unauthorized, do the following:
5454

5555
[!code-csharp[UserInfoTest.cs](../../../samples/tests/xunit/UserInfoTest.cs?start=40&end=49&highlight=3)]
5656

57-
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.
57+
After calling `AddAuthorization()`, 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.
5858

5959
### Authenticated and authorized state
6060

6161
To set the state to authenticated and authorized, do the following:
6262

6363
[!code-csharp[UserInfoTest.cs](../../../samples/tests/xunit/UserInfoTest.cs?start=55&end=64&highlight=3)]
6464

65-
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.
65+
After calling `AddAuthorization()`, 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.
6666

6767
Note that the second parameter, `AuthorizationState`, is optional, and defaults to `AuthorizationState.Authorized` if not specified.
6868

docs/site/docs/test-doubles/fake-webassemblyhostenvironment.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
2-
uid: fake-webassemblyhostenvironment
3-
title: Faking IWebAssemblyHostEnvironment
2+
uid: bunit-webassemblyhostenvironment
3+
title: Adding IWebAssemblyHostEnvironment
44
---
55

6-
# Faking `IWebAssemblyHostEnvironment`
6+
# Adding `IWebAssemblyHostEnvironment`
77

8-
bUnit has a fake implementation of Blazor's `IWebAssemblyHostEnvironment` built-in, which is added by default to bUnit's `TestContext.Services` service provider. That means nothing special is needed to test components that depend on `IWebAssemblyHostEnvironment`, as it is already available by default.
8+
bUnit has itws own implementation of Blazor's `IWebAssemblyHostEnvironment` built-in, which is added by default to bUnit's `TestContext.Services` service provider. That means nothing special is needed to test components that depend on `IWebAssemblyHostEnvironment`, as it is already available by default.
99

10-
Out of the box, the fake implementation has its `Environment` property set to `production`, and its `BaseAddress` set to `/`.
10+
Out of the box, the implementation has its `Environment` property set to `production`, and its `BaseAddress` set to `/`.
1111

1212
## Setting `Environment` and `BaseAddress`
1313

14-
Lets look at a few examples of how to set the two `IWebAssemblyHostEnvironment` properties `Environment` and `BaseAddress` via the built-in fake.
14+
Lets look at a few examples of how to set the two `IWebAssemblyHostEnvironment` properties `Environment` and `BaseAddress` via the built-in object.
1515

1616
In the examples, we'll use the following `<HelloWorld>` component:
1717

@@ -30,7 +30,7 @@ To verify that the `<HelloWorld>` component correctly says hello to the develope
3030

3131
```csharp
3232
// Arrange
33-
var hostEnvironment = Services.GetRequiredService<FakeWebAssemblyHostEnvironment>();
33+
var hostEnvironment = Services.GetRequiredService<BunitWebAssemblyHostEnvironment>();
3434

3535
// Sets the environment to "Development". There are two other helper
3636
// methods available as well, SetEnvironmentToProduction() and
@@ -48,7 +48,7 @@ To verify that the `<HelloWorld>` component correctly uses the current `BaseAddr
4848

4949
```csharp
5050
// Arrange
51-
var hostEnvironment = Services.GetRequiredService<FakeWebAssemblyHostEnvironment>();
51+
var hostEnvironment = Services.GetRequiredService<BunitWebAssemblyHostEnvironment>();
5252

5353
// Sets a new base address directly on the BaseAddress property.
5454
hostEnvironment.BaseAddress = "myBaseUrl/";

docs/site/docs/test-doubles/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ bUnit does, however, come with a few specially crafted test doubles for some of
1111

1212
The built-in test doubles are described on the following pages:
1313

14-
- <xref:faking-auth>
14+
- <xref:bunit-auth>
1515
- <xref:emulating-ijsruntime>
1616
- <xref:mocking-httpclient>
17-
- <xref:faking-persistentcomponentstate>
18-
- <xref:fake-navigation-manager>
19-
- <xref:fake-webassemblyhostenvironment>
17+
- <xref:bunit-persistentcomponentstate>
18+
- <xref:bunit-navigation-manager>
19+
- <xref:bunit-webassemblyhostenvironment>
2020
- <xref:input-file>

docs/site/docs/test-doubles/fake-navigation-manager.md renamed to docs/site/docs/test-doubles/navigation-manager.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
2-
uid: fake-navigation-manager
3-
title: Faking NavigationManager
2+
uid: bunit-navigation-manager
3+
title: Adding NavigationManager
44
---
55

6-
# Faking `NavigationManager`
6+
# Adding `NavigationManager`
77

8-
bUnit has a fake version of Blazor's `NavigationManager` built-in, which is added by default to bUnit's `TestContext.Services` service provider. That means nothing special is needed to test components that depend on `NavigationManager`, as it is already available by default.
8+
bUnit has its own version of Blazor's `NavigationManager` built-in, which is added by default to bUnit's `TestContext.Services` service provider. That means nothing special is needed to test components that depend on `NavigationManager`, as it is already available by default.
99

1010
## Verify `NavigationManager` interactions
1111

@@ -43,7 +43,7 @@ To verify that the `<PrintCurrentUrl>` component correctly listens to location c
4343

4444
```csharp
4545
// Arrange
46-
var navMan = Services.GetRequiredService<FakeNavigationManager>();
46+
var navMan = Services.GetRequiredService<BunitNavigationManager>();
4747
var cut = RenderComponent<PrintCurrentUrl>();
4848

4949
// Act - trigger a navigation change
@@ -64,11 +64,11 @@ var cut = RenderComponent<PrintCurrentUrl>(parameters => parameters
6464
cut.Find("button").Click();
6565

6666
// Assert - inspect the navigation manager to see if its Uri has been updated.
67-
var navMan = Services.GetRequiredService<FakeNavigationManager>();
67+
var navMan = Services.GetRequiredService<BunitNavigationManager>();
6868
Assert.Equal("http://localhost/foo", navMan.Uri);
6969
```
7070

71-
If a component issues multiple `NavigateTo` calls, then it is possible to inspect the navigation history by accessing the <xref:Bunit.TestDoubles.FakeNavigationManager.History> property. It's a stack based structure, meaning the latest navigations will be first in the collection at index 0.
71+
If a component issues multiple `NavigateTo` calls, then it is possible to inspect the navigation history by accessing the <xref:Bunit.TestDoubles.BunitNavigationManager.History> property. It's a stack based structure, meaning the latest navigations will be first in the collection at index 0.
7272

7373
## Asserting that navigation was prevented with the `NavigationLock` component
7474

@@ -93,7 +93,7 @@ A component can look like this:
9393
A typical test, which asserts that the navigation got prevented, would look like this:
9494

9595
```csharp
96-
var navMan = Services.GetRequiredService<FakeNavigationManager>();
96+
var navMan = Services.GetRequiredService<BunitNavigationManager>();
9797
var cut = RenderComponent<InterceptComponent>();
9898

9999
cut.Find("button").Click();
@@ -123,7 +123,7 @@ As `<a href>` navigation is not natively supported in bUnit, the `NavigationMana
123123
The test utilizes the `NavigationManager` itself to achieve the same:
124124

125125
```csharp
126-
var navMan = Services.GetRequiredService<FakeNavigationManager>();
126+
var navMan = Services.GetRequiredService<BunitNavigationManager>();
127127
var cut = RenderComponent<InterceptAHRefComponent>();
128128

129129
navMan.NavigateTo("/counter");
@@ -149,7 +149,7 @@ NavigationManager.NavigateToLogin("authentication/login", requestOptions);
149149

150150
A test could look like this:
151151
```csharp
152-
var navigationManager = Services.GetRequiredService<FakeNavigationManager>();
152+
var navigationManager = Services.GetRequiredService<BunitNavigationManager>();
153153

154154
ActionToTriggerTheNavigationManager();
155155

0 commit comments

Comments
 (0)