Как создать IdentityResult с успехом == trueC#

Место общения программистов C#
Ответить
Гость
 Как создать IdentityResult с успехом == true

Сообщение Гость »


I have a class with Microsoft.AspNet.Identity.UserManager injected, and I want to expect the userManager.CreateAsync(user, password) method to return a Task where the IdentityResult.Succeeded = true. However, the only available constructors for IdentityResult are failure constructors that will cause Succeeded property to be false.

How does one create an IdentityResult that has Succeeded == true? IdentityResult doesn't implement an interface and Succeeded isn't virtual so I don't see any obvious ways of creating a mock object through Rhino Mocks (which i'm using as my mocking framework).

My method does something like the below. Providing this example to show why I might want to mock this.

public async Task RegisterUser(NewUser newUser) { ApplicationUser newApplicationUser = new ApplicationUser() { UserName = newUser.UserName, Email = newUser.Email }; IdentityResult identityResult = await applicationUserManager.CreateAsync(newApplicationUser, newUser.Password); if(identityResult.Succeeded) { someOtherDependency.DoSomethingAmazing(); } return identityResult; } I'm trying to write a unit test that ensures that someOtherDependency.DoSomethingAmazing() is called if identityResult.Succeeded is true. Thanks for any help!
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»