{ Car newCar = this.Bind(); newCar -6ren">
gpt4 book ai didi

unit-testing - 使用 Nancy.Testing.Browser 发布时发生 ConfigurableBootstrapper 错误

转载 作者:行者123 更新时间:2023-12-01 09:30:55 31 4
gpt4 key购买 nike

我有一个声明了 Post 的简单 NancyModule:

Post["/Car/New"] = args => 
{
Car newCar = this.Bind<Car>();
newCar = _carRepos.CreateNewCar(newCar);
return Response.AsJson<Car>(newCar);
};

从 View 发布到此效果很好:

<form action="/Car/New" method="post">
<input type="text" name="colour" />
<input type="submit" value="Submit" />
</form>

当我尝试对此路线进行测试时,我收到以下错误:

System.Exception : ConfigurableBootstrapper Exception
----> Nancy.RequestExecutionException : Oh noes!
----> System.MissingMethodException : Method not found: '!!0 Nancy.ModelBinding.ModuleExtensions.Bind(Nancy.INancyModule, System.String[])'.
Result StackTrace:
at Nancy.Testing.PassThroughStatusCodeHandler.Handle(HttpStatusCode statusCode, NancyContext context)
at Nancy.NancyEngine.CheckStatusCodeHandler(NancyContext context)
at Nancy.NancyEngine.HandleRequest(Request request, Func`2 preRequest)
at Nancy.NancyEngine.HandleRequest(Request request)
at Nancy.Testing.Browser.HandleRequest(String method, String path, Action`1 browserContext)
at Nancy.Testing.Browser.Post(String path, Action`1 browserContext)
at Shopr.Tests.Cars.CarTests.PostNewCarReturnsCar() in c:\Users\*******\Documents\Visual Studio 2012\Projects\Shopr\Shopr.Tests\Cars\CarTests.cs:line 35
--RequestExecutionException
at Nancy.NancyEngine.InvokeOnErrorHook(NancyContext context, ErrorPipeline pipeline, Exception ex)
--MissingMethodException
at Shopr.Api.Modules.CarsModule.<.ctor>b__3(Object args)
at Nancy.Routing.Route.Invoke(DynamicDictionary parameters)
at Nancy.Routing.DefaultRouteInvoker.Invoke(Route route, DynamicDictionary parameters, NancyContext context)
at Nancy.Routing.DefaultRequestDispatcher.Dispatch(NancyContext context)
at Nancy.NancyEngine.InvokeRequestLifeCycle(NancyContext context, IPipelines pipelines)

这是我的测试:

[Test]
public void PostNewCarReturnsCar()
{
var browser = BrowserFactory.Create();
var response = browser.Post("/Car/New", with =>
{
with.FormValue("Colour", "Red");
});

var car = GetObjectFromJsonBody(response.Body.AsString());

Assert.IsNotNull(car);
Assert.AreEqual(2, car.Id);
}

这是我的测试 Bootstrap :

public class NancyBootstrapper : ConfigurableBootstrapper
{
public NancyBootstrapper()
: base(with => { with.Module<CarsModule>(); })
{ }

protected override void ConfigureApplicationContainer(TinyIoCContainer container)
{
container.Register<ICarRepository>(new FakeData.CarRepository());
}
}

我是否必须在我的 ConfigurableBootstrapper 中执行任何特殊操作才能使绑定(bind)起作用?

最佳答案

仔细检查您的 packages.config 是否提取了正确的版本。

更新:因为这主要来自@StevenRobbins,所以我表扬他:

enter image description here

关于unit-testing - 使用 Nancy.Testing.Browser 发布时发生 ConfigurableBootstrapper 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15342196/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com