public void ShouldReturnUsersByUserNameMatch()
			{
				var testData = UserTestData.Setup(false);
				var userList = new SrirachaUser[] 
				{
					new SrirachaUser { UserName="******", EmailAddress = "*****@*****.**" },
					new SrirachaUser { UserName="******", EmailAddress = "*****@*****.**" },
					new SrirachaUser { UserName="******", EmailAddress = "*****@*****.**" },
					new SrirachaUser { UserName="******", EmailAddress = "*****@*****.**" },
					new SrirachaUser { UserName="******", EmailAddress = "*****@*****.**" },
				};
				string userNameToMatch = "test1";
				var matchedList = userList.Where(i=>i.EmailAddress.Contains(userNameToMatch));
				var pagedList = new PagedSortedList<SrirachaUser>(new PagedList.StaticPagedList<SrirachaUser>(matchedList,  1, int.MaxValue, matchedList.Count()), string.Empty, true);
                testData.Repository.Setup(i => i.GetUserList(It.IsAny<ListOptions>(), It.IsAny<List<string>>(), null)).Returns(pagedList);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				int totalRecords;
				var collection = provider.FindUsersByName(userNameToMatch, 0, 10, out totalRecords);

				Assert.AreEqual(1, totalRecords);
				Assert.IsNotNull(collection);
				Assert.AreEqual(1, collection.Count);
				Assert.IsNotNull(collection["test1"]);
			}
			public void ShouldReturnFalseInvalidUserName()
			{
				var testData = UserTestData.Setup(true);
				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				bool result = provider.ValidateUser(testData.UserName, Guid.NewGuid().ToString());

				Assert.IsFalse(result);
			}
			public void DefaultsToSriracha()
			{
				var provider = new SrirachaMembershipProvider();
				Assert.AreEqual("Sriracha", provider.ApplicationName);
			}
			public void ShouldUpdateUserFields()
			{
				var testData = UserTestData.Setup(true);
				var membershipUser = new MembershipUser
				(
					providerName: SrirachaMembershipProvider.ProviderName,
					name: testData.SrirachaUser.UserName,
					providerUserKey: testData.SrirachaUser.UserGuid,
					email: Guid.NewGuid().ToString() + "@example.com",
					passwordQuestion: Guid.NewGuid().ToString(),
					creationDate: testData.SrirachaUser.CreatedDateTimeUtc,
					isLockedOut: testData.SrirachaUser.LockedIndicator,
					comment: null,
					isApproved: true,
					lastActivityDate: DateTime.UtcNow,
					lastLockoutDate: DateTime.MinValue,
					lastLoginDate: DateTime.UtcNow,
					lastPasswordChangedDate: DateTime.MinValue
				);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				provider.UpdateUser(membershipUser);

				Assert.AreEqual(membershipUser.Email, testData.SrirachaUser.EmailAddress);
				testData.Repository.Verify(i=>i.UpdateUser(It.IsAny<SrirachaUser>()), Times.Once());
			}
			public void ShouldAcceptValidUserNamePassword()
			{
				var testData = UserTestData.Setup(true);
				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				bool result = provider.ValidateUser(testData.UserName, testData.Password);

				Assert.IsTrue(result);
			}
			public void ShouldThrowException()
			{
				var testData = UserTestData.Setup(false);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				Assert.Throws(typeof(ProviderException), delegate { provider.ResetPassword(null, null); });
			}
			public void ShouldSucceedIfUserAlreadyLocked()
			{
				var testData = UserTestData.Setup(true);
				testData.SrirachaUser.LockedIndicator = false;

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				bool result = provider.UnlockUser(testData.SrirachaUser.UserName);

				Assert.IsTrue(result);
				Assert.IsFalse(testData.SrirachaUser.LockedIndicator);
			}
			public void ShouldUpdateLastActivityDateForProviderKeyIfOnline()
			{
				var testData = UserTestData.Setup(true);
				testData.SrirachaUser.LastActivityDateTimeUtc = DateTime.UtcNow.AddMonths(-1);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				var membershipUser = provider.GetUser(testData.SrirachaUser.UserGuid, true);

				Assert.IsNotNull(membershipUser);
				testData.Repository.Verify(i => i.UpdateUser(testData.SrirachaUser), Times.Once());
				Assert.Greater(testData.SrirachaUser.LastActivityDateTimeUtc, DateTime.UtcNow.AddMinutes(-1));
			}
			public void ShouldNotUpdateLastActivityDateForProviderKeyIfNotOnline()
			{
				var testData = UserTestData.Setup(true);
				testData.SrirachaUser.LastActivityDateTimeUtc = DateTime.UtcNow.AddMonths(-1);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				var membershipUser = provider.GetUser(testData.SrirachaUser.UserGuid, false);

				Assert.IsNotNull(membershipUser);
				testData.Repository.Verify(i => i.UpdateUser(It.IsAny<SrirachaUser>()), Times.Never());
			}
			public void ShouldReturnUserByProviderKey()
			{
				var testData = UserTestData.Setup(true);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				var membershipUser = provider.GetUser(testData.SrirachaUser.UserGuid, false);

				Assert.IsNotNull(membershipUser);
				Assert.AreEqual(testData.SrirachaUser.UserName, membershipUser.UserName);
				Assert.AreEqual(testData.SrirachaUser.UserGuid, membershipUser.ProviderUserKey);
			}
			public void ShouldReturnNullForInvalidProviderKey()
			{
				var testData = UserTestData.Setup(true);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				var membershipUser = provider.GetUser(Guid.NewGuid(), false);

				Assert.IsNull(membershipUser);
			}
			public void ShouldUpdateLastActivityDateForUserNameIfOnline()
			{
				var testData = UserTestData.Setup(true);
				testData.SrirachaUser.LastActivityDateTimeUtc = DateTime.UtcNow.AddMonths(-1);
				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				var membershipUser = provider.GetUser(testData.SrirachaUser.UserName, true);

				Assert.IsNotNull(membershipUser);
                Thread.Sleep(1000); //The update user is run async, try to wait for it
				testData.Repository.Verify(i => i.UpdateUser(testData.SrirachaUser), Times.Once());
				Assert.Greater(testData.SrirachaUser.LastActivityDateTimeUtc, DateTime.UtcNow.AddMinutes(-1));
			}
			public void ShouldReturnListOfUsersWhoseLastActivityDateWas15MinutesAgo()
			{
				var testData = UserTestData.Setup(false);
				testData.Repository.Setup(i => i.GetUserCount(It.IsAny<DateTime?>())).Returns(10);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				int userCount = provider.GetNumberOfUsersOnline();

				Assert.AreEqual(10, userCount);
			}
			public void ShouldReturnUserList()
			{
				var testData = UserTestData.Setup(false);
				var userList = new SrirachaUser[] 
				{
					new SrirachaUser { UserName="******", EmailAddress = "*****@*****.**" },
					new SrirachaUser { UserName="******", EmailAddress = "*****@*****.**" },
					new SrirachaUser { UserName="******", EmailAddress = "*****@*****.**" },
					new SrirachaUser { UserName="******", EmailAddress = "*****@*****.**" },
					new SrirachaUser { UserName="******", EmailAddress = "*****@*****.**" },
				};
				var pagedList = new PagedSortedList<SrirachaUser>(new PagedList.StaticPagedList<SrirachaUser>(userList,  1, int.MaxValue, userList.Count()), string.Empty, true);
                testData.Repository.Setup(i => i.GetUserList(It.Is<ListOptions>(j => j.PageNumber == 1 && j.PageSize == 10), null, null)).Returns(pagedList);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				int totalRecords;
				var collection = provider.GetAllUsers(0, 10, out totalRecords);

				Assert.AreEqual(5, totalRecords);
				Assert.IsNotNull(collection);
				Assert.AreEqual(5, collection.Count);
				Assert.IsNotNull(collection["test1"]);
				Assert.IsNotNull(collection["test2"]);
				Assert.IsNotNull(collection["test3"]);
				Assert.IsNotNull(collection["test4"]);
				Assert.IsNotNull(collection["test5"]);
			}
			public void ShouldBeFalse()
			{
				var testData = UserTestData.Setup(false);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				Assert.IsFalse(provider.RequiresQuestionAndAnswer);
			}
			public void ShouldReturnUserNameByEmail()
			{
				var testData = UserTestData.Setup(true);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				string userName = provider.GetUserNameByEmail(testData.SrirachaUser.EmailAddress);
				
				Assert.AreEqual(testData.SrirachaUser.UserName, userName);
			}
			public void ShouldBeTrue()
			{
				var testData = UserTestData.Setup(false);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				Assert.IsTrue(provider.RequiresUniqueEmail);
			}
			public void ShouldReturnEmptyStringForInvalidEmail()
			{
				var testData = UserTestData.Setup(false);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				string userName = provider.GetUserNameByEmail(Guid.NewGuid().ToString());

				Assert.AreEqual(string.Empty, userName);
			}
			public void ShouldResetIsLockedFlag()
			{
				var testData = UserTestData.Setup(true);
				testData.SrirachaUser.LockedIndicator = true;

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				bool result = provider.UnlockUser(testData.SrirachaUser.UserName);

				Assert.IsTrue(result);
				Assert.IsFalse(testData.SrirachaUser.LockedIndicator);
				testData.Repository.Verify(i=>i.UpdateUser(testData.SrirachaUser), Times.Once());
			}
			public void ShouldBeZero()
			{
				var testData = UserTestData.Setup(false);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				Assert.AreEqual(0, provider.MinRequiredNonAlphanumericCharacters);
			}
			public void ShouldFailIfUserNameInvalid()
			{
				var testData = UserTestData.Setup(true);
				testData.SrirachaUser.LockedIndicator = true;

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				bool result = provider.UnlockUser(Guid.NewGuid().ToString());

				Assert.IsFalse(result);
				Assert.IsTrue(testData.SrirachaUser.LockedIndicator);
				testData.Repository.Verify(i => i.UpdateUser(It.IsAny<SrirachaUser>()), Times.Never());
			}
			public void ShouldBeSix()
			{
				var testData = UserTestData.Setup(false);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				Assert.AreEqual(6, provider.MinRequiredPasswordLength);
			}
			public void ShouldThrowExceptionForInvalidUserName()
			{
				var testData = UserTestData.Setup(false);
				var membershipUser = new MembershipUser
				(
					providerName: SrirachaMembershipProvider.ProviderName,
					name: Guid.NewGuid().ToString(),
					providerUserKey: Guid.NewGuid(),
					email: Guid.NewGuid().ToString() + "@example.com",
					passwordQuestion: Guid.NewGuid().ToString(),
					creationDate: DateTime.MinValue,
					isLockedOut: false,
					comment: null,
					isApproved: true,
					lastActivityDate: DateTime.UtcNow,
					lastLockoutDate: DateTime.MinValue,
					lastLoginDate: DateTime.UtcNow,
					lastPasswordChangedDate: DateTime.MinValue
				);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				Assert.Throws(typeof(RecordNotFoundException), delegate { provider.UpdateUser(membershipUser); });
				testData.Repository.Verify(i => i.UpdateUser(It.IsAny<SrirachaUser>()), Times.Never());
			}
			public void ShouldBeFiveMinutes()
			{
				var testData = UserTestData.Setup(false);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				Assert.AreEqual(5, provider.PasswordAttemptWindow);
			}
			public void ShouldUpdateLastLogicDateUponSuccess()
			{
				var testData = UserTestData.Setup(true);
				testData.SrirachaUser.LastLoginDateDateTimeUtc = DateTime.UtcNow.AddDays(-1);
				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				bool result = provider.ValidateUser(testData.UserName, testData.Password);

				Assert.IsTrue(result);
				Assert.Less(DateTime.UtcNow.AddMinutes(-1), testData.SrirachaUser.LastLoginDateDateTimeUtc);
				testData.Repository.Verify(i=>i.UpdateUser(testData.SrirachaUser), Times.Once());
			}
			public void ShouldBeHashed()
			{
				var testData = UserTestData.Setup(false);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				Assert.AreEqual(MembershipPasswordFormat.Hashed, provider.PasswordFormat);
			}
			public void ShouldReturnFalseForInvalidUserName()
			{
				var testData = UserTestData.Setup(false);
				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				bool result = provider.ValidateUser(testData.UserName, testData.Password);

				Assert.IsFalse(result);
			}
			public void ShouldMatchSecurityConstantsValue()
			{
				var testData = UserTestData.Setup(false);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				Assert.AreEqual(@"^(?=.*\d).{6,}$", provider.PasswordStrengthRegularExpression);
			}
			public void IsUpdatable()
			{
				SrirachaMembershipProvider provider = new SrirachaMembershipProvider();
				string testValue = Guid.NewGuid().ToString();
				provider.ApplicationName = testValue;
				Assert.AreEqual(testValue, provider.ApplicationName);
			}
			public void ShouldBeFalse()
			{
				var testData = UserTestData.Setup(false);

				var provider = new SrirachaMembershipProvider(testData.Repository.Object);
				Assert.IsFalse(provider.EnablePasswordRetrieval);
			}