我正在尝试使用WebSocket API上传大文件(至少500MB,最好是几GB).问题是我无法弄清楚如何编写"发送此文件的片段,释放使用的资源然后重复".我希望我可以避免使用像Flash/Silverlight这样的东西.
目前,我正在开展以下工作:
function FileSlicer(file) {
// randomly picked 1MB slices,
// I don't think this size is important for this experiment
this.sliceSize = 1024*1024;
this.slices = Math.ceil(file.size / this.sliceSize);
this.currentSlice = 0;
this.getNextSlice = function() {
var start = this.currentSlice * this.sliceSize;
var end = Math.min((this.currentSlice+1) * this.sliceSize, file.size);
++this.currentSlice;
return file.slice(start, end);
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我会上传使用:
function Uploader(url, file) {
var fs = new FileSlicer(file);
var socket = new WebSocket(url);
socket.onopen = function() {
for(var i = 0; i …Run Code Online (Sandbox Code Playgroud) 我试图首先使用EntityFramework代码测试我的代码.为了使其可测试并允许隔离测试,我创建了一个我DbContext实现的接口.我没有测试DbContext类 - 我将假设EF代码按预期工作.
现在,请考虑以下方法:
public IEnumerable<User> GetOddId()
{
return context_.Users.Where((u, i) => i % 2 == 1).AsEnumerable();
}
Run Code Online (Sandbox Code Playgroud)
这个方法将通过我的mock传递FakeDbSet(因为它将使用内存中的LINQ提供程序),而在使用EF/LINQ to SQL驱动程序时它会因异常而失败.
你会不会留下它并希望人们知道不要写这样的问题?你会放弃隔离测试并测试实际的数据库吗?
具有DataMigrations的LocalDb(可能带有适当的种子)是否有助于对实际数据库进行测试?
请证明答案是正确的.
TLDR:如何测试EntityFramework代码,考虑内存LINQ和SQL LINQ之间的差异?
很久以后编辑:我发现了一个非常好的框架,完全符合我的需要.我写了一篇关于使用Effort进行单元测试的博客文章.另请注意,即将推出的EF6可能不需要这一切,它承诺了一些单元测试功能.