我正在尝试从帐户控制器对我的mvc5 app注册操作进行单元测试。在我的单元测试中,我尝试模拟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
答案 0 :(得分:0)
我认为您缺少对Microsoft.AspNet.Identity.EntityFramework的引用。
安装此nuget包。 http://www.nuget.org/packages/Microsoft.AspNet.Identity.EntityFramework/。为我修好了。