Skip to content

Commit fd27ac3

Browse files
committed
cp
1 parent 9d3f1aa commit fd27ac3

27 files changed

Lines changed: 244 additions & 200 deletions

src/bunit.core/FragmentBase.cs

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This file is used by Code Analysis to maintain SuppressMessage
2+
// attributes that are applied to this project.
3+
// Project-level suppressions either have no target or are given
4+
// a specific target and scoped to a namespace, type, member, etc.
5+
6+
using System.Diagnostics.CodeAnalysis;
7+
8+
[assembly: SuppressMessage("Usage", "BL0006:Do not use RenderTree types")]

src/bunit.core/RazorTestRenderer.cs

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

src/bunit.web/Components/ComponentUnderTest.cs renamed to src/bunit.core/RazorTesting/ComponentUnderTest.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
using System.Threading.Tasks;
2+
using Bunit.RazorTesting;
23
using Microsoft.AspNetCore.Components;
34

45
namespace Bunit
56
{
6-
/// <summary>
7-
/// Represents a component that can be added inside a <see cref="Fixture"/>,
8-
/// where a component under test can be defined as the child content.
9-
/// </summary>
10-
public class ComponentUnderTest : FragmentBase
7+
/// <summary>
8+
/// Represents a component that can be added inside a <see cref="Fixture"/>,
9+
/// where a component under test can be defined as the child content.
10+
/// </summary>
11+
public class ComponentUnderTest : FragmentBase
1112
{
1213
/// <inheritdoc />
1314
public override Task SetParametersAsync(ParameterView parameters)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Threading.Tasks;
4+
using Bunit.RazorTesting;
45
using Microsoft.AspNetCore.Components;
56

67
namespace Bunit
@@ -69,6 +70,7 @@ public class Fixture : RazorTest
6970
/// </summary>
7071
[Parameter] public IReadOnlyCollection<Func<Task>> TestsAsync { get => _testsAsync; set => _testsAsync = value ?? Array.Empty<Func<Task>>(); }
7172

73+
/// <inheritdoc/>
7274
public override Task RunTest() => throw new NotImplementedException();
7375
}
7476
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Bunit.RazorTesting;
2+
using Microsoft.AspNetCore.Components;
3+
4+
namespace Bunit
5+
{
6+
/// <summary>
7+
/// Represents a component that can be added inside a <see cref="Fixture"/>, whose content
8+
/// can be accessed in Razor-based test.
9+
/// </summary>
10+
public class Fragment : FragmentBase
11+
{
12+
/// <summary>
13+
/// Gets or sets the id of the fragment.
14+
/// </summary>
15+
[Parameter] public string Id { get; set; } = string.Empty;
16+
}
17+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Microsoft.AspNetCore.Components;
4+
5+
namespace Bunit.RazorTesting
6+
{
7+
/// <summary>
8+
/// Represents a component that can be used to capture a render fragment.
9+
/// </summary>
10+
public abstract class FragmentBase : IComponent
11+
{
12+
/// <summary>
13+
/// A no-op test method.
14+
/// </summary>
15+
protected static void NoopTestMethod() { }
16+
17+
/// <summary>
18+
/// A no-op async test method
19+
/// </summary>
20+
protected static Task NoopTestMethodAsync() => Task.CompletedTask;
21+
22+
/// <summary>
23+
/// Gets or sets the child content of the fragment.
24+
/// </summary>
25+
[Parameter] public RenderFragment ChildContent { get; set; } = default!;
26+
27+
/// <inheritdoc />
28+
public void Attach(RenderHandle renderHandle) { }
29+
30+
/// <inheritdoc />
31+
public virtual Task SetParametersAsync(ParameterView parameters)
32+
{
33+
parameters.SetParameterProperties(this);
34+
if (ChildContent is null)
35+
throw new InvalidOperationException($"No {nameof(ChildContent)} specified in test component.");
36+
return Task.CompletedTask;
37+
}
38+
}
39+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Threading.Tasks;
66
using Microsoft.AspNetCore.Components;
77

8-
namespace Bunit
8+
namespace Bunit.RazorTesting
99
{
1010
/// <summary>
1111
/// Represents a component used to define tests in Razor files.
@@ -22,6 +22,10 @@ public abstract class RazorTest : FragmentBase
2222
/// </summary>
2323
[Parameter] public string? Skip { get; set; }
2424

25+
/// <summary>
26+
/// Run the test logic of the <see cref="RazorTest"/>.
27+
/// </summary>
28+
/// <returns></returns>
2529
public abstract Task RunTest();
2630

2731
/// <inheritdoc/>

src/bunit.web/Rendering/ComponentNotFoundException.cs renamed to src/bunit.core/Rendering/ComponentNotFoundException.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
using System;
1+
using System;
22

33
namespace Bunit
44
{
55
/// <summary>
6-
/// Represents an exception that is thrown when a search for a component in a
7-
/// <see cref="IRenderedFragment"/> did not succeed.
6+
/// Represents an exception that is thrown when a search for a component did not succeed.
87
/// </summary>
98
public class ComponentNotFoundException : Exception
109
{
@@ -16,4 +15,4 @@ public ComponentNotFoundException(Type componentType) : base($"A component of ty
1615
{
1716
}
1817
}
19-
}
18+
}
File renamed without changes.

0 commit comments

Comments
 (0)