本文整理汇总了C#中MockUserAccount.Setup方法的典型用法代码示例。如果您正苦于以下问题:C# MockUserAccount.Setup方法的具体用法?C# MockUserAccount.Setup怎么用?C# MockUserAccount.Setup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockUserAccount
的用法示例。
在下文中一共展示了MockUserAccount.Setup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BasicProperties_Assigned
public void BasicProperties_Assigned()
{
var sub = new MockUserAccount("ten", "user", "pass", "email");
var now = new DateTime(2000, 2, 3, 8, 30, 0);
sub.Setup(x => x.UtcNow).Returns(now);
Assert.AreEqual("ten", sub.Object.Tenant);
Assert.AreEqual("user", sub.Object.Username);
Assert.AreEqual("email", sub.Object.Email);
Assert.AreEqual(now, sub.Object.Created);
sub.Verify(x => x.SetPassword("pass"));
}
示例2: EmailIsUsername_AllowEmailChangeWhenEmailIsUsername_WhenFail_DoesNotUpdatesUsername
public void EmailIsUsername_AllowEmailChangeWhenEmailIsUsername_WhenFail_DoesNotUpdatesUsername()
{
SecuritySettings.Instance.EmailIsUsername = true;
SecuritySettings.Instance.AllowEmailChangeWhenEmailIsUsername = true;
var sub = new MockUserAccountService();
var account = new MockUserAccount();
sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns(account.Object);
sub.Mock.Setup(x => x.Authenticate(It.IsAny<UserAccount>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<TimeSpan>())).Returns(true);
account.Setup(x => x.ChangeEmailFromKey(It.IsAny<string>(), It.IsAny<string>())).Returns(false);
sub.Object.ChangeEmailFromKey("pass", "key", "[email protected]");
Assert.AreNotEqual("[email protected]", account.Object.Username);
}
示例3: VerifyFails_DoesNotCallNotificationService
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());
}
示例4: EmailIsUsername_AllowEmailChangeWhenEmailIsUsername_ReturnsSuccess
public void EmailIsUsername_AllowEmailChangeWhenEmailIsUsername_ReturnsSuccess()
{
SecuritySettings.Instance.EmailIsUsername = true;
SecuritySettings.Instance.AllowEmailChangeWhenEmailIsUsername = true;
var sub = new MockUserAccountService();
var account = new MockUserAccount();
sub.Mock.Setup(x => x.GetByUsername(It.IsAny<string>(), It.IsAny<string>())).Returns(account.Object);
account.Setup(x => x.ChangeEmailRequest(It.IsAny<string>())).Returns(true);
Assert.IsTrue(sub.Object.ChangeEmailRequest("user", "[email protected]"));
}
示例5: UserAccountChangeEmailFromKeySuccess_SaveChangesCalled
public void UserAccountChangeEmailFromKeySuccess_SaveChangesCalled()
{
var sub = new MockUserAccountService();
var account = new MockUserAccount();
sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns(account.Object);
sub.Mock.Setup(x => x.Authenticate(It.IsAny<UserAccount>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<TimeSpan>())).Returns(true);
account.Setup(x => x.ChangeEmailFromKey(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
sub.Object.ChangeEmailFromKey("pass", "key", "[email protected]");
sub.UserAccountRepository.Verify(x => x.SaveChanges());
}
示例6: UserAccountChangeEmailRequestFail_ReturnsFail
public void UserAccountChangeEmailRequestFail_ReturnsFail()
{
var sub = new MockUserAccountService();
var account = new MockUserAccount();
sub.Mock.Setup(x => x.GetByUsername(It.IsAny<string>(), It.IsAny<string>())).Returns(account.Object);
account.Setup(x => x.ChangeEmailRequest(It.IsAny<string>())).Returns(false);
Assert.IsFalse(sub.Object.ChangeEmailRequest("user", "[email protected]"));
}
示例7: UserAccountChangeEmailRequestSuccess_CallsSendChangeEmailRequestNotice
public void UserAccountChangeEmailRequestSuccess_CallsSendChangeEmailRequestNotice()
{
var sub = new MockUserAccountService();
sub.NotificationService = new Mock<INotificationService>();
var account = new MockUserAccount();
sub.Mock.Setup(x => x.GetByUsername(It.IsAny<string>(), It.IsAny<string>())).Returns(account.Object);
account.Setup(x => x.ChangeEmailRequest(It.IsAny<string>())).Returns(true);
sub.Object.ChangeEmailRequest("user", "[email protected]");
sub.NotificationService.Verify(x => x.SendChangeEmailRequestNotice(account.Object, "[email protected]"));
}
示例8: KeyHasEmailPrefix_ReturnsSuccess
public void KeyHasEmailPrefix_ReturnsSuccess()
{
var sub = new MockUserAccount();
sub.Setup(x => x.IsVerificationKeyStale).Returns(false);
sub.Object.VerificationKey = "prefixkey";
sub.Setup(x => x.Hash(It.IsAny<string>())).Returns("prefix");
var result = sub.Object.ChangeEmailFromKey("prefixkey", "[email protected]");
Assert.IsTrue(result);
}
示例9: ChangeEmailFromKeySuccess_SetsNewEmail
public void ChangeEmailFromKeySuccess_SetsNewEmail()
{
var sub = new MockUserAccount();
sub.Setup(x => x.IsVerificationKeyStale).Returns(false);
sub.Object.VerificationKey = "prefixkey";
sub.Setup(x => x.Hash(It.IsAny<string>())).Returns("prefix");
var result = sub.Object.ChangeEmailFromKey("prefixkey", "[email protected]");
Assert.AreEqual("[email protected]", sub.Object.Email);
}
示例10: VerificationKeyStale_ReturnsFail
public void VerificationKeyStale_ReturnsFail()
{
var sub = new MockUserAccount();
sub.Setup(x => x.IsVerificationKeyStale).Returns(true);
var result = sub.Object.ChangeEmailFromKey("key", "[email protected]");
Assert.IsFalse(result);
}
示例11: KeyDoesNotMatch_ReturnsFail
public void KeyDoesNotMatch_ReturnsFail()
{
var sub = new MockUserAccount();
sub.Setup(x => x.IsVerificationKeyStale).Returns(false);
sub.Object.VerificationKey = "key1";
var result = sub.Object.ChangeEmailFromKey("key2", "[email protected]");
Assert.IsFalse(result);
}
示例12: ChangeEmailSuccess_VerificationKeyMatchesEmailPrefix_VerificationKeyFlagsNotReset
public void ChangeEmailSuccess_VerificationKeyMatchesEmailPrefix_VerificationKeyFlagsNotReset()
{
var sub = new MockUserAccount();
sub.Object.IsAccountVerified = true;
sub.Setup(x => x.IsVerificationKeyStale).Returns(false);
sub.Setup(x => x.Hash(It.IsAny<string>())).Returns("key");
sub.Object.VerificationKey = "key";
var date = new DateTime(2000, 2, 3);
sub.Object.VerificationKeySent = date;
var result = sub.Object.ChangeEmailRequest("[email protected]");
Assert.AreEqual("key", sub.Object.VerificationKey);
Assert.AreEqual(date, sub.Object.VerificationKeySent);
}
示例13: ChangeEmailSuccess_VerificationKeyDoesntMatchEmailPrefix_VerificationKeyFlagsReset
public void ChangeEmailSuccess_VerificationKeyDoesntMatchEmailPrefix_VerificationKeyFlagsReset()
{
var sub = new MockUserAccount();
sub.Object.IsAccountVerified = true;
sub.Setup(x => x.IsVerificationKeyStale).Returns(false);
sub.Setup(x => x.Hash(It.IsAny<string>())).Returns("hash");
sub.Setup(x => x.GenerateSalt()).Returns("salt");
var now = new DateTime(2000, 2, 3);
sub.Setup(x => x.UtcNow).Returns(now);
sub.Object.VerificationKey = "key";
var result = sub.Object.ChangeEmailRequest("[email protected]");
Assert.AreEqual("hashsalt", sub.Object.VerificationKey);
Assert.AreEqual(now, sub.Object.VerificationKeySent);
}
示例14: FailedLoginCountHigh_LastFailedLoginIsNotRecent_ReturnsFalse
public void FailedLoginCountHigh_LastFailedLoginIsNotRecent_ReturnsFalse()
{
var sub = new MockUserAccount();
sub.Object.FailedLoginCount = 10;
var date = new DateTime(2003, 2, 3, 8, 30, 0);
sub.Setup(x => x.UtcNow).Returns(date);
var duration = TimeSpan.FromMinutes(10);
sub.Object.LastFailedLogin = date.Subtract(TimeSpan.FromMinutes(11));
var result = sub.Object.HasTooManyRecentPasswordFailures(5, duration);
Assert.IsFalse(result);
}
示例15: UserAccountFails_DoesNotCallsSaveChangesOnUserAccountRepo
public void UserAccountFails_DoesNotCallsSaveChangesOnUserAccountRepo()
{
var sub = new MockUserAccountService();
var account = new MockUserAccount();
sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns(account.Object);
sub.Object.ChangePasswordFromResetKey("key", "new");
account.Setup(x => x.ChangePasswordFromResetKey(It.IsAny<string>(), It.IsAny<string>())).Returns(false);
sub.Object.ChangePasswordFromResetKey("key", "new");
sub.UserAccountRepository.Verify(x => x.SaveChanges(), Times.Never());
}