ASP.NET模拟失败的SignInResult返回了Null。
创始人
2024-09-19 02:00:14
0

这个问题可能是由于在模拟SignInResult时没有正确设置返回对象而导致的。下面是一些示例代码,展示了如何使用Microsoft.AspNetCore.Authentication.Abstractions命名空间中的不同方法来成功模拟SignInResult并正确处理它的返回值。

使用设置Succeeded属性的AuthenticationTicket对象:

// create a mock authentication ticket object
var ticket = new AuthenticationTicket(new ClaimsPrincipal(), new AuthenticationProperties(), "mockScheme");

// create a mock SignInResult with the ticket object
var result = SignInResult.Success(ticket);

// assert that the result is not null
Assert.NotNull(result);

使用创建成功的AuthenticationProperties对象:

// create a mock AuthenticationProperties object with an IsPersistent value of false
var props = new AuthenticationProperties { IsPersistent = false };

// create a mock SignInResult with the AuthenticationProperties object
var result = SignInResult.Success(props);

// assert that the result is not null
Assert.NotNull(result);

使用创建成功的ClaimsPrincipal对象:

// create a mock ClaimsPrincipal object
var principal = new ClaimsPrincipal();

// create a mock SignInResult with the ClaimsPrincipal object
var result = SignInResult.Success(principal);

// assert that the result is not null
Assert.NotNull(result);

这些示例代码应该能够帮助你成功模拟SignInResult并正确处理它的返回值。

相关内容

热门资讯

透视辅助!新道游开挂辅助透视,... 新道游开挂辅助透视 无需打开直接搜索微信:136704302本司针对手游进行,选择我们的四大理由: ...
指导大家"朱雀开心罗... 指导大家"朱雀开心罗松辅助器"开挂(透视)辅助软件(其实确实有挂)-哔哩哔哩;亲真的是有正版授权,小...
透视玄学!518互游辅助器下载... 518互游辅助器下载是一款专注玩家量身打造的游戏记牌类型软件,在518互游辅助器下载这款游戏中我们可...
一分钟秒懂"陕西三代... 【福星临门,好运相随】;一分钟秒懂"陕西三代辅助器"开挂(透视)辅助平台(一贯确实是有挂的)-哔哩哔...
透视美元局!透视软件app,哈... 透视美元局!透视软件app,哈糖大菠萝挂法,透牌教程(有人有挂)-哔哩哔哩 【无需打开直接搜索加薇1...
一分钟教会你"山西扣... 一分钟教会你"山西扣点免费辅助"开挂(透视)辅助安装(其实是有挂)-哔哩哔哩;详细山西扣点免费辅助攻...
玩家攻略推荐"福建兄... 玩家攻略推荐"福建兄弟十三水辅助器下载"开挂(透视)辅助下载(果然确实是有挂的)-哔哩哔哩;福建兄弟...
信息共享!四川家园游戏辅助软件... 信息共享!四川家园游戏辅助软件,创思维激k辅助器,解说技巧(新版有挂)-哔哩哔哩;亲,四川家园游戏辅...
分享给玩家"欢乐对决... 分享给玩家"欢乐对决辅助软件"开挂(透视)辅助插件(一直是有挂)-哔哩哔哩;最新版2026是一款经典...
发现玩家!九酷众娱辅助,aa ... 发现玩家!九酷众娱辅助,aa poker透视软件,科技教程(果真有挂)-哔哩哔哩;打开点击测试直接进...