|
1 | 1 | namespace MyTested.AspNetCore.Mvc.Test.BuildersTests.ViewComponentsTests
|
2 | 2 | {
|
| 3 | + using System; |
| 4 | + using System.Reflection; |
3 | 5 | using Builders.Base;
|
4 | 6 | using Builders.Contracts.Base;
|
5 | 7 | using Builders.Contracts.Invocations;
|
|
11 | 13 | using Setups;
|
12 | 14 | using Setups.Models;
|
13 | 15 | using Setups.ViewComponents;
|
14 |
| - using System; |
15 |
| - using System.Reflection; |
16 | 16 | using Xunit;
|
17 | 17 |
|
18 | 18 | public class ViewComponentBuilderTests
|
@@ -102,7 +102,7 @@ public void InvokedWithShouldPopulateCorrectActionDescriptor()
|
102 | 102 | Assert.Equal("Invoke", viewComponent.ViewComponentContext.ViewComponentDescriptor.MethodInfo.Name);
|
103 | 103 | });
|
104 | 104 | }
|
105 |
| - |
| 105 | + |
106 | 106 | [Fact]
|
107 | 107 | public void UnresolvedRouteValuesShouldHaveFriendlyException()
|
108 | 108 | {
|
@@ -293,6 +293,24 @@ public void NonViewComponentShouldThrowException()
|
293 | 293 | "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.");
|
294 | 294 | }
|
295 | 295 |
|
| 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 | + |
296 | 314 | private void CheckViewComponentResultTestBuilder<TInvocationResult>(
|
297 | 315 | IViewComponentResultTestBuilder<TInvocationResult> testBuilder,
|
298 | 316 | string expectedActionName)
|
|
0 commit comments