我有一个集成测试LoadFile_DataLoaded_Successfully().我想将它重构为单元测试以破坏与filesytem的依赖关系.
PS我是TDD的新手:
这是我的生产类:
public class LocalizationData
{
private bool IsValidFileName(string fileName)
{
if (fileName.ToLower().EndsWith("xml"))
{
return true;
}
return false;
}
public XmlDataProvider LoadFile(string fileName)
{
if (IsValidFileName(fileName))
{
XmlDataProvider provider =
new XmlDataProvider
{
IsAsynchronous = false,
Source = new Uri(fileName, UriKind.Absolute)
};
return provider;
}
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
和我的考试班(Nunit)
[TestFixture]
class LocalizationDataTest
{
[Test]
public void LoadFile_DataLoaded_Successfully()
{
var data = new LocalizationData();
string fileName = "d:/azeri.xml";
XmlDataProvider result = data.LoadFile(fileName);
Assert.IsNotNull(result);
Assert.That(result.Document, Is.Not.Null);
} …Run Code Online (Sandbox Code Playgroud) 我需要一个转换页面,在自动重定向到主页之前显示2秒钟.我该怎么做呢?我似乎无法延迟为我工作.
hPipe = CreateFile(
lpszPipename, // pipe name
GENERIC_READ | // read and write access
GENERIC_WRITE,
0, // no sharing
NULL, // default security attributes
OPEN_EXISTING, // opens existing pipe
0, // default attributes
NULL); // no template file
Run Code Online (Sandbox Code Playgroud)
如何将上述ATL方法转换为方式,以便在销毁COM组件时自动关闭管道?
如果我有以下......
a OrElse b
Run Code Online (Sandbox Code Playgroud)
......并且a是真,那么显然b永远不会被评估.但是,如果我添加一个Or,那么呢?
a OrElse b Or c
Run Code Online (Sandbox Code Playgroud)
是否应该评估?如果我放入一些括号怎么办?
如果这是基本的,请道歉.当然我可以自己测试答案,但我无法在这里或其他地方找到这个问题的答案.的处理问题,很多还是与 OrElse运算,但没有处理或者与 OrElse运算
这是关于nginx和rails环境中的瘦身的新手问题.在轨道上阅读/学习时,我经常听说nginx和thin是一个很好的组合,适用于rails网站.在阅读每个描述时,他们都将自己描述为Web服务器,因此我对组合带来的内容感到困惑.如果有人可以简要描述它们是什么以及它们如何相互补充,我将非常感激.
谢谢!
我的代码在FF/Chrome/Everything中工作正常,除了IE(7/8都失败了,没有打算继续下去).由于限制,我不能使用jQuery并且硬编码Javascript.问题出在IE上,我得到"preventDefault为null或者不是对象".希望你们中的一个有答案,这里有相关的代码:
AddEvent方法:
function addEvent( obj, type, fn ) {
if ( obj.attachEvent ) {
obj['e'+type+fn] = fn;
obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
obj.attachEvent( 'on'+type, obj[type+fn] );
} else
obj.addEventListener( type, fn, false );
};
Run Code Online (Sandbox Code Playgroud)
事件处理程序抛出错误
function mousedown(e){
if(e.preventDefault){
e.preventDefault();
} else {
e.returnValue = false;
e.cancelBubble=true;
}
//Processing
};
Run Code Online (Sandbox Code Playgroud)
DOCTYPE和charset也都在调用HTML页面上设置.任何想法,将不胜感激.mousedown方法的if语句中抛出错误.
编辑:
由于抓取window.event确实"修复"了主要问题,我发现问题是代码的不同部分.基本上我在预先放置的元素的ontop上添加一个元素,然后将mousedown/mousemove事件注册到该div.在事件上触发事件时<div>,抛出错误的地方.
这可能是因为我将事件注册到2
rect = document.createElement('div');
rect.className='square';
rect.id='chooser_rectangle';
rect.style.left=initx+'px';
rect.style.top=inity+'px';
addEvent(rect,"mousemove",mousemove);
addEvent(rect,"mousedown",mousedown);
Run Code Online (Sandbox Code Playgroud) 在我看来,我想以"mm/dd/yyyy"格式显示当前日期.
我有一种情况,我想依赖注入我的用户对象,但也将当前用户放在IoC容器中.我想要以下几行:
kernel.Get<User>(); // Should return a new User()
kernel.Get<User>("Current"); // Should return the current user
Run Code Online (Sandbox Code Playgroud)
有人可能认为像这样的绑定会起作用:
Bind<User>().ToSelf();
Bind<User>().ToMethod(LoadCurrentUser).InRequestScope().Named("Current");
Run Code Online (Sandbox Code Playgroud)
当然,这给了:
Ninject.ActivationException: Error activating User More than one matching bindings are available. Activation path: 1) Request for User Suggestions: 1) Ensure that you have defined a binding for User only once.
我理解错误,因为命名绑定不限制该绑定的应用程序,因此两个绑定都适用.很明显,我需要使用.When*()方法的上下文绑定,但我无法想出任何方法来做到这一点.我觉得应该有什么方法可以检测是否应用了命名实例.就像是:
// Not valid Ninject syntax
Bind<User>().ToSelf().WhenUnnamedRequested();
Bind<User>().ToMethod(LoadCurrentUser).WhenNamedRequested().InRequestScope().Named("Current");
Run Code Online (Sandbox Code Playgroud)
我找不到IRequest界面上的任何地方或它的属性告诉我要求的名称.我该怎么做呢?
我正在寻找一种方法,我可以从输入字段中提取每个单词的第一个字母,并将其放入变量中.
示例:如果输入字段是"Stack-Overflow Questions Tags Users"变量的输出应该是类似的"SOQTU"
如何运行Windows批处理文件但隐藏命令窗口?我不希望cmd.exe在执行文件时在屏幕上可见.这可能吗?