本文整理汇总了C#中TestableUserService类的典型用法代码示例。如果您正苦于以下问题:C# TestableUserService类的具体用法?C# TestableUserService怎么用?C# TestableUserService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestableUserService类属于命名空间,在下文中一共展示了TestableUserService类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: WithTokenThatDoesNotMatchUserReturnsFalse
public async Task WithTokenThatDoesNotMatchUserReturnsFalse()
{
var user = new User { Username = "username", EmailConfirmationToken = "token" };
var service = new TestableUserService();
var confirmed = await service.ConfirmEmailAddress(user, "not-token");
Assert.False(confirmed);
}
开发者ID:ZhiYuanHuang,项目名称:NuGetGallery,代码行数:9,代码来源:UserServiceFacts.cs
示例2: ReturnsFalseIfUserIsNotFound
public void ReturnsFalseIfUserIsNotFound()
{
var service = new TestableUserService();
service.MockUserRepository
.Setup(r => r.GetAll()).Returns(Enumerable.Empty<User>().AsQueryable());
var changed = service.ChangePassword("username", "oldpwd", "newpwd");
Assert.False(changed);
}
开发者ID:argsv,项目名称:NuGetGallery,代码行数:10,代码来源:UserServiceFacts.cs
示例3: ReturnsFalseIfPasswordDoesNotMatchUser
public void ReturnsFalseIfPasswordDoesNotMatchUser()
{
var service = new TestableUserService();
service.MockUserRepository
.Setup(r => r.GetAll()).Returns(new[]
{
new User { Username = "user", HashedPassword = "hashed" }
}.AsQueryable());
service.MockCrypto
.Setup(s => s.ValidateSaltedHash(It.IsAny<string>(), It.IsAny<string>(), Constants.Sha512HashAlgorithmId)).Returns(false);
var changed = service.ChangePassword("user", "oldpwd", "newpwd");
Assert.False(changed);
}
开发者ID:bnicoloff,项目名称:NuGetGallery,代码行数:15,代码来源:UserServiceFacts.cs
示例4: ReturnsTrueWhenSuccessful
public void ReturnsTrueWhenSuccessful()
{
var user = new User { Username = "user", HashedPassword = "old hash", PasswordHashAlgorithm = "PBKDF2" };
var service = new TestableUserService();
service.MockUserRepository
.Setup(r => r.GetAll()).Returns(new[] { user }.AsQueryable());
service.MockCrypto
.Setup(s => s.ValidateSaltedHash("old hash", "oldpwd", Constants.PBKDF2HashAlgorithmId)).Returns(true);
service.MockCrypto
.Setup(s => s.GenerateSaltedHash("newpwd", Constants.PBKDF2HashAlgorithmId)).Returns("hash and bacon");
var changed = service.ChangePassword("user", "oldpwd", "newpwd");
Assert.True(changed);
Assert.Equal("hash and bacon", user.HashedPassword);
}
开发者ID:bnicoloff,项目名称:NuGetGallery,代码行数:16,代码来源:UserServiceFacts.cs
示例5: DoesNotChangeConfirmationTokenButUserHasPendingEmailChange
public void DoesNotChangeConfirmationTokenButUserHasPendingEmailChange()
{
var user = new User { EmailAddress = "[email protected]", EmailConfirmationToken = "pending-token" };
var service = new TestableUserService();
service.UpdateProfile(user, "[email protected]", emailAllowed: true);
Assert.Equal("pending-token", user.EmailConfirmationToken);
}
开发者ID:argsv,项目名称:NuGetGallery,代码行数:9,代码来源:UserServiceFacts.cs
示例6: DoesNotSetConfirmationTokenWhenEmailAddressNotChanged
public void DoesNotSetConfirmationTokenWhenEmailAddressNotChanged()
{
var user = new User { EmailAddress = "[email protected]" };
var service = new TestableUserService();
service.UpdateProfile(user, "[email protected]", emailAllowed: true);
Assert.Null(user.EmailConfirmationToken);
}
开发者ID:argsv,项目名称:NuGetGallery,代码行数:9,代码来源:UserServiceFacts.cs
示例7: SetsAnApiKey
public void SetsAnApiKey()
{
var userService = new TestableUserService();
var user = userService.Create(
"theUsername",
"thePassword",
"theEmailAddress");
Assert.NotEqual(Guid.Empty, user.ApiKey);
}
开发者ID:argsv,项目名称:NuGetGallery,代码行数:11,代码来源:UserServiceFacts.cs
示例8: SavesEmailSettings
public async Task SavesEmailSettings()
{
var user = new User { EmailAddress = "[email protected]", EmailAllowed = true, NotifyPackagePushed = true};
var service = new TestableUserService();
service.MockUserRepository
.Setup(r => r.GetAll())
.Returns(new[] { user }.AsQueryable());
// Disable notifications
await service.ChangeEmailSubscriptionAsync(user, false, false);
Assert.Equal(false, user.EmailAllowed);
Assert.Equal(false, user.NotifyPackagePushed);
// Enable contact notifications
await service.ChangeEmailSubscriptionAsync(user, true, false);
Assert.Equal(true, user.EmailAllowed);
Assert.Equal(false, user.NotifyPackagePushed);
// Disable notifications
await service.ChangeEmailSubscriptionAsync(user, false, false);
Assert.Equal(false, user.EmailAllowed);
Assert.Equal(false, user.NotifyPackagePushed);
// Enable package pushed notifications
await service.ChangeEmailSubscriptionAsync(user, false, true);
Assert.Equal(false, user.EmailAllowed);
Assert.Equal(true, user.NotifyPackagePushed);
// Disable notifications
await service.ChangeEmailSubscriptionAsync(user, false, false);
Assert.Equal(false, user.EmailAllowed);
Assert.Equal(false, user.NotifyPackagePushed);
// Enable all notifications
await service.ChangeEmailSubscriptionAsync(user, true, true);
Assert.Equal(true, user.EmailAllowed);
Assert.Equal(true, user.NotifyPackagePushed);
service.MockUserRepository
.Verify(r => r.CommitChangesAsync());
}
开发者ID:ZhiYuanHuang,项目名称:NuGetGallery,代码行数:41,代码来源:UserServiceFacts.cs
示例9: WithEmptyTokenThrowsArgumentNullException
public async Task WithEmptyTokenThrowsArgumentNullException()
{
var service = new TestableUserService();
await AssertEx.Throws<ArgumentNullException>(() => service.ConfirmEmailAddress(new User(), ""));
}
开发者ID:ZhiYuanHuang,项目名称:NuGetGallery,代码行数:6,代码来源:UserServiceFacts.cs
示例10: ThrowsArgumentExceptionForNullUser
public void ThrowsArgumentExceptionForNullUser()
{
var service = new TestableUserService();
ContractAssert.ThrowsArgNull(() => service.UpdateProfile(null, emailAllowed: true), "user");
}
开发者ID:kl4w,项目名称:NuGetGallery,代码行数:6,代码来源:UserServiceFacts.cs
示例11: WithEmptyTokenThrowsArgumentNullException
public void WithEmptyTokenThrowsArgumentNullException()
{
var service = new TestableUserService();
Assert.Throws<ArgumentNullException>(() => service.ConfirmEmailAddress(new User(), ""));
}
开发者ID:kl4w,项目名称:NuGetGallery,代码行数:6,代码来源:UserServiceFacts.cs
示例12: FindsUsersUpdatesPasswordIfUsingLegacyHashAlgorithm
public void FindsUsersUpdatesPasswordIfUsingLegacyHashAlgorithm()
{
var user = new User
{
Username = "theUsername",
HashedPassword = CryptographyService.GenerateSaltedHash("thePassword", "SHA1"),
PasswordHashAlgorithm = "SHA1",
EmailAddress = "[email protected]",
};
var service = new TestableUserService();
service.MockUserRepository
.Setup(r => r.GetAll())
.Returns(new[] { user }.AsQueryable());
service.MockUserRepository
.Setup(r => r.CommitChanges())
.Verifiable();
service.FindByUsernameOrEmailAddressAndPassword("[email protected]", "thePassword");
Assert.Equal("PBKDF2", user.PasswordHashAlgorithm);
Assert.True(VerifyPasswordHash(user, "thePassword"));
service.MockUserRepository.Verify(r => r.CommitChanges(), Times.Once());
}
开发者ID:argsv,项目名称:NuGetGallery,代码行数:23,代码来源:UserServiceFacts.cs
示例13: FindsUsersByEmailAddress
public void FindsUsersByEmailAddress()
{
var user = new User
{
Username = "theUsername",
HashedPassword = CryptographyService.GenerateSaltedHash("thePassword", Constants.PBKDF2HashAlgorithmId),
EmailAddress = "[email protected]",
PasswordHashAlgorithm = "PBKDF2"
};
var service = new TestableUserService();
service.MockUserRepository
.Setup(r => r.GetAll())
.Returns(new[] { user }.AsQueryable());
var foundByEmailAddress = service.FindByUsernameOrEmailAddressAndPassword("[email protected]", "thePassword");
Assert.NotNull(foundByEmailAddress);
Assert.Same(user, foundByEmailAddress);
}
开发者ID:argsv,项目名称:NuGetGallery,代码行数:19,代码来源:UserServiceFacts.cs
示例14: FindsUsersByUserName
public void FindsUsersByUserName()
{
var user = CreateAUser("theUsername", "thePassword", "[email protected]");
var service = new TestableUserService();
service.MockUserRepository
.Setup(r => r.GetAll())
.Returns(new[] { user }.AsQueryable());
var foundByUserName = service.FindByUsernameAndPassword("theUsername", "thePassword");
Assert.NotNull(foundByUserName);
Assert.Same(user, foundByUserName);
}
开发者ID:argsv,项目名称:NuGetGallery,代码行数:13,代码来源:UserServiceFacts.cs
示例15: SetsTheUserToConfirmedWhenEmailConfirmationIsNotEnabled
public void SetsTheUserToConfirmedWhenEmailConfirmationIsNotEnabled()
{
var userService = new TestableUserService();
userService.MockConfig
.Setup(x => x.ConfirmEmailAddresses)
.Returns(false);
var user = userService.Create(
"theUsername",
"thePassword",
"theEmailAddress");
Assert.Equal(true, user.Confirmed);
}
开发者ID:argsv,项目名称:NuGetGallery,代码行数:14,代码来源:UserServiceFacts.cs
示例16: SetsCreatedDate
public void SetsCreatedDate()
{
var userService = new TestableUserService();
var user = userService.Create(
"theUsername",
"thePassword",
"theEmailAddress");
Assert.NotNull(user.CreatedUtc);
// Allow for up to 5 secs of time to have elapsed between Create call and now. Should be plenty
Assert.True((DateTime.UtcNow - user.CreatedUtc) < TimeSpan.FromSeconds(5));
}
开发者ID:argsv,项目名称:NuGetGallery,代码行数:14,代码来源:UserServiceFacts.cs
示例17: SetsAConfirmationToken
public void SetsAConfirmationToken()
{
var userService = new TestableUserService();
var user = userService.Create(
"theUsername",
"thePassword",
"theEmailAddress");
Assert.NotEmpty(user.EmailConfirmationToken);
Assert.False(user.Confirmed);
}
开发者ID:argsv,项目名称:NuGetGallery,代码行数:12,代码来源:UserServiceFacts.cs
示例18: ReturnsFalseIfPasswordDoesNotMatchUser_PBKDF2
public void ReturnsFalseIfPasswordDoesNotMatchUser_PBKDF2()
{
var user = new User
{
Username = "user",
HashedPassword = CryptographyService.GenerateSaltedHash("oldpwd", "PBKDF2"),
PasswordHashAlgorithm = "PBKDF2",
};
var service = new TestableUserService();
service.MockUserRepository
.Setup(r => r.GetAll()).Returns(new[] { user}.AsQueryable());
var changed = service.ChangePassword("user", "not_the_password", "newpwd");
Assert.False(changed);
}
开发者ID:argsv,项目名称:NuGetGallery,代码行数:16,代码来源:UserServiceFacts.cs
示例19: WithNullUserThrowsArgumentNullException
public void WithNullUserThrowsArgumentNullException()
{
var service = new TestableUserService();
Assert.Throws<ArgumentNullException>(() => service.ConfirmEmailAddress(null, "token"));
}
开发者ID:kl4w,项目名称:NuGetGallery,代码行数:6,代码来源:UserServiceFacts.cs
示例20: ReturnsFalseIfUserNotFound
public void ReturnsFalseIfUserNotFound()
{
var userService = new TestableUserService();
userService.MockUserRepository
.Setup(r => r.GetAll())
.Returns(Enumerable.Empty<User>().AsQueryable());
bool result = userService.ResetPasswordWithToken("user", "some-token", "new-password");
Assert.False(result);
}
开发者ID:argsv,项目名称:NuGetGallery,代码行数:11,代码来源:UserServiceFacts.cs
注:本文中的TestableUserService类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论