在传递给委托的方法中调用方法本身时,如何验证是否在模拟上调用了方法Task.Run?按时间mock.Verify调用任务仍然没有执行.
我之前尝试过await Task.Delay,mock.Verify但这似乎让测试跑者不知所措.
使用的原因Task.Run是卸载逻辑以防止攻击者在执行时能够区分系统中是否存在电子邮件地址.
using System.Threading.Tasks;
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace AsyncTesting
{
class MyController : Controller
{
public IEmailService EmailService { get; set; }
public MyController(IEmailService emailService)
{
EmailService = emailService;
}
public ViewResult BeginPasswordReset(string emailAddress)
{
BeginPasswordResetAsync(emailAddress);
return View();
}
private Task BeginPasswordResetAsync(string emailAddress)
{
return Task.Run(delegate
{
EmailService.Send(emailAddress);
});
}
}
internal interface IEmailService
{
void Send(string emailAddress);
}
internal class MyControllerTests
{
[TestMethod]
public …Run Code Online (Sandbox Code Playgroud) 如果Application_Error由应用程序启动中的异常触发,RouteConfig或者BundleConfig如何检查Request/ Response是否可用?目前有关附加信息的Response.Clear投掷.System.Web.HttpExceptionResponse is not available in this context
void Application_Error(object sender, EventArgs e)
{
//Log error
Log.Error(e);
//Clear
Response.Clear();
Server.ClearError();
//Redirect
Response.Redirect("~/Error");
}
Run Code Online (Sandbox Code Playgroud)
其他问题建议重写不使用Response或使用HttpContext.Current.Response或更改IIS配置.
综上所述; 如何判断应用程序启动过程中是否出现错误?
我不知道角度发生了什么,它没有捕捉到错误的反应,我在这里看到的问题没有答案.
我有一个简单的http请求,我得到400响应,我想在用户发生时向用户显示一条消息,问题是200的部分被执行了.
我试过两种方式:
this.forgatPassword = function(data) {
return $http.post('http://someaddress/ForgotPassword', data);
}
$scope.forgatPassword = function() {
AuthService.forgatPassword($scope.user).then(function(res) {
$scope.message = true;
}, function(error) {
console.log('rejected');
});
}
$scope.forgatPassword = function() {
AuthService.forgatPassword($scope.user).then(function(res) {
$scope.message = true;
}).catch( function(error) {
console.log('rejected');
});
}
Run Code Online (Sandbox Code Playgroud)