Skip to content

Commit 7ab39d5

Browse files
committed
Started refactoring bunit into core, web and xunit projects. Removed dependencies on xunit in core and web.
1 parent cadf6f0 commit 7ab39d5

93 files changed

Lines changed: 8460 additions & 4 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ indent_size = 4
2121

2222
[*.sh]
2323
indent_size = 4
24-
end_of_line = lf
24+
end_of_line = lf
25+
26+
[*.{yml,yaml}]
27+
indent_style = space
28+
indent_size = 2

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ All notable changes to **bUnit** will be documented in this file. The project ad
33

44
## [Unreleased]
55

6+
### Removed
7+
- The generic collection assertion methods `ShouldAllBe<T>(this IEnumerable<T> collection, params Action<T, int>[] elementInspectors)` and `ShouldAllBe<T>(this IEnumerable<T> collection, params Action<T>[] elementInspectors)` have been removed from the library.
8+
69
## [1.0.0-beta-6] - 2020-03-01
710
This release includes a **name change from Blazor Components Testing Library to bUnit**. It also brings along two extra helper methods for working with asynchronously rendering components during testing, and a bunch of internal optimizations and tweaks to the code.
811

@@ -242,4 +245,4 @@ The latest version of the library is availble on NuGet:
242245

243246
### Fixed
244247
- **Wrong casing on keyboard event dispatch helpers.**
245-
The helper methods for the keyboard events was not probably cased, so that has been updated. E.g. from `Keypress(...)` to `KeyPress(...)`.
248+
The helper methods for the keyboard events was not probably cased, so that has been updated. E.g. from `Keypress(...)` to `KeyPress(...)`.

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
9+
<PackageReference Update="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0-beta3.final">
1010
<PrivateAssets>all</PrivateAssets>
1111
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1212
</PackageReference>
1313
</ItemGroup>
14-
14+
1515
</Project>

bunit.sln

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.tests", "tests\bunit.
2222
EndProject
2323
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.template", "template\bunit.template.csproj", "{FB46378D-BFB8-4C72-9CA3-0407D4665218}"
2424
EndProject
25+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "code", "code", "{B36CB30C-0AB9-4F79-93B0-25420547439B}"
26+
EndProject
27+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bunit.core", "code\bunit.core\bunit.core.csproj", "{6CD3C6FE-C430-41C2-8D50-C090DC9312F8}"
28+
EndProject
29+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bunit.web", "code\bunit.web\bunit.web.csproj", "{3D3B8EA1-93C1-47D5-96A3-938EAF210191}"
30+
EndProject
31+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bunit.xunit", "code\bunit.xunit\bunit.xunit.csproj", "{F64CF0F2-279B-4D42-80BD-EB26B0F364AC}"
32+
EndProject
33+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bunit.web.tests", "code\bunit.web.tests\bunit.web.tests.csproj", "{D2B61950-A81E-471A-B2C8-B245ADD6979F}"
34+
EndProject
2535
Global
2636
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2737
Debug|Any CPU = Debug|Any CPU
@@ -40,6 +50,22 @@ Global
4050
{FB46378D-BFB8-4C72-9CA3-0407D4665218}.Debug|Any CPU.Build.0 = Debug|Any CPU
4151
{FB46378D-BFB8-4C72-9CA3-0407D4665218}.Release|Any CPU.ActiveCfg = Release|Any CPU
4252
{FB46378D-BFB8-4C72-9CA3-0407D4665218}.Release|Any CPU.Build.0 = Release|Any CPU
53+
{6CD3C6FE-C430-41C2-8D50-C090DC9312F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
54+
{6CD3C6FE-C430-41C2-8D50-C090DC9312F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
55+
{6CD3C6FE-C430-41C2-8D50-C090DC9312F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
56+
{6CD3C6FE-C430-41C2-8D50-C090DC9312F8}.Release|Any CPU.Build.0 = Release|Any CPU
57+
{3D3B8EA1-93C1-47D5-96A3-938EAF210191}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
58+
{3D3B8EA1-93C1-47D5-96A3-938EAF210191}.Debug|Any CPU.Build.0 = Debug|Any CPU
59+
{3D3B8EA1-93C1-47D5-96A3-938EAF210191}.Release|Any CPU.ActiveCfg = Release|Any CPU
60+
{3D3B8EA1-93C1-47D5-96A3-938EAF210191}.Release|Any CPU.Build.0 = Release|Any CPU
61+
{F64CF0F2-279B-4D42-80BD-EB26B0F364AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
62+
{F64CF0F2-279B-4D42-80BD-EB26B0F364AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
63+
{F64CF0F2-279B-4D42-80BD-EB26B0F364AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
64+
{F64CF0F2-279B-4D42-80BD-EB26B0F364AC}.Release|Any CPU.Build.0 = Release|Any CPU
65+
{D2B61950-A81E-471A-B2C8-B245ADD6979F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
66+
{D2B61950-A81E-471A-B2C8-B245ADD6979F}.Debug|Any CPU.Build.0 = Debug|Any CPU
67+
{D2B61950-A81E-471A-B2C8-B245ADD6979F}.Release|Any CPU.ActiveCfg = Release|Any CPU
68+
{D2B61950-A81E-471A-B2C8-B245ADD6979F}.Release|Any CPU.Build.0 = Release|Any CPU
4369
EndGlobalSection
4470
GlobalSection(SolutionProperties) = preSolution
4571
HideSolutionNode = FALSE
@@ -48,6 +74,10 @@ Global
4874
{AA96790B-67C9-4141-ACDB-037C8DC092EC} = {E006E9A4-F554-46DF-838F-812956521F64}
4975
{04E0142A-33CC-4E30-B903-F1370D94AD8C} = {C929375E-BD70-4B78-88C1-BDD1623C3365}
5076
{FB46378D-BFB8-4C72-9CA3-0407D4665218} = {E006E9A4-F554-46DF-838F-812956521F64}
77+
{6CD3C6FE-C430-41C2-8D50-C090DC9312F8} = {B36CB30C-0AB9-4F79-93B0-25420547439B}
78+
{3D3B8EA1-93C1-47D5-96A3-938EAF210191} = {B36CB30C-0AB9-4F79-93B0-25420547439B}
79+
{F64CF0F2-279B-4D42-80BD-EB26B0F364AC} = {B36CB30C-0AB9-4F79-93B0-25420547439B}
80+
{D2B61950-A81E-471A-B2C8-B245ADD6979F} = {B36CB30C-0AB9-4F79-93B0-25420547439B}
5181
EndGlobalSection
5282
GlobalSection(ExtensibilityGlobals) = postSolution
5383
SolutionGuid = {24106918-1C86-4769-BDA6-9C80E64CD260}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Bunit.Asserting
8+
{
9+
/// <summary>
10+
/// Represents a generic assert exception used when an actual result does not match an expected result.
11+
/// </summary>
12+
public class ActualExpectedAssertException : Exception
13+
{
14+
/// <summary>
15+
/// Creates an instance of the <see cref="ActualExpectedAssertException"/>.
16+
/// </summary>
17+
/// <param name="actual">The actual result</param>
18+
/// <param name="expected">The expected result</param>
19+
/// <param name="actualText">A text explaining the actual result</param>
20+
/// <param name="expectedText">A text explaining the expected result</param>
21+
/// <param name="message">An error message explaining the context of the assertion</param>
22+
public ActualExpectedAssertException(string actual, string expected, string actualText, string expectedText, string message)
23+
: base(CreateMessage(actual, expected, actualText, expectedText, message))
24+
{
25+
}
26+
27+
private static string CreateMessage(string actual, string expected, string actualText, string expectedText, string message)
28+
{
29+
return $"{message}{Environment.NewLine}{actualText}: {actual}{Environment.NewLine}{expectedText}: {expected}";
30+
}
31+
}
32+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Diagnostics.CodeAnalysis;
5+
using Microsoft.Extensions.DependencyInjection;
6+
7+
namespace Bunit
8+
{
9+
/// <summary>
10+
/// Represents a <see cref="IServiceProvider"/> and <see cref="IServiceCollection"/>
11+
/// as a single type used for test purposes.
12+
/// </summary>
13+
[SuppressMessage("Naming", "CA1710:Identifiers should have correct suffix")]
14+
public sealed class TestServiceProvider : IServiceProvider, IServiceCollection, IDisposable
15+
{
16+
private readonly IServiceCollection _serviceCollection;
17+
private ServiceProvider? _serviceProvider;
18+
19+
/// <summary>
20+
/// Gets a reusable default test service provider.
21+
/// </summary>
22+
public static readonly IServiceProvider Default = new TestServiceProvider(new ServiceCollection(), true);
23+
24+
/// <summary>
25+
/// Gets whether this <see cref="TestServiceProvider"/> has been initialized, and
26+
/// no longer will accept calls to the <c>AddService</c>'s methods.
27+
/// </summary>
28+
public bool IsProviderInitialized => _serviceProvider is { };
29+
30+
/// <inheritdoc/>
31+
public int Count => _serviceCollection.Count;
32+
33+
/// <inheritdoc/>
34+
public bool IsReadOnly => IsProviderInitialized || _serviceCollection.IsReadOnly;
35+
36+
/// <inheritdoc/>
37+
public ServiceDescriptor this[int index]
38+
{
39+
get => _serviceCollection[index];
40+
set
41+
{
42+
CheckInitializedAndThrow();
43+
_serviceCollection[index] = value;
44+
}
45+
}
46+
47+
/// <summary>
48+
/// Creates an instance of the <see cref="TestServiceProvider"/> and sets its service collection to the
49+
/// provided <paramref name="initialServiceCollection"/>, if any.
50+
/// </summary>
51+
/// <param name="initialServiceCollection"></param>
52+
public TestServiceProvider(IServiceCollection? initialServiceCollection = null) : this(initialServiceCollection ?? new ServiceCollection(), false)
53+
{
54+
}
55+
56+
private TestServiceProvider(IServiceCollection initialServiceCollection, bool initializeProvider)
57+
{
58+
_serviceCollection = initialServiceCollection;
59+
if (initializeProvider) _serviceProvider = _serviceCollection.BuildServiceProvider();
60+
}
61+
62+
/// <summary>
63+
/// Get service of type T from the test provider.
64+
/// </summary>
65+
/// <typeparam name="TService">The type of service object to get.</typeparam>
66+
/// <returns>A service object of type T or null if there is no such service.</returns>
67+
public TService GetService<TService>() => (TService)GetService(typeof(TService));
68+
69+
/// <inheritdoc/>
70+
public object GetService(Type serviceType)
71+
{
72+
if (_serviceProvider is null)
73+
_serviceProvider = _serviceCollection.BuildServiceProvider();
74+
75+
return _serviceProvider.GetService(serviceType);
76+
}
77+
78+
/// <inheritdoc/>
79+
public IEnumerator<ServiceDescriptor> GetEnumerator() => _serviceCollection.GetEnumerator();
80+
81+
/// <inheritdoc/>
82+
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
83+
84+
/// <inheritdoc/>
85+
public void Dispose()
86+
{
87+
_serviceProvider?.Dispose();
88+
}
89+
90+
/// <inheritdoc/>
91+
public int IndexOf(ServiceDescriptor item) => _serviceCollection.IndexOf(item);
92+
/// <inheritdoc/>
93+
public void Insert(int index, ServiceDescriptor item)
94+
{
95+
CheckInitializedAndThrow();
96+
_serviceCollection.Insert(index, item);
97+
}
98+
/// <inheritdoc/>
99+
public void RemoveAt(int index)
100+
{
101+
CheckInitializedAndThrow();
102+
_serviceCollection.RemoveAt(index);
103+
}
104+
105+
/// <inheritdoc/>
106+
public void Add(ServiceDescriptor item)
107+
{
108+
CheckInitializedAndThrow();
109+
_serviceCollection.Add(item);
110+
}
111+
/// <inheritdoc/>
112+
public void Clear()
113+
{
114+
CheckInitializedAndThrow();
115+
_serviceCollection.Clear();
116+
}
117+
118+
/// <inheritdoc/>
119+
public bool Contains(ServiceDescriptor item) => _serviceCollection.Contains(item);
120+
/// <inheritdoc/>
121+
public void CopyTo(ServiceDescriptor[] array, int arrayIndex) => _serviceCollection.CopyTo(array, arrayIndex);
122+
/// <inheritdoc/>
123+
public bool Remove(ServiceDescriptor item)
124+
{
125+
CheckInitializedAndThrow();
126+
return _serviceCollection.Remove(item);
127+
}
128+
129+
private void CheckInitializedAndThrow()
130+
{
131+
if (IsProviderInitialized)
132+
throw new InvalidOperationException("Services cannot be added to provider after it has been initialized.");
133+
}
134+
}
135+
}

code/bunit.core/bunit.core.csproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
<RazorLangVersion>3.0</RazorLangVersion>
6+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
7+
<RootNamespace>Bunit</RootNamespace>
8+
<AssemblyName>Bunit.Core</AssemblyName>
9+
</PropertyGroup>
10+
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.*" />
14+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.*" />
15+
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.*" />
16+
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.*" />
17+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.*" PrivateAssets="All" />
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<IsPackable>false</IsPackable>
6+
<RootNamespace>Bunit</RootNamespace>
7+
<AssemblyName>Bunit.Web.Tests</AssemblyName>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="AngleSharp" Version="0.13.0" />
12+
<PackageReference Include="AngleSharp.Css" Version="0.13.0" />
13+
<PackageReference Include="AngleSharp.Diffing" Version="0.13.3-alpha-44" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
15+
<PackageReference Include="Shouldly" Version="4.0.0-beta0002" />
16+
<PackageReference Include="xunit" Version="2.4.1" />
17+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
18+
<PrivateAssets>all</PrivateAssets>
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20+
</PackageReference>
21+
<PackageReference Include="coverlet.collector" Version="1.2.0" />
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<ProjectReference Include="..\bunit.web\bunit.web.csproj" />
26+
</ItemGroup>
27+
28+
</Project>

0 commit comments

Comments
 (0)