Skip to content

Commit 85f2f2c

Browse files
authored
Merge pull request #1722 from bUnit-dev/v2-migration-docs
V2 migration docs
2 parents 0f68a6a + 055c055 commit 85f2f2c

File tree

6 files changed

+80
-6
lines changed

6 files changed

+80
-6
lines changed

docs/serve-docs.cmd

Lines changed: 0 additions & 2 deletions
This file was deleted.

docs/serve-docs.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

docs/site/docs/migrations/1to2.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
uid: migrating-from-1-to-2
3+
title: Migrating from 1.x to 2.x
4+
---
5+
6+
# Migrating from bUnit 1.x to 2.x
7+
This document describes the changes made in bUnit 2.x that may affect existing tests written for bUnit 1.x. The old documentation for bUnit 1.x is available at: https://v1.bunit.dev.
8+
9+
## One package to rule them all
10+
`bunit.core` and `bunit.web` have be merged into a single package called `bunit`. The seperation was used to allow for extensibitlity, which isn't used anymore. Therefore `bunit.core` and `bunit.web` will stay on version 1.x, while `bunit` will be the only package going forward. To migrate, simply remove the `bunit.core` and `bunit.web` packages and add the `bunit` package. We don't expect many users to have used the `bunit.core` or `bunit.web` package directly, but may hit 3rd party packages that depend on them.
11+
12+
## `TestContext` renamed to `BunitContext`
13+
14+
The `TestContext` class has been renamed to `BunitContext`. To migrate tests, rename all instances of `TestContext` to `BunitContext`:
15+
16+
```diff
17+
- public class MyTestClass : TestContext
18+
+ public class MyTestClass : BunitContext
19+
```
20+
21+
## `BunitContext` offers `Dispose` and `DisposeAsync` methods
22+
In version 1, the `TestContext` class only implemented `IDisposable`, but in version 2, it also implements `IAsyncDisposable`. Therefore, if there are asynchronous disposable inside the container for example, the asynchronous version should be used.
23+
24+
## The `Fake` prefix was renamed to `Bunit` (e.g. `FakeNavigationManager` to `BunitNavigationManager`)
25+
The `Fake` prefix used for various fake implementations has been renamed to `Bunit`. This includes the following types:
26+
* `FakeNavigationManager` to `BunitNavigationManager`
27+
* `FakeJSRuntime` to `BunitJSRuntime`
28+
* `FakeAuthenticationStateProvider` to `BunitAuthenticationStateProvider`
29+
* `FakeAuthrozitationContext` to `BunitAuthorizationContext`
30+
* `FakeuthorizationPolicyProvider` to `BunitAuthorizationPolicyProvider`
31+
32+
## Unified the `Render` methods
33+
In v1 there were multiple `RenderXXX`methods (like `RenderComponent`, `Render` and `SetParametersAndRender`) that were used to render components and markup. In v2, these methods have been unified into a single `Render` method that can handle both components and markup) via the simple `Render` method:
34+
35+
```diff
36+
- var cut = RenderComponent<MyComponent>();
37+
+ var cut = Render<MyComponent>();
38+
```
39+
40+
## Removed some abstraction
41+
Many types were removed in favor of one public type:
42+
* `IRenderedComponent<TComponent>` - where `TComponent` is the type of the component rendered (or the a `ContainerFragment` if markup was rendered).
43+
44+
The removed types were:
45+
* `IRenderedFragment`
46+
* `IRenderedComponent`
47+
* `IRenderedMarkup`
48+
* `IRenderedComponentBase`
49+
50+
If any of the types were used (for example in extensions methods), they should be replaced with `IRenderedComponent`.
51+
52+
## Removed of `IsNullOrEmpty` extension method on `IEnumerable<T>` and `CreateLogger` on `IServiceProvider`
53+
The `IsNullOrEmpty` extension method on `IEnumerable<T>` has been removed, as well as the `CreateLogger` extension method on `IServiceProvider`. These extension methods are pretty common and conflict with other libraries. These methods can be recreated like this:
54+
55+
```csharp
56+
public static class Extensions
57+
{
58+
public static bool IsNullOrEmpty<T>(this IEnumerable<T> enumerable)
59+
=> enumerable == null || !enumerable.Any();
60+
61+
public static ILogger<T> CreateLogger<T>(this IServiceProvider serviceProvider)
62+
{
63+
var loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>() ?? NullLoggerFactory.Instance;
64+
return loggerFactory.CreateLogger<T>();
65+
}
66+
}
67+
```

docs/site/docs/migrations/index.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
uid: migrations
3+
title: Migrations
4+
---
5+
6+
# Migrations
7+
8+
This section covers the migration across major versions of bUnit. The mirations themselves also list the link to the old version of the documentation (including the old API documentation).
9+
10+
- <xref:migrating-from-1-to-2>

docs/site/docs/toc.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
# [Extensions](xref:extensions)
3636
## [bunit.generators](xref:bunit-generators)
3737

38+
# [Migrations](xref:migrations)
39+
## [1.x to 2.x](xref:migrating-from-1-to-2)
40+
3841
# [Miscellaneous testing tips](xref:misc-test-tips)
3942
# [External resources](xref:external-resources)
4043
# [Contribute](xref:contribute)

docs/site/index.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ bUnit is available on NuGet in various incarnations. Most users should just pick
4242
| Name | Description | NuGet Download Link |
4343
| ----- | ----- | ---- |
4444
| [bUnit](https://www.nuget.org/packages/bunit/) | Includes the bUnit.core and bUnit.web packages. | [![Nuget](https://img.shields.io/nuget/dt/bunit?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit/) |
45-
| [bUnit.core](https://www.nuget.org/packages/bunit.core/) | Core library that enables rendering a Blazor component in a test context. | [![Nuget](https://img.shields.io/nuget/dt/bunit.core?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.core/) |
46-
| [bUnit.web](https://www.nuget.org/packages/bunit.web/) | Adds support for testing Blazor components for the web. This includes bUnit.core. | [![Nuget](https://img.shields.io/nuget/dt/bunit.web?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.web/) |
4745
| [bUnit.template](https://www.nuget.org/packages/bunit.template/) | Template for bUnit test projects based on xUnit, NUnit or MSTest | [![Nuget](https://img.shields.io/nuget/dt/bunit.template?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.template/) |
4846
| [bUnit.generators](https://www.nuget.org/packages/bunit.generators/)|Source code generators to minimize code setup in various situations.|[![Nuget](https://img.shields.io/nuget/dt/bunit.generators?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.generators/)|
4947
| [bUnit.web.query](https://www.nuget.org/packages/bunit.web.query/)|bUnit implementation of testing-library.com's query APIs.|[![Nuget](https://img.shields.io/nuget/dt/bunit.web.query?logo=nuget&style=flat-square)](https://www.nuget.org/packages/bunit.web.query/)|

0 commit comments

Comments
 (0)