Skip to content

Commit e1ea87c

Browse files
committed
Added more unit tests to ViewComponentBuilder.
1 parent a8ca467 commit e1ea87c

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

test/MyTested.AspNetCore.Mvc.ViewComponents.Test/BuildersTests/ViewComponentsTests/ViewComponentBuilderTests.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
namespace MyTested.AspNetCore.Mvc.Test.BuildersTests.ViewComponentsTests
22
{
3+
using System;
4+
using System.Reflection;
35
using Builders.Base;
46
using Builders.Contracts.Base;
57
using Builders.Contracts.Invocations;
@@ -11,8 +13,6 @@
1113
using Setups;
1214
using Setups.Models;
1315
using Setups.ViewComponents;
14-
using System;
15-
using System.Reflection;
1616
using Xunit;
1717

1818
public class ViewComponentBuilderTests
@@ -102,7 +102,7 @@ public void InvokedWithShouldPopulateCorrectActionDescriptor()
102102
Assert.Equal("Invoke", viewComponent.ViewComponentContext.ViewComponentDescriptor.MethodInfo.Name);
103103
});
104104
}
105-
105+
106106
[Fact]
107107
public void UnresolvedRouteValuesShouldHaveFriendlyException()
108108
{
@@ -293,6 +293,24 @@ public void NonViewComponentShouldThrowException()
293293
"NonViewComponent is not recognized as a valid view component type. Classes decorated with 'NonViewComponentAttribute' are not considered as passable view components. Additionally, make sure the SDK is set to 'Microsoft.NET.Sdk.Web' in your test project's '.csproj' file in order to enable proper view component discovery. If your type is still not recognized, you may manually add it in the application part manager by using the 'AddMvc().PartManager.ApplicationParts.Add(applicationPart))' method.");
294294
}
295295

296+
[Fact]
297+
public void AndAlsoShouldWorkCorrectly()
298+
{
299+
MyViewComponent<NormalComponent>
300+
.Instance()
301+
.WithViewComponentContext(viewComponentContext =>
302+
{
303+
viewComponentContext.ViewContext.RouteData.Values.Add("testkey", "testvalue");
304+
})
305+
.AndAlso()
306+
.ShouldPassForThe<NormalComponent>(viewComponent =>
307+
{
308+
Assert.NotNull(viewComponent);
309+
Assert.NotNull(viewComponent.ViewComponentContext);
310+
Assert.True(viewComponent.ViewComponentContext.ViewContext.RouteData.Values.ContainsKey("testkey"));
311+
});
312+
}
313+
296314
private void CheckViewComponentResultTestBuilder<TInvocationResult>(
297315
IViewComponentResultTestBuilder<TInvocationResult> testBuilder,
298316
string expectedActionName)

0 commit comments

Comments
 (0)