我想编写用于在ASP.NET Core 1中上传文件的测试,但似乎找不到一种模拟/实例化从IFormFile派生的对象的好方法.有关如何做到这一点的任何建议?
谢谢.
我正在构建一个web api,我有一个资源,必须有3个get方法,如下所示:
[HttpGet]
[Route("{city}/{streetName}/{streetNumber}/{littera}")]
public IActionResult GetByAddress([FromQuery]string city, [FromQuery]string streetName, [FromQuery]int streetNumber, [FromQuery]string littera)
{
var model = _availabilityService.FindByAddress(city, streetName, streetNumber, littera);
return Ok(model);
}
[HttpGet("{pointId}")]
public IActionResult GetByPointId(string pointId)
{
var model = _availabilityService.FindByPointId(pointId);
return Ok(model);
}
[HttpGet]
[Route("{xCoordinate}/{yCoordinate}")]
public IActionResult GetByCoordinates([FromQuery]decimal xCoordinate, [FromQuery]decimal yCoordinate)
{
var model = _availabilityService.FindByCoordinates(xCoordinate, yCoordinate);
return Ok(model);
}
Run Code Online (Sandbox Code Playgroud)
只有一个参数(pointId)的get方法工作正常,因为它不被视为查询字符串,而是id和id.然而,似乎剩下的两种方法无法通过ASP.NET中的路由器区分.
我在这里真的很茫然,无法弄清楚它为什么不起作用.我能够解决的是,如果我删除其中一种方法,另一种方法可以正常工作.
关于我做错的任何建议?
仅供参考,相应的网址:应该如下所示:
api/1.0/availabilities?city=Metropolis&streetName=Superstreet&streetNumber=1&littera=A
Run Code Online (Sandbox Code Playgroud)
和
/api/1.0/availabilities?xCoordinate=34.3444&yCoordinate=66.3422
Run Code Online (Sandbox Code Playgroud)
谢谢!
我正在使用SoapCore使用asp.net core 2创建WCF类的应用程序。
这样做对我来说很好,但是在集成测试端点时遇到了一些障碍。
由于SoapCore是中间件,并且与任何api控制器都没有关系,因此我无法使用HttpClient来测试端点,因此TestServer对我没有用。
我的问题是在不使用TestServer的情况下如何与我的集成测试并行运行kestrel,或者在这种情况下是否可以利用TestServer?
我认为这里的任何代码都没有用,但是到目前为止,我得到的是以下内容。
启动文件
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<IPaymentService>(service => new Services.PaymentService());
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseSoapEndpoint<IPaymentService>("/PaymentService.svc", new BasicHttpBinding());
app.UseMvc();
}
}
Run Code Online (Sandbox Code Playgroud)
PaymentService
[ServiceContract]
public interface IPaymentService
{
[OperationContract]
string ReadPaymentFiles(string caller);
}
public class PaymentService : IPaymentService
{
public string ReadPaymentFiles(string caller)
{
return caller;
} …Run Code Online (Sandbox Code Playgroud) c# testing kestrel-http-server asp.net-core asp.net-core-2.0