Skip to content

Commit 3a26460

Browse files
committed
Added unit test for ViewComponentDescriptorCache.
1 parent e1ea87c commit 3a26460

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/MyTested.AspNetCore.Mvc.ViewComponents.Test/ServicesTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.AspNetCore.Mvc.ViewComponents;
1212
using Microsoft.AspNetCore.Mvc.ViewFeatures;
1313
using Microsoft.Extensions.DependencyInjection;
14+
using MyTested.AspNetCore.Mvc.Internal.Contracts;
1415
using Setups;
1516
using Setups.Services;
1617
using Setups.ViewComponents;
@@ -550,5 +551,23 @@ public void WithViewContextFuncShouldSetItToAccessor()
550551

551552
MyApplication.StartsFrom<DefaultStartup>();
552553
}
554+
555+
[Fact]
556+
public void ViewComponentDescriptorCacheShouldWorkCorrectlyAndReturnDescriptor()
557+
{
558+
MyApplication.StartsFrom<DefaultStartup>();
559+
560+
MyViewComponent<NormalComponent>
561+
.InvokedWith(c => c.Invoke())
562+
.ShouldPassForThe<NormalComponent>(vc =>
563+
{
564+
var cache = vc.HttpContext.RequestServices.GetService<IViewComponentDescriptorCache>();
565+
var viewComponentDescriptor = cache.GetViewComponentDescriptor(vc.GetType().GetMethod("Invoke"));
566+
567+
Assert.True(viewComponentDescriptor.GetType() == typeof(ViewComponentDescriptor));
568+
});
569+
570+
MyApplication.StartsFrom<DefaultStartup>();
571+
}
553572
}
554573
}

0 commit comments

Comments
 (0)