我有一个关于我正在使用Visual Studio项目中的Resharper从我正在工作的警告的快速提问.警告是:
"不使用纯方法的返回值"
发生这种情况的方法如下:
private static bool FilePathHasInvalidChars(string userInputPath)
{
try
{
//this is where the warning occurs:
Path.GetFullPath(userInputPath);
}
catch (Exception e)
{
Log.Error(String.Format(
"The Program failed to run due to invalid characters or empty " +
"string value for the Input Directory. " +
"Full Path : <{0}>. Error Message : {1}.",
userInputPath, e.Message), e);
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
我想我知道为什么警告正在发生.我Path.GetFullPath(path)仅用于捕获与无效字符有关的所有异常.该路径将由用户提供输入,因此我实际上并未使用该结果Path.GetFullPath(userInputPath).我唯一的用途就是检查我对此方法的检查是在主方法上进行的检查,以确保提供的路径不为空或没有任何无效字符.
我使用上述方法的地方如下:
if (FilePathHasInvalidChars(inputDirectory))
{
return;
}
Run Code Online (Sandbox Code Playgroud)
基本上它只是程序开始使用无效参数执行之前的退出点.
我想知道这个警告是否会引起任何问题,或者我是否会Path.GetFullPath以某种方式滥用该方法会导致我将来出现问题?
I want to use the commons.apache.maths classes for my own project but I don't know how to correctly import them into eclipse. I have visited the download page for the package mentioned above http://commons.apache.org/math/download_math.cgi but I don't know if the jar file which i want to import is on the binaries zip files or the source zip files. I tried the binaries ones first and when I do the import i just get a list of empty packages. Could somebody …
我是第一次尝试NUnit,单元测试和集成测试.我一直在阅读和做很多在线课程.因为我相信你非常清楚这是理解理论并在实践中做到的事情.
我被困在一个特定的测试上.我的应用程序是在C#.Net 3.5中.
我试图断言具有某个错误输入的方法将抛出特定异常.当我使用给测试的相同输入运行方法时,抛出预期的异常.
被测试的方法是:
private static bool FilePathHasInvalidChars(string userInputPath)
{
try
{
Path.GetFullPath(userInputPath);//this is where the warning appears
}
catch (Exception e)
{
Log.Error(String.Format(
"The Program failed to run due to invalid characters or empty string value for the Input Directory. Full Path : <{0}>. Error Message : {1}.",
userInputPath, e.Message), e);
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
我想检查上面的代码是否可以捕获异常,如果提供的输入目录不符合条件.
我目前的单元测试是:
[Test]
public void can_throws_exception_for_empty_string()
{
var testDirectory = "";
var sut = new DirectoryInfoValidator();
Assert.Throws<ArgumentNullException>(() => sut.FilePathHasInvalidChars(testDirectory));
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是测试总是失败,如果我检查返回它说明它期望一个ArgumentNull异常但是为null.我从测试中截取了输出的截图: …
c# integration-testing nunit unit-testing exception-handling