Я не уверен в шаблоне, но я пытаюсь создать такой тест: я хочу создать контроллер, но иметь зависимости, доступные как замороженные параметры для теста.
Тест заключается в следующем.
[Theory, AutoNSubstituteData]
public void TestService(
[Frozen] ITestService service,
TestController controller,
string value)
{
controller.Test(value);
service.Received().ProcessValue(Arg.Any<string>());
}
Я получаю эту ошибку при запуске теста.
System.InvalidOperationExceptionAn exception was thrown
while getting data for theory WebTest.Tests.Controllers.TestControllerRouteTests
.TestService:
System.Reflection.TargetInvocationException:
Exception has been thrown by the target of an invocation. ---> System.NotImplementedException: The method or operation is not implemented.
at System.Web.HttpContextBase.get_Items()
at System.Web.WebPages.DisplayModeProvider.SetDisplayMode(HttpContextBase context, IDisplayMode displayMode)
Я создал атрибут AutoNSubstituteData из этого Сообщение AutoNSubsituteData. Я попытался создать поддельный контекст, чтобы решить проблему.
/// <summary>
/// The auto n substitute data attribute.
/// </summary>
internal class AutoNSubstituteDataAttribute : AutoDataAttribute
{
/// <summary>
/// Initialises a new instance of the <see cref="AutoNSubstituteDataAttribute"/> class.
/// </summary>
internal AutoNSubstituteDataAttribute()
: base(new Fixture()
.Customize(new AutoNSubstituteCustomization())
.Customize(new HttpContextBaseCustomization()))
{
}
}
internal class HttpContextBaseCustomization : ICustomization
{
public void Customize(IFixture fixture)
{
fixture.Customize<ViewContext>(_ => _.OmitAutoProperties());
fixture.Customize<HttpContextBase>(_ => _.FromFactory(() => Substitute.For<HttpContextBase>()));
}
}