﻿using Avo.AspNet.Identity.MongoDB;
using Microsoft.AspNet.Identity;
using MongoDB.Driver;
using NUnit.Framework;

namespace Avo.AspNet.Identity.MongoDB.Tests
{
    [TestFixture]
	public class UserPasswordStoreTests : UserIntegrationTestsBase
	{
		[Test]
		public void HasPassword_NoPassword_ReturnsFalse()
		{
			var user = new IdentityUser("bob");
			var manager = GetUserManager();
			manager.Create(user);

			var hasPassword = manager.HasPassword(user.Id);

			Assert.That(hasPassword, Is.False);
		}

		[Test]
		public void AddPassword_NewPassword_CanFindUserByPassword()
		{
			var user = new IdentityUser("bob");
			var manager = GetUserManager();
			manager.Create(user);
            manager.AddPassword(user.Id, "testtest");
            var findUserByPassword = manager.Find("bob", "testtest");
			Assert.That(findUserByPassword, Is.Not.Null);
		}

		[Test]
		public void RemovePassword_UserWithPassword_SetsPasswordNull()
		{
			var user = new IdentityUser("bob");
			var manager = GetUserManager();
			manager.Create(user);
			manager.AddPassword(user.Id, "testtest");

			manager.RemovePassword(user.Id);

			var savedUser = Users.AsQueryable().Single();
			Assert.That(savedUser.PasswordHash, Is.Null);
		}
	}
}