Yoamb
Yoamb

Reputation: 485

Debug Microsoft.AspNet.Identity.Core pdb

I try to implement register base on Microsoft.AspNet.Identity.Core.

package.config :

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFramework" version="6.1.3" targetFramework="net451" />
  <package id="Microsoft.AspNet.Identity.Core" version="2.2.1" targetFramework="net451" />
  <package id="Microsoft.AspNet.Identity.EntityFramework" version="2.2.1" targetFramework="net451" />
  <package id="Microsoft.AspNet.Identity.Owin" version="2.2.1" targetFramework="net451" />
  <package id="Microsoft.Owin" version="3.0.1" targetFramework="net451" />
  <package id="Microsoft.Owin.Security" version="3.0.1" targetFramework="net451" />
  <package id="Microsoft.Owin.Security.Cookies" version="3.0.1" targetFramework="net451" />
  <package id="Microsoft.Owin.Security.OAuth" version="3.0.1" targetFramework="net451" />
  <package id="Newtonsoft.Json" version="7.0.1" targetFramework="net451" />
  <package id="Owin" version="1.0" targetFramework="net451" />
</packages>

My unit test class:

public class register_test
    {
        Mock<IUserStore<ApplicationUser>> _userStore;
        IRegisterService _registerService;
        Mock<ApplicationUserManager> _userManagerMock;
        IDataProtectionProvider _dataProvider;


        public register_test()
        {
            _dataProvider = new DpapiDataProtectionProvider("paracours");
            _userStore = new Mock<IUserStore<ApplicationUser>>();
            _userManagerMock = new Mock<ApplicationUserManager>(_userStore.Object, _dataProvider);
            _registerService = new RegisterService(_userManagerMock.Object);
        }
        [Fact]
        public async Task register_sucess()
        {
            ApplicationUser user = new ApplicationUser() { Email = "[email protected]", UserName = "[email protected]" };
            _userManagerMock.Setup(u => u.CreateAsync(It.IsAny<ApplicationUser>(), It.IsAny<string>()))
                .ReturnsAsync(IdentityResult.Success)
                .Callback(() => user.Id = "0f8fad5b-d9cb-469f-a165-70867728950e");


            var result = await _registerService.RegisterAsync(user);

            _userManagerMock.Verify(x =>
                x.CreateAsync(
                It.Is<ApplicationUser>(u => u.Email == "[email protected]"),
                It.Is<string>(pass => pass == "P@ssword1")));

            Assert.NotNull(result);
            Assert.Equal(user.Id, "0f8fad5b-d9cb-469f-a165-70867728950e");

        }

        [Fact]
        public void email_token_generation_success()
        {

            _userManagerMock.Setup(u => u.FindByIdAsync(It.IsAny<string>()))
               .ReturnsAsync(new ApplicationUser() { Email = "[email protected]", UserName = "[email protected]", EmailConfirmed = false });
            var result = _registerService.EmailToken("0f8fad5b-d9cb-469f-a165-70867728950e");

            Assert.NotNull(result);

        }
    }


My service :

public class RegisterService : IRegisterService
{
    private readonly ApplicationUserManager _userManager;


    public RegisterService() { }

    public RegisterService(ApplicationUserManager userManager)
    {
        _userManager = userManager;
    }

    public virtual async Task<IdentityResult> RegisterAsync(ApplicationUser user)
    {
        return await _userManager.CreateAsync(user, "P@ssword1");
    }

    public virtual string EmailToken(string userId)
    {
        return _userManager.GenerateEmailConfirmationToken(userId);

    }
}

My Debug configuration:


When I touch F11, it'go to :

using System;
using System.Collections.Generic;
using System.Security.Claims;

namespace Microsoft.AspNet.Identity
{
    /// <summary>
    ///     Extension methods for UserManager
    /// </summary>
    public static class UserManagerExtensions
    {
        ...

        /// <summary>
        ///     Get the confirmation token for the user
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static string GenerateEmailConfirmationToken<TUser, TKey>(this UserManager<TUser, TKey> manager,
            TKey userId)
            where TKey : IEquatable<TKey>
            where TUser : class, IUser<TKey>
        {
            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }
            return AsyncHelper.RunSync(() => manager.GenerateEmailConfirmationTokenAsync(userId));
        }
        ...
    }
}


I don't know how to debug : manager.GenerateEmailConfirmationTokenAsync(userId)
inside
AsyncHelper.RunSync(() =>
Please i need held , it's new for me Task and debug

Upvotes: 1

Views: 1438

Answers (1)

Yoamb
Yoamb

Reputation: 485

I solve myself my problem. When i mock ApplicationUserManager with :

new Mock(_userStore.Object, _dataProvider);

It's create a Castle.Proxie for GenerateEmailConfirmationToken => that couldn't be resolve in the symbol (.pdb)

The solution is to not mock ApplicationUserManager

Upvotes: 1

Related Questions