Skip to content

Commit 291428f

Browse files
committed
Refactored classes and moved ComponentBuildDelegate to ComponentTestContext (closes #181)
1 parent abd9fb5 commit 291428f

File tree

21 files changed

+41
-42
lines changed

21 files changed

+41
-42
lines changed

src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Base/BaseTestBuilderWithComponent.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ protected BaseTestBuilderWithComponent(ComponentTestContext testContext)
2525
: base(testContext)
2626
{
2727
this.TestContext = testContext;
28-
this.BuildComponentAction += () => { };
2928
}
3029

3130
/// <summary>
@@ -45,14 +44,12 @@ private set
4544
this.testContext = value;
4645
}
4746
}
48-
49-
protected Action BuildComponentAction { get; set; }
50-
47+
5148
/// <inheritdoc />
5249
public IAndTestBuilder ShouldPassForThe<TComponent>(Action<TComponent> assertions)
5350
where TComponent : class
5451
{
55-
this.BuildComponentAction();
52+
this.TestContext.ComponentBuildDelegate?.Invoke();
5653

5754
assertions(TestHelper.TryGetShouldPassForValue<TComponent>(this.TestContext));
5855

@@ -63,7 +60,7 @@ public IAndTestBuilder ShouldPassForThe<TComponent>(Action<TComponent> assertion
6360
public IAndTestBuilder ShouldPassForThe<TComponent>(Func<TComponent, bool> predicate)
6461
where TComponent : class
6562
{
66-
this.BuildComponentAction();
63+
this.TestContext.ComponentBuildDelegate?.Invoke();
6764

6865
if (!predicate(TestHelper.TryGetShouldPassForValue<TComponent>(this.TestContext)))
6966
{

src/MyTested.AspNetCore.Mvc.Abstractions/Builders/Components/BaseComponentBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public abstract class BaseComponentBuilder<TBuilder> : BaseTestBuilderWithCompon
1010
public BaseComponentBuilder(ComponentTestContext testContext)
1111
: base(testContext)
1212
{
13-
this.BuildComponentAction += this.BuildComponentIfNotExists;
13+
this.TestContext.ComponentBuildDelegate += this.BuildComponentIfNotExists;
1414
}
1515

1616
protected abstract void BuildComponentIfNotExists();

src/MyTested.AspNetCore.Mvc.Abstractions/Internal/TestContexts/ComponentTestContext.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public object Component
2525
{
2626
if (this.component == null)
2727
{
28-
this.component = this.ComponentConstruction();
28+
this.component = this.ComponentConstructionDelegate();
2929
}
3030

3131
return this.component;
@@ -134,11 +134,13 @@ public object Model
134134
}
135135
}
136136

137-
public Func<object> ComponentConstruction { get; set; }
137+
public Func<object> ComponentConstructionDelegate { get; set; }
138+
139+
public Action ComponentBuildDelegate { get; set; }
138140

139-
public Action ComponentPreparationAction { get; set; }
141+
public Action ComponentPreparationDelegate { get; set; }
140142

141-
public Action PreMethodInvocationAction { get; set; }
143+
public Action PreMethodInvocationDelegate { get; set; }
142144

143145
public TComponent ComponentAs<TComponent>()
144146
where TComponent : class => this.Component as TComponent;

src/MyTested.AspNetCore.Mvc.Controllers/Builders/Actions/ShouldReturn/ShouldReturnEmpty.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public partial class ShouldReturnTestBuilder<TActionResult>
1212
public IBaseTestBuilderWithActionResult<TActionResult> Empty()
1313
{
1414
this.ValidateActionReturnType<EmptyResult>();
15-
return this.NewAndShouldPassForTestBuilder();
15+
return this.NewAndTestBuilderWithActionResult();
1616
}
1717
}
1818
}

src/MyTested.AspNetCore.Mvc.Controllers/Builders/Actions/ShouldReturn/ShouldReturnNoContent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public partial class ShouldReturnTestBuilder<TActionResult>
1212
public IBaseTestBuilderWithActionResult<TActionResult> NoContent()
1313
{
1414
this.ValidateActionReturnType<NoContentResult>();
15-
return this.NewAndShouldPassForTestBuilder();
15+
return this.NewAndTestBuilderWithActionResult();
1616
}
1717
}
1818
}

src/MyTested.AspNetCore.Mvc.Controllers/Builders/Actions/ShouldReturn/ShouldReturnNullOrDefault.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public IBaseTestBuilderWithActionResult<TActionResult> DefaultValue()
2121
typeof(TActionResult).ToFriendlyTypeName()));
2222
}
2323

24-
return this.NewAndShouldPassForTestBuilder();
24+
return this.NewAndTestBuilderWithActionResult();
2525
}
2626

2727
/// <inheritdoc />
@@ -35,7 +35,7 @@ public IBaseTestBuilderWithActionResult<TActionResult> Null()
3535
typeof(TActionResult).ToFriendlyTypeName()));
3636
}
3737

38-
return this.NewAndShouldPassForTestBuilder();
38+
return this.NewAndTestBuilderWithActionResult();
3939
}
4040

4141
/// <inheritdoc />
@@ -49,7 +49,7 @@ public IBaseTestBuilderWithActionResult<TActionResult> NotNull()
4949
typeof(TActionResult).ToFriendlyTypeName()));
5050
}
5151

52-
return this.NewAndShouldPassForTestBuilder();
52+
return this.NewAndTestBuilderWithActionResult();
5353
}
5454

5555
private bool CheckValidDefaultValue()

src/MyTested.AspNetCore.Mvc.Controllers/Builders/Actions/ShouldReturn/ShouldReturnUnauthorized.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public partial class ShouldReturnTestBuilder<TActionResult>
1212
public IBaseTestBuilderWithActionResult<TActionResult> Unauthorized()
1313
{
1414
this.ValidateActionReturnType<UnauthorizedResult>();
15-
return this.NewAndShouldPassForTestBuilder();
15+
return this.NewAndTestBuilderWithActionResult();
1616
}
1717
}
1818
}

src/MyTested.AspNetCore.Mvc.Controllers/Builders/Actions/ShouldReturn/ShouldReturnUnsupportedMediaType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public partial class ShouldReturnTestBuilder<TActionResult>
1212
public IBaseTestBuilderWithActionResult<TActionResult> UnsupportedMediaType()
1313
{
1414
this.ValidateActionReturnType<UnsupportedMediaTypeResult>();
15-
return this.NewAndShouldPassForTestBuilder();
15+
return this.NewAndTestBuilderWithActionResult();
1616
}
1717
}
1818
}

src/MyTested.AspNetCore.Mvc.Controllers/Builders/Actions/VoidActionResultTestBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public VoidActionResultTestBuilder(ControllerTestContext testContext)
2626
public IBaseTestBuilderWithInvokedAction ShouldReturnEmpty()
2727
{
2828
ActionValidator.CheckForException(this.CaughtException);
29-
return this.NewAndShouldPassForTestBuilder();
29+
return this.NewAndTestBuilderWithInvokedAction();
3030
}
3131

3232
/// <inheritdoc />
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
/// Provides additional testing methods.
88
/// </summary>
99
/// <typeparam name="TActionResult">Result from invoked action in ASP.NET Core MVC controller.</typeparam>
10-
public class AndShouldPassForTestBuilder<TActionResult> : BaseTestBuilderWithActionResult<TActionResult>
10+
public class AndTestBuilderWithActionResult<TActionResult> : BaseTestBuilderWithActionResult<TActionResult>
1111
{
1212
/// <summary>
13-
/// Initializes a new instance of the <see cref="AndShouldPassForTestBuilder{TActionResult}"/> class.
13+
/// Initializes a new instance of the <see cref="AndTestBuilderWithActionResult{TActionResult}"/> class.
1414
/// </summary>
1515
/// <param name="testContext"><see cref="ControllerTestContext"/> containing data about the currently executed assertion chain.</param>
16-
public AndShouldPassForTestBuilder(ControllerTestContext testContext)
16+
public AndTestBuilderWithActionResult(ControllerTestContext testContext)
1717
: base(testContext)
1818
{
1919
}

0 commit comments

Comments
 (0)