Carlos G.
Carlos G.

Reputation: 145

Asp Identity UserManager only has Async methods using Moq

i'm using Moq with Asp Identity but when i use UserManager this only get Async methods, here is my code:

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create(Person person)
    {
        if (_personRepository.Exist(person.Identificaction))
        {        
            person.IdUserCreate = _userManager.FindByName(User.Identity.Name).Id;

            try
            {
                _personRepository.Save(person);
            }
            catch (Exception)
            {
               ////
            }
        }
        else
              ///


        return RedirectToAction("Create");
    }

My PersonRepository,

public..... { rgContext _context = new rgContext();

    public void Save(person Entity)
    {
        _context.Person.Add(Entity);
        _context.SaveChanges();
    }

}

Test Method:

        [TestMethod]
    public void CreateVoter_Should_Save_Voter()
    {


        var MockPersonRepository = new Mock<IEntity<Person>>();

        var UserManger = new Mock<rgUserManager>();

        MockPersonRepository.Setup(c => c.Exist("2222222")).Returns(true);


        UserManger.Setup(c => c.**FindByNameAsync**("[email protected]")).Returns(Task.FromResult(new rgUser() { Id = 1 }));

        //////


    }

I'm here when i declare UserManger, only got async methods for example:

and i need to use the synchronous method because this app is really small but this is kicking my as....

I hope you can help :p

Pd: I'm using unity for DI.

Upvotes: 1

Views: 716

Answers (1)

Dillon
Dillon

Reputation: 707

I know this post is old, but do you have your using statement in the class?

using Microsoft.AspNet.Identity;

Upvotes: 2

Related Questions