Skip to content

Commit 134723c

Browse files
linkdotnetegil
authored andcommitted
feat: Add simple test
1 parent e8feca6 commit 134723c

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

src/bunit.generators/Web.Stubs/StubAttributeGenerator.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ namespace Bunit.Web.Stubs;
44

55
internal static class StubAttributeGenerator
66
{
7-
public static string StubAttribute => @"
8-
#if NET5_0_OR_GREATER
7+
public static string StubAttribute => @"#if NET5_0_OR_GREATER
98
namespace Bunit;
109
1110
/// <summary>
Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
1+
using System.Reflection;
12
using Microsoft.AspNetCore.Components;
23

34
namespace Bunit.Web.Stub;
45

56
public class StubTests
67
{
78
[Fact]
8-
public void Test001()
9-
{}
9+
public void Stubbed_component_has_same_parameters()
10+
{
11+
var counterComponentStubProperties = typeof(CounterComponentStub).GetProperties();
12+
13+
foreach (var prop in typeof(CounterComponent).GetProperties())
14+
{
15+
var matchingProp = counterComponentStubProperties.FirstOrDefault(p => p.Name == prop.Name);
16+
17+
Assert.NotNull(matchingProp);
18+
19+
var isParameter = prop.GetCustomAttribute(typeof(ParameterAttribute)) is not null;
20+
var stubIsParameter = matchingProp.GetCustomAttribute(typeof(ParameterAttribute)) is not null;
21+
Assert.Equal(isParameter, stubIsParameter);
22+
23+
var isCascadingParameter = prop.GetCustomAttribute(typeof(CascadingParameterAttribute)) is not null;
24+
var stubIsCascadingParameter = matchingProp.GetCustomAttribute(typeof(CascadingParameterAttribute)) is not null;
25+
Assert.Equal(isCascadingParameter, stubIsCascadingParameter);
26+
}
27+
}
1028

1129
[Stub(typeof(CounterComponentStub))]
12-
public class CounterComponentStub : ComponentBase
30+
public partial class CounterComponentStub : ComponentBase
1331
{
1432
}
1533
}

0 commit comments

Comments
 (0)