Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6b22c39
Update CI-CD-Docs.yml
egil May 19, 2020
2588887
Update README.md
egil May 19, 2020
d777bd7
updated docs styling
egil May 19, 2020
31b2b6c
new push workflow to nuget
egil May 19, 2020
b84984e
update to workflows
egil May 19, 2020
3bea071
Update .force-nuget-push
egil May 19, 2020
cb52202
Update .force-nuget-push
egil May 19, 2020
53f7c83
update to push workflows
egil May 19, 2020
552b231
Update .force-nuget-push
egil May 19, 2020
56d1170
updates to publish workflow
egil May 19, 2020
ae42cfb
updated to workflow
egil May 19, 2020
2ddbc08
Update .force-nuget-push
egil May 19, 2020
5890837
release workflow update
egil May 19, 2020
5fb8a01
Update .force-nuget-push
egil May 19, 2020
16558a0
CI workflow update
egil May 19, 2020
34ff673
Update index.md
egil May 19, 2020
bb7ff56
Set next version to beta-8
egil May 19, 2020
6d2adcc
make dispose virtual (#137)
SimonCropp May 20, 2020
e0e3330
Started section in changelog for beta-8
egil May 20, 2020
fe4cd6c
DEV workflow tweaks to not run when they contain changes to non sourc…
egil May 20, 2020
b08ea7e
Changed global.json to not allow SDK prereleases
egil May 20, 2020
1a321b6
Merge branch 'master' into dev
egil May 20, 2020
d8f5b95
Delete pull_request_template.md
egil May 20, 2020
e1682a6
Update CI-PR.yml
egil May 20, 2020
a295e0c
Update CI.yml
egil May 20, 2020
007b8b3
Removed CS8602 error from tests, which started to show up with 3.1.300
egil May 20, 2020
8742dfd
Update CHANGELOG.md
egil Jun 15, 2020
286017f
Merge branch 'main' into dev
egil Jun 16, 2020
89c9dcf
new workflow for pushing to GPR
egil Jun 16, 2020
5b554aa
Merge branch 'main' into dev
egil Jun 17, 2020
f04daf5
CodeDoc FindComponents - specify the order is from depth first search
egil Jun 18, 2020
a54efc3
Added dotnet serve local tool and script that enable hosting docs web…
egil Jun 18, 2020
c2cf2b3
Fix/naming convention jsinterop (#150)
yourilima Jun 19, 2020
7cc6e1f
docs contrib guidelines update
egil Jun 19, 2020
3f730fa
Merge branch 'main' into dev
egil Jun 24, 2020
25ebd5f
Docs: Verify Markup page first parts
egil Jun 24, 2020
b7f0334
Docs: verify markup
egil Jun 24, 2020
6b8dc3f
Docs: completed verify markup page
egil Jun 25, 2020
41540d5
Dev authorization fakes (#151)
DarthPedro Jun 25, 2020
d5ebfbc
Added `MarkupMatches(this string actual ...)` extension methods. Mak…
egil Jun 26, 2020
99a97c5
Moved InvokeAsync from IRenderedFragmentBase to IRenderedComponentBas…
egil Jun 26, 2020
a20d0a2
Merge branch 'main' into dev
egil Jul 15, 2020
020ccd9
Update changelog
egil Jul 15, 2020
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
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-serve": {
"version": "1.7.125",
"commands": [
"dotnet-serve"
]
}
}
}
7 changes: 4 additions & 3 deletions .github/workflows/CI-PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ on:
pull_request:
branches:
- dev
paths-ignore:
- 'docs/**'
paths:
- 'sample/**'
- 'src/**'

env:
VERSION: ''
Expand Down Expand Up @@ -58,4 +59,4 @@ jobs:
dotnet new --install ${GITHUB_WORKSPACE}/packages/bunit.template.$VERSION.nupkg
dotnet new bunit --no-restore -o ${GITHUB_WORKSPACE}/Test
dotnet restore ${GITHUB_WORKSPACE}/Test/Test.csproj --source ${GITHUB_WORKSPACE}/packages
dotnet test ${GITHUB_WORKSPACE}/Test
dotnet test ${GITHUB_WORKSPACE}/Test
5 changes: 3 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ on:
push:
branches:
- dev
paths-ignore:
- 'docs/**'
paths:
- 'sample/**'
- 'src/**'

env:
VERSION: ''
Expand Down
42 changes: 41 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,47 @@

All notable changes to **bUnit** will be documented in this file. The project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0-beta-7] - 2020-05-19
## [Unreleased]

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### Added
List of new features.

### Changed
List of changes in existing functionality.

### Deprecated
List of soon-to-be removed features.

### Removed
List of now removed features.

### Fixed
List of any bug fixes.

### Security
List of fixed security vulnerabilities.

## [1.0.0-beta-8] - 2020-07-15

Here is beta-8, a small summer vacation release this time. A few needed additions, especially around testing components that use Blazor's authentication and authorization. In addition to this, a lot of documentation has been added to https://bunit.egilhansen.com/docs/getting-started/.

### Added
List of new features.

- Authorization fakes added to make it much easier to test components that use authentication and authorization. Learn more in the [Faking Blazor's Authentication and Authorization](https://bunit.egilhansen.com/docs/test-doubles/faking-auth) page. By [@DarthPedro](https://github.com/DarthPedro) in [#151](https://github.com/egil/bUnit/pull/151).

- Added `MarkupMatches(this string actual ...)` extension methods. Make it easier to compare just the text content from a DON text node with a string, while still getting the benefit of the semantic HTML comparer.

### Changed
List of changes in existing functionality.

- `TestContextBase.Dispose` made virtual to allow inheritor's to override it. By [@SimonCropp](https://github.com/SimonCropp) in [#137](https://github.com/egil/bunit/pull/137).

- **[Breaking change]** Changed naming convention for JSMock feature and moved to new namespace, `Bunit.TestDoubles.JSInterop`. All classes and methods containing `Js` (meaning JavaScript) renamed to `JS` for consistency with Blazor's `IJSRuntime`. By [@yourilima](https://github.com/yourilima) in [#150](https://github.com/egil/bUnit/pull/150)

## [1.0.0-beta-7] - 2020-05-19## [1.0.0-beta-7] - 2020-05-19

There are three big changes in bUnit in this release, as well as a whole host of small new features, improvements to the API, and bug fixes. The three big changes are:

Expand Down
32 changes: 32 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Contributing to the documentation

This folder contains the documentation site for bUnit.

Here is a small getting started guide for contributing to the documentation.

## Structure

1. The `site` folder contains the code for generating the documentation site, _and_ the documentation in markdown files, located in `site/docs`.
2. The `samples` folder projects for the sample code that is displayed in the documentation. It has the following projects:
- `samples/components`: A Blazor component library project where components under test are placed.
- `samples/tests/mstest`: A MSTest project, where MSTest test samples are placed.
- `samples/tests/nunit`: A NUnit project, where NUnit test samples are placed.
- `samples/tests/razor`: A xUnit based test project, where razor test samples are placed.
- `samples/tests/xunit`: A xUnit project, where xUnit C# only test samples are placed.

These samples components source files and tests source files are included in the documentation using [DocFx's Code Snippet syntax](https://dotnet.github.io/docfx/spec/docfx_flavored_markdown.html?tabs=tabid-1%2Ctabid-a#code-snippet). They are created as real projects, making them runnable, which helps ensure that the code shown in the documentation pages are correct and works.

## Building and view docs locally

To build and view the documentation locally, a few steps is needed:

1. From `docs/site` run `dotnet build`. If you get warnings from running `dotnet build`, try running it again.
2. From `docs/` run `serve-docs.cmd`, it will start up a local web server, hosting the generated documentation site on http://localhost:8080, using the [`dotnet serve` tool](https://github.com/natemcmaster/dotnet-serve).
3. After changing samples, from `docs/samples`, run `dotnet test`. This will compile the sample components and run the sample tests.

## Documentation writing rules

- All pages should have a [YAML header](https://dotnet.github.io/docfx/spec/docfx_flavored_markdown.html#yaml-header) with an `UID` to enable easy [cross reference](https://dotnet.github.io/docfx/spec/docfx_flavored_markdown.html#cross-reference) between pages
- All page and code references should be created using the [`xref:UID` cross reference syntax](https://dotnet.github.io/docfx/tutorial/links_and_cross_references.html#using-cross-reference).
- Prefer to include code snippets as from sample files in the `samples` projects, using the [code snippet syntax](https://dotnet.github.io/docfx/spec/docfx_flavored_markdown.html#code-snippet).
- All code snippets should use 2 spaces as an indention unit (1 tab = 2 spaces)
24 changes: 24 additions & 0 deletions docs/samples/components/InjectAuthService.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@using Microsoft.AspNetCore.Components.Authorization
@inject AuthenticationStateProvider AuthenticationStateProvider

<p>Test Component</p>

@if (isAuthenticated)
{
<p>User: @userName</p>
}

@code{
bool isAuthenticated = false;
string userName;

protected override async Task OnInitializedAsync()
{
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync().ConfigureAwait(false);
if (state != null)
{
this.isAuthenticated = state.User.Identity.IsAuthenticated;
this.userName = state.User.Identity.Name;
}
}
}
37 changes: 37 additions & 0 deletions docs/samples/components/UserInfo.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@using Microsoft.AspNetCore.Components.Authorization
@inject AuthenticationStateProvider AuthenticationStateProvider

@if (isAuthenticated)
{
<h1>Welcome @userName</h1>
}
@if (!isAuthenticated)
{
<h1>Please log in!</h1>
}
<CascadingAuthenticationState>
<AuthorizeView>
<Authorized>
<p>State: Authorized</p>
</Authorized>
<Authorizing>
<p>State: Authorizing</p>
</Authorizing>
<NotAuthorized>
<p>State: Not authorized</p>
</NotAuthorized>
</AuthorizeView>
</CascadingAuthenticationState>

@code
{
bool isAuthenticated = false;
string userName;

protected override async Task OnParametersSetAsync()
{
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
isAuthenticated = state.User.Identity.IsAuthenticated;
userName = state.User.Identity.Name;
}
}
36 changes: 36 additions & 0 deletions docs/samples/components/UserRights.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@using Microsoft.AspNetCore.Components.Authorization
@using System.Security.Claims
@using System.Globalization

<CascadingAuthenticationState>
<AuthorizeView>
<h1>Hi @context.User.Identity.Name, you have these claims and rights:</h1>
</AuthorizeView>
<ul>
<AuthorizeView>
@foreach (var claim in @context.User.FindAll(x => x.Type != ClaimTypes.Name))
{
<li>@GetClaimName(claim): @claim.Value</li>
}
</AuthorizeView>
<AuthorizeView Roles="superuser">
<li>You have the role SUPER USER</li>
</AuthorizeView>
<AuthorizeView Roles="admin">
<li>You have the role ADMIN</li>
</AuthorizeView>
<AuthorizeView Policy="content-editor">
<li>You are a CONTENT EDITOR</li>
</AuthorizeView>
</ul>
</CascadingAuthenticationState>

@code
{
private static string GetClaimName(Claim claim)
{
var claimType = new Uri(claim.Type);
var name = claimType.Segments.Last();
return CultureInfo.InvariantCulture.TextInfo.ToTitleCase(name);
}
}
1 change: 1 addition & 0 deletions docs/samples/components/bunit.docs.samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.4" />
</ItemGroup>

Expand Down
38 changes: 38 additions & 0 deletions docs/samples/tests/xunit/InjectAuthServiceTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Bunit.TestDoubles.Authorization;
using System;
using Xunit;

namespace Bunit.Docs.Samples
{
public class InjectAuthServiceTest
{
[Fact(DisplayName = "Use AuthenticationStateProvider service with authenticated and authorized user")]
public void Test001()
{
// arrange
using var ctx = new TestContext();
var authContext = ctx.Services.AddTestAuthorization();
authContext.SetAuthorized("TestUserName", AuthorizationState.Authorized);

// act
var cut = ctx.RenderComponent<InjectAuthService>();

// assert
Assert.Contains("<p>User: TestUserName</p>", cut.Markup, StringComparison.InvariantCulture);
}

[Fact(DisplayName = "Use AuthenticationStateProvider service with unauthenticated and unauthorized user")]
public void Test002()
{
// arrange
using var ctx = new TestContext();
var authContext = ctx.Services.AddTestAuthorization();

// act
var cut = ctx.RenderComponent<InjectAuthService>();

// assert
Assert.DoesNotContain("User:", cut.Markup, StringComparison.InvariantCulture);
}
}
}
71 changes: 71 additions & 0 deletions docs/samples/tests/xunit/UserInfoTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using Bunit.TestDoubles.Authorization;
using Xunit;

namespace Bunit.Docs.Samples
{
public class UserInfoTest
{
[Fact(DisplayName = "UserInfo with unauthenticated user")]
public void Test001()
{
// Arrange
using var ctx = new TestContext();
ctx.Services.AddTestAuthorization();

// Act
var cut = ctx.RenderComponent<UserInfo>();

// Assert
cut.MarkupMatches(@"<h1>Please log in!</h1>
<p>State: Not authorized</p>");
}

[Fact(DisplayName = "UserInfo while authorizing user")]
public void Test004()
{
// Arrange
using var ctx = new TestContext();
var authContext = ctx.Services.AddTestAuthorization();
authContext.SetAuthorizing();

// Act
var cut = ctx.RenderComponent<UserInfo>();

// Assert
cut.MarkupMatches(@"<h1>Please log in!</h1>
<p>State: Authorizing</p>");
}

[Fact(DisplayName = "UserInfo with authenticated but unauthorized user")]
public void Test002()
{
// Arrange
using var ctx = new TestContext();
var authContext = ctx.Services.AddTestAuthorization();
authContext.SetAuthorized("TEST USER", AuthorizationState.Unauthorized);

// Act
var cut = ctx.RenderComponent<UserInfo>();

// Assert
cut.MarkupMatches(@"<h1>Welcome TEST USER</h1>
<p>State: Not authorized</p>");
}

[Fact(DisplayName = "UserInfo with authenticated and authorized user")]
public void Test003()
{
// Arrange
using var ctx = new TestContext();
var authContext = ctx.Services.AddTestAuthorization();
authContext.SetAuthorized("TEST USER");

// Act
var cut = ctx.RenderComponent<UserInfo>();

// Assert
cut.MarkupMatches(@"<h1>Welcome TEST USER</h1>
<p>State: Authorized</p>");
}
}
}
Loading