【问题标题】:Mocking IUserStore against asp.net identity inside asp.net mvc5在 asp.net mvc5 中针对 asp.net 身份模拟 IUserStore
【发布时间】: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


    【解决方案1】:

    我认为您缺少对 Microsoft.AspNet.Identity.EntityFramework 的引用。

    安装这个 nuget 包。 http://www.nuget.org/packages/Microsoft.AspNet.Identity.EntityFramework/。为我修好了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-13
      • 2012-02-25
      相关资源
      最近更新 更多