using Fan.Membership;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Moq;
using System;
using System.Threading.Tasks;

namespace Fan.Blog.Tests.Helpers
{
    /// <summary>
    /// Fake <see cref="UserManager{TUser}"/> to help create <see cref="FakeSignInManager"/>.
    /// </summary>
    /// <remarks>
    /// https://stackoverflow.com/questions/35627568/asp-net-5-unit-test-controller-with-usermanager
    /// </remarks>
    public class FakeUserManager : UserManager<User>
    {
        public FakeUserManager()
            : base(new Mock<IUserStore<User>>().Object,
                  new Mock<IOptions<IdentityOptions>>().Object,
                  new Mock<IPasswordHasher<User>>().Object,
                  new IUserValidator<User>[0],
                  new IPasswordValidator<User>[0],
                  new Mock<ILookupNormalizer>().Object,
                  new Mock<IdentityErrorDescriber>().Object,
                  new Mock<IServiceProvider>().Object,
                  new Mock<ILogger<UserManager<User>>>().Object)
        { }

        public override Task<IdentityResult> CreateAsync(User user, string password)
        {
            return Task.FromResult(IdentityResult.Success);
        }

        public override Task<User> FindByNameAsync(string userName)
        {
            return Task.FromResult(Actor.User);
        }
    }
}
