Skip to content

Commit f6979c3

Browse files
committed
Added unit tests for the ComponentTestContextViewDataExtensions.
1 parent 3016d34 commit f6979c3

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
namespace MyTested.AspNetCore.Mvc.Test.InternalTests
2+
{
3+
using Microsoft.AspNetCore.Http;
4+
using Microsoft.Extensions.DependencyInjection.Extensions;
5+
using Setups;
6+
using Setups.Controllers;
7+
using Setups.ViewComponents;
8+
using System;
9+
using Xunit;
10+
11+
public class ComponentTestContextViewDataExtensionsTests
12+
{
13+
[Fact]
14+
public void GetViewDataShouldThrowInvalidOperationExceptionWithPocoViewComponent()
15+
{
16+
Test.AssertException<InvalidOperationException>(
17+
() =>
18+
{
19+
MyViewComponent<PocoViewComponent>
20+
.Instance()
21+
.InvokedWith(c => c.Invoke())
22+
.ShouldHave()
23+
.NoViewData()
24+
.AndAlso()
25+
.ShouldReturn()
26+
.View();
27+
}, "ViewDataDictionary could not be found on the provided PocoViewComponent. The property should be specified manually by providing component instance or using the specified helper methods.");
28+
}
29+
30+
[Fact]
31+
public void GetViewDataShouldHaveNoViewDataForPocoController()
32+
{
33+
MyApplication
34+
.StartsFrom<DefaultStartup>()
35+
.WithServices(services =>
36+
{
37+
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
38+
});
39+
40+
MyController<FullPocoController>
41+
.Instance()
42+
.Calling(c => c.OkResultAction())
43+
.ShouldHave()
44+
.NoViewData()
45+
.AndAlso()
46+
.ShouldReturn()
47+
.Ok();
48+
49+
MyApplication.StartsFrom<DefaultStartup>();
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)