public void MultiTenantEnabled_NullTenant_ReturnsEmptyResults()
 {
     SecuritySettings.Instance.MultiTenant = true;
     var sub = new MockUserAccountService();
     sub.MockUserAccounts(
         new UserAccount { Tenant = "a" },
         new UserAccount { Tenant = "a" },
         new UserAccount { Tenant = "b" });
     var result = sub.Object.GetAll(null);
     Assert.AreEqual(0, result.Count());
 }
 public void MultiTenantNotEnabled_NullTenant_ReturnsResultsForDefaultTenant()
 {
     SecuritySettings.Instance.MultiTenant = false;
     SecuritySettings.Instance.DefaultTenant = "a";
     var sub = new MockUserAccountService();
     sub.MockUserAccounts(
         new UserAccount { Tenant = "a" },
         new UserAccount { Tenant = "a" },
         new UserAccount { Tenant = "b" });
     var result = sub.Object.GetAll(null);
     Assert.AreEqual(2, result.Count());
 }
            public void VerifyFails_DoesNotCallNotificationService()
            {
                var sub = new MockUserAccountService();
                sub.NotificationService = new Mock<INotificationService>();
                var account = new MockUserAccount();
                sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns(account.Object);
                account.Setup(x => x.VerifyAccount(It.IsAny<string>())).Returns(false);

                sub.Object.VerifyAccount("key");

                sub.NotificationService.Verify(x => x.SendAccountVerified(It.IsAny<UserAccount>()), Times.Never());
            }
 public void CallsAuthenticateOnUserAccount()
 {
     var sub = new MockUserAccountService();
     var account = new MockUserAccount();
     sub.Object.Authenticate(account.Object, "pass", 10, TimeSpan.FromDays(1));
     account.Verify(x => x.Authenticate("pass", 10, TimeSpan.FromDays(1)));
 }
 public void NoAccountFound_ReturnsFail()
 {
     var sub = new MockUserAccountService();
     sub.Mock.Setup(x => x.GetByUsername(It.IsAny<string>(), It.IsAny<string>())).Returns((UserAccount)null);
     Assert.IsFalse(sub.Object.Authenticate("user", "pass"));
 }
 public void NullUsername_ReturnsFail()
 {
     var sub = new MockUserAccountService();
     Assert.IsFalse(sub.Object.Authenticate(null, "pass"));
 }
 public void NoTenantParam_LockoutParams_PassessNullTenant()
 {
     var sub = new MockUserAccountService();
     sub.Object.Authenticate("user", "pass", 10, TimeSpan.FromDays(1));
     sub.Mock.Verify(x => x.Authenticate(null, "user", "pass", 10, TimeSpan.FromDays(1)));
 }
 public void NoLockoutParams_PassessDefaultLocakoutParams()
 {
     var sub = new MockUserAccountService();
     sub.Object.Authenticate("ten", "user", "pass");
     sub.Mock.Verify(x => x.Authenticate("ten", "user", "pass", SecuritySettings.Instance.AccountLockoutFailedLoginAttempts, SecuritySettings.Instance.AccountLockoutDuration));
 }
            public void CallsSendAccountDelete()
            {
                var sub = new MockUserAccountService();
                sub.NotificationService = new Mock<INotificationService>();
                var account = new UserAccount();
                sub.Object.DeleteAccount(account);

                sub.NotificationService.Verify(x => x.SendAccountDelete(account));
            }
 public void NoTenantParam_PassesNullTenant()
 {
     var sub = new MockUserAccountService();
     sub.Object.DeleteAccount("user");
     sub.Mock.Verify(x => x.DeleteAccount(null, "user"));
 }
            public void KeysMatch_DeleteAccountCalled()
            {
                var sub = new MockUserAccountService();
                var account = new MockUserAccount();
                sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns(account.Object);
                account.Object.VerificationKey = "key";

                sub.Object.CancelNewAccount("key");

                sub.Mock.Verify(x => x.DeleteAccount(account.Object));
            }
            public void KeysMatch_ReturnsTrue()
            {
                var sub = new MockUserAccountService();
                var account = new MockUserAccount();
                sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns(account.Object);
                account.Object.VerificationKey = "key";

                Assert.IsTrue(sub.Object.CancelNewAccount("key"));
            }
            public void AccountVerified_ReturnsFalse()
            {
                var sub = new MockUserAccountService();
                var account = new MockUserAccount();
                sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns(account.Object);
                account.Object.IsAccountVerified = true;

                Assert.IsFalse(sub.Object.CancelNewAccount("key"));
            }
 public void InvalidKey_ReturnsFalse()
 {
     var sub = new MockUserAccountService();
     sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns((UserAccount)null);
     Assert.IsFalse(sub.Object.CancelNewAccount("key"));
 }
            public void VerifySucceeds_CallsNotificationService()
            {
                var sub = new MockUserAccountService();
                sub.NotificationService = new Mock<INotificationService>();
                var account = new MockUserAccount();
                sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns(account.Object);
                account.Setup(x => x.VerifyAccount(It.IsAny<string>())).Returns(true);

                sub.Object.VerifyAccount("key");

                sub.NotificationService.Verify(x => x.SendAccountVerified(account.Object));
            }
            public void AllowAccountDeletionDisabled_AccountIsVerified_CallsCloseOnAccount()
            {
                SecuritySettings.Instance.AllowAccountDeletion = false;

                var sub = new MockUserAccountService();
                var account = new MockUserAccount();
                account.Object.IsLoginAllowed = true;
                account.Object.IsAccountVerified = true;
                sub.Object.DeleteAccount(account.Object);

                sub.UserAccountRepository.Verify(x => x.Remove(account.Object), Times.Never());
                account.Verify(x => x.CloseAccount());
            }
            public void CallsSaveChangesOnRepo()
            {
                var sub = new MockUserAccountService();
                var account = new UserAccount();
                sub.Object.DeleteAccount(account);

                sub.UserAccountRepository.Verify(x => x.SaveChanges());
            }
            public void MultiTenantEnabled_NullTenantParam_ReturnsFail()
            {
                SecuritySettings.Instance.MultiTenant = true;

                var sub = new MockUserAccountService();
                var result = sub.Object.DeleteAccount(null, "user");
                Assert.IsFalse(result);
            }
 public void NoTenantParam_PassesNullForTenant()
 {
     var sub = new MockUserAccountService();
     sub.Object.Authenticate("user", "pass");
     sub.Mock.Verify(x => x.Authenticate(null, "user", "pass"));
 }
 public void NullUsernameParam_ReturnsFail()
 {
     var sub = new MockUserAccountService();
     var result = sub.Object.DeleteAccount((string)null);
     Assert.IsFalse(result);
 }
 public void SomeAccountsClosed_ReturnsOnlyAccountsNotClosed()
 {
     var sub = new MockUserAccountService();
     sub.MockUserAccounts(
         new UserAccount { ID = 1, Tenant = SecuritySettings.Instance.DefaultTenant, IsAccountClosed = true },
         new UserAccount { ID = 2, Tenant = SecuritySettings.Instance.DefaultTenant, IsAccountClosed = true },
         new UserAccount { ID = 3, Tenant = SecuritySettings.Instance.DefaultTenant, },
         new UserAccount { ID = 4, Tenant = SecuritySettings.Instance.DefaultTenant, });
     var result = sub.Object.GetAll(null);
     Assert.AreEqual(2, result.Count());
     CollectionAssert.AreEquivalent(new int[] { 3, 4 }, result.Select(x => x.ID).ToArray());
 }
 public void NoAccountFound_ReturnsFail()
 {
     var sub = new MockUserAccountService();
     var result = sub.Object.DeleteAccount("user");
     Assert.IsFalse(result);
 }
            public void MultiTenantEnabled_NullTenantParam_ReturnsFail()
            {
                SecuritySettings.Instance.MultiTenant = true;

                var sub = new MockUserAccountService();
                Assert.IsFalse(sub.Object.Authenticate(null, "user", "pass"));
            }
 public void AccountFound_ReturnsSuccess()
 {
     var sub = new MockUserAccountService();
     var account = new MockUserAccount();
     sub.Mock.Setup(x => x.GetByUsername(It.IsAny<string>(), It.IsAny<string>())).Returns(account.Object);
     var result = sub.Object.DeleteAccount("user");
     Assert.IsTrue(result);
 }
 public void NullPassword_ReturnsFail()
 {
     var sub = new MockUserAccountService();
     Assert.IsFalse(sub.Object.Authenticate("user", null));
 }
 public void AccountFound_DeleteAccountCalled()
 {
     var sub = new MockUserAccountService();
     var account = new MockUserAccount();
     sub.Mock.Setup(x => x.GetByUsername(It.IsAny<string>(), It.IsAny<string>())).Returns(account.Object);
     var result = sub.Object.DeleteAccount("user");
     sub.Mock.Verify(x => x.DeleteAccount(account.Object));
 }
 public void AccountFound_CallsAuthenticate()
 {
     var sub = new MockUserAccountService();
     UserAccount account = new UserAccount();
     sub.Mock.Setup(x => x.GetByUsername(It.IsAny<string>(), It.IsAny<string>())).Returns(account);
     sub.Object.Authenticate("user", "pass");
     sub.Mock.Verify(x => x.Authenticate(account, "pass", It.IsAny<int>(), It.IsAny<TimeSpan>()));
 }
            public void AllowAccountDeletion_CallsRemoveOnRepo()
            {
                SecuritySettings.Instance.AllowAccountDeletion = true;

                var sub = new MockUserAccountService();
                var account = new MockUserAccount();
                sub.Object.DeleteAccount(account.Object);

                sub.UserAccountRepository.Verify(x => x.Remove(account.Object));
            }
 public void CallsSaveChangesOnRepo()
 {
     var sub = new MockUserAccountService();
     var account = new MockUserAccount();
     sub.Object.Authenticate(account.Object, "pass", 10, TimeSpan.FromDays(1));
     sub.UserAccountRepository.Verify(x => x.SaveChanges());
 }
            public void AllowAccountDeletionDisabled_AccountIsNotVerified_CallsRemoveOnRepo()
            {
                SecuritySettings.Instance.AllowAccountDeletion = false;

                var sub = new MockUserAccountService();
                var account = new MockUserAccount();
                account.Object.IsAccountVerified = false;
                sub.Object.DeleteAccount(account.Object);

                sub.UserAccountRepository.Verify(x => x.Remove(account.Object));
            }