【发布时间】:2014-07-18 15:47:43
【问题描述】:
我正在尝试从帐户控制器对我的 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
【问题讨论】:
标签: c# asp.net-mvc unit-testing testing mocking