Inside my tests, here is my code:
[SetUp]
public void Initialise()
{
mockOwinManager = new Mock<IOwinManager<ApplicationUser, ApplicationRole>>();
mockSearch = new Mock<ISearch<ApplicationUser>>();
mockMail = new Mock<IRpdbMail>();
mockUserStore = new Mock<IUserStore<ApplicationUser>>();
mockOwinManager.Setup(x => x.UserManager).Returns(() => new AppUserManager(mockUserStore.Object));
sut = new UsersController(mockOwinManager.Object, mockSearch.Object, mockMail.Object);
}
And then the test itself:
[Test]
public void WhenPut_IfUserIsNullReturnInternalServerError()
{
//Arrange
mockOwinManager.Setup(x => x.UserManager.FindByIdAsync(It.IsAny<string>())).Returns(() => null);
//Act
var response = sut.Put(new AppPersonUpdate());
//Assert
Assert.AreEqual(response.Result.StatusCode, HttpStatusCode.InternalServerError);
}
But my arrange line throws the following error:
Can not instantiate proxy of class: Microsoft.AspNet.Identity.UserManager`1[[SWDB.BusinessLayer.Identity.ApplicationUser, SWDB.BusinessLayer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].
Could not find a parameterless constructor.
Why is this so, since in Setup I've set my mockOwinManager's UserManager property in what I'd like it to return already?
Thanks
Aucun commentaire:
Enregistrer un commentaire