在asp.net mvc5中对asp.net身份嘲弄IUserStore
本文关键字:asp net 嘲弄 IUserStore 身份 mvc5 中对 | 更新日期: 2023-09-27 18:13:26
我正试图从帐户控制器单元测试我的mvc5应用程序注册操作。在我的单元测试中,我试图模拟IUserStore,但我有一些有线铸造问题。
//inside unit FileName = testegisterationSpecs.cs
var store = new Mock<IUserStore<ApplicationUser>>(MockBehavior.Strict);
我的ApplicationUser模型如下,您可以看到继承链。public class ApplicationUser : IdentityUser
{
//[Required]
public string FirstName { get; set; }
//[Required]
public string LastName { get; set; }
//[Required]
public string Email { get; set; }
}
public class IdentityUser : IUser
{
public IdentityUser();
public IdentityUser(string userName);
public virtual ICollection<IdentityUserClaim> Claims { get; }
public virtual string Id { get; set; }
public virtual ICollection<IdentityUserLogin> Logins { get; }
public virtual string PasswordHash { get; set; }
public virtual ICollection<IdentityUserRole> Roles { get; }
public virtual string SecurityStamp { get; set; }
public virtual string UserName { get; set; }
}
下面是我得到的错误。
The type 'JumpStartPakistan.Web.Models.ApplicationUser' cannot be used as type parameter 'TUser' in the generic type or method 'Microsoft.AspNet.Identity.IUserStore<TUser>'. There is no implicit reference conversion from 'JumpStartPakistan.Web.Models.ApplicationUser' to 'Microsoft.AspNet.Identity.IUser<string>'. E:'Projects'AspNet'MVC'JumpStartPakistanReboot'JumpStartPakistan'JumpStartPakistan.Tests'Web'Registration'RegisterationSpecs.cs
我想你错过了对Microsoft.AspNet.Identity.EntityFramework的引用。
安装这个nuget包。http://www.nuget.org/packages/Microsoft.AspNet.Identity.EntityFramework/。