私はいくつかの私のWebサービスをテストしようとしています。このために、私はHttpResponseMessage
のいくつかを主張したいと思います。このために、私がやっている:失敗したとしてユニットテストHttpResponseMessage
public IHttpActionResult Login(String userName, String userPassword)
{
try
{
if (userName == null)
return NotFound();
//Logging in user etc.
return Ok();
}
catch
{
return NotFound();
}
}
しかし、テストは常にLogin()
戻っOk()
は、私がデバッグするときにもかかわらず、返す:Login
はメソッドのようなものです
[TestMethod()]
public void LoginTest()
{
HttpResponseMessage response = Request.CreateResponse(_accountController.Login("testuser", "testpw")); //CODE STOPS RUNNING AT THIS LINE
Assert.IsTrue(response.IsSuccessStatusCode, "User unable to log in with correct login info");
}
を。私はテストをデバッグするときに見かけ上のエラーまたは例外んが、しかし、出力は(私はちょうどLoaded
またはUnloaded
だかを示すラインを除外している)のようなものを示しています
The thread 0x1190 has exited with code 0 (0x0).
Exception thrown: 'System.InvalidOperationException' in System.ServiceModel.dll
Exception thrown: 'System.ArgumentNullException' in System.Web.Http.dll
Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll
Exception thrown: 'Microsoft.VisualStudio.TestPlatform.MSTestFramework.TestFailedException' in Microsoft.VisualStudio.TestPlatform.Extensions.VSTestIntegration.dll
Exception thrown: 'Microsoft.VisualStudio.TestPlatform.MSTestFramework.TestFailedException' in Microsoft.VisualStudio.TestPlatform.Extensions.VSTestIntegration.dll
The thread 0xaec has exited with code 0 (0x0).
Exception thrown: 'System.InvalidOperationException' in Microsoft.VisualStudio.TestPlatform.TestExecutor.Core.dll
Exception thrown: 'System.ServiceModel.CommunicationObjectAbortedException' in System.ServiceModel.dll
Exception thrown: 'System.ServiceModel.CommunicationObjectAbortedException' in System.ServiceModel.dll
Exception thrown: 'System.ServiceModel.CommunicationObjectAbortedException' in System.ServiceModel.Internals.dll
Exception thrown: 'System.IO.IOException' in System.dll
Exception thrown: 'System.ServiceModel.CommunicationObjectAbortedException' in System.ServiceModel.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.VisualStudio.TestPlatform.TestExecutor.Core.dll
Exception thrown: 'System.ServiceModel.CommunicationObjectAbortedException' in System.ServiceModel.dll
The program '[9936] vstest.executionengine.x86.exe' has exited with code 0 (0x0).
The program '[4084] TanulmanyiRendszer.Admin.vshost.exe' has exited with code -1 (0xffffffff).
私の推測では、これが方法ではありませんということですIHttpActionResult
をHttpResponseMessage
に変換する必要があります。この問題を解決するにはどうすればよいですか?