我正在尝试将测试移植到NUnit3并且收到System.ArgumentException:不支持'async void'方法,请改为使用'async Task'.
[Test]
public void InvalidUsername()
{
...
var exception = Assert.Throws<HttpResponseException>(async () => await client.LoginAsync("notarealuser@example.com", testpassword));
exception.HttpResponseMessage.StatusCode.ShouldEqual(HttpStatusCode.BadRequest); // according to http://tools.ietf.org/html/rfc6749#section-5.2
...
}
Run Code Online (Sandbox Code Playgroud)
Assert.Throws似乎采用TestDelegate,定义为:
public delegate void TestDelegate();
Run Code Online (Sandbox Code Playgroud)
因此ArgumentException.移植此代码的最佳方法是什么?
我正在从IIS WebAPI迁移到OwinHost.利用nuget软件包的最新预发布版本,我在这里成功使用了说明:
https://github.com/ninject/Ninject.Web.Common/wiki/Setting-up-a-OWIN-WebApi-application
这是我的代码的存根:
public void Configuration(IAppBuilder app)
{
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
app.UseNinjectMiddleware(CreateKernel);
app.UseNinjectWebApi(config);
}
private static StandardKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Load(Assembly.GetExecutingAssembly());
RegisterServices(kernel);
return kernel;
}
private static void RegisterServices(IKernel kernel)
{
...
}
Run Code Online (Sandbox Code Playgroud)
但是在我的代码和文档示例中,Ninject内核直到启动后才会创建.但是,在Cors和OAuth中间件注册的启动注册过程中,我需要Ninject DI.在迁移到OwinHost之前,我可以这样做:
public void Configuration(IAppBuilder app)
{
_bootstrapper = new Bootstrapper();
_bootstrapper.Initialize(CreateKernel);
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
// USE _boostrapper.Kernel here
app.UseNinjectMiddleware(CreateKernel);
app.UseNinjectWebApi(config);
}
Run Code Online (Sandbox Code Playgroud)
但在内部,OwinBootstrapper.Execute将最终调用CreateKernel和bootstrapper.Initialize第二次,结果不好.
在Startup中创建和使用ninject内核并仍然注册Ninject/WebAPI中间件的正确方法是什么?
问题: 是否存在Windows API调用(可能仅限NTFS),它允许用户将非常大的文件拆分为许多其他文件而不实际复制任何数据(换句话说,指定连接文件之间的逻辑断点,文件名和大小)?
示例: SetFileValidData,NtSetInformationFile
场景: 我需要以编程方式从非本地驱动器(包括网络,USB和DVD驱动器)分发/复制10GB文件.它由超过100,000个单独文件组成,中值大小约为16千字节,但加入了~2GB块.
但是,使用简单的FileStream api(64kb缓冲区)将文件从非本地驱动器上的块提取到本地硬盘驱动器上的单个文件似乎在我的机器上限制为大约4MB/s,而使用Explorer复制整个块时发生超过80MB/s!
复制整个块似乎是合乎逻辑的,但是给Windows足够的信息来逻辑地分割文件(理论上应该能够非常非常快地发生).
Vista安装不是这样做的吗?
通常,要使用构造函数注入注册一些配置值,我会这样做:
string setting = ConfigurationManager.AppSettings["SomeSetting"];
container.Register<IService>(new Service(setting));
Run Code Online (Sandbox Code Playgroud)
你如何完成类似的事情,以便将配置值传递给装饰器构造函数?
是创建一些可以注入装饰器的配置提供程序类的唯一方法吗?似乎 RegisterDecorator 应该有一个重载,允许根据需要手动更新类。
你如何转换Expression<Func<IBar, T>>为Expression<Func<Bar, T>>Bar实施IBar?
这个更通用的问题有答案:
将表达式<Func <T1,bool >>动态转换为Expression <Func <T2,bool>
这是这种情况下最好的方法吗?鉴于Bar实施IBar,有没有更简单的方法?
所以,鉴于这个人为的示例代码:
public class Foo<T>
{
private readonly List<T> _list = new List<T>();
public void Add(T item)
{
_list.Add(item);
}
public bool AnyFunc(Func<T, bool> predicate)
{
return _list.Any(predicate);
}
public bool AnyExpression(Expression<Func<T, bool>> expression)
{
return _list.AsQueryable().Any(expression);
}
}
public interface IBar
{
string Name { get; }
}
public class Bar : IBar
{
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这证明了这个问题:
public class Test() …Run Code Online (Sandbox Code Playgroud)