本文整理汇总了C#中NuGetGallery.User类的典型用法代码示例。如果您正苦于以下问题:C# User类的具体用法?C# User怎么用?C# User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
User类属于NuGetGallery命名空间,在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatePackageWillSavePackageFileToFileStorage
public async Task CreatePackageWillSavePackageFileToFileStorage()
{
// Arrange
var guid = Guid.NewGuid().ToString();
var fakeUser = new User();
var userService = new Mock<IUserService>();
userService.Setup(x => x.FindByApiKey(It.IsAny<Guid>())).Returns(fakeUser);
var packageRegistration = new PackageRegistration();
packageRegistration.Owners.Add(fakeUser);
var packageService = new Mock<IPackageService>();
packageService.Setup(p => p.FindPackageRegistrationById(It.IsAny<string>())).Returns(packageRegistration);
var packageFileService = new Mock<IPackageFileService>();
packageFileService.Setup(p => p.SavePackageFileAsync(It.IsAny<Package>(), It.IsAny<Stream>())).Returns(Task.FromResult(0)).Verifiable();
var nuGetPackage = new Mock<INupkg>();
nuGetPackage.Setup(x => x.Metadata.Id).Returns("theId");
nuGetPackage.Setup(x => x.Metadata.Version).Returns(new SemanticVersion("1.0.42"));
var controller = CreateController(
fileService: packageFileService,
userService: userService,
packageService: packageService,
packageFromInputStream: nuGetPackage);
// Act
await controller.CreatePackagePut(guid);
// Assert
packageFileService.Verify();
}
示例2: WillReturnConflictIfAPackageWithTheIdAndSemanticVersionAlreadyExists
public void WillReturnConflictIfAPackageWithTheIdAndSemanticVersionAlreadyExists()
{
var version = new SemanticVersion("1.0.42");
var nuGetPackage = new Mock<IPackage>();
nuGetPackage.Setup(x => x.Id).Returns("theId");
nuGetPackage.Setup(x => x.Version).Returns(version);
var user = new User();
var packageRegistration = new PackageRegistration
{
Packages = new List<Package> { new Package { Version = version.ToString() } },
Owners = new List<User> { user }
};
var packageSvc = new Mock<IPackageService>();
packageSvc.Setup(x => x.FindPackageRegistrationById(It.IsAny<string>())).Returns(packageRegistration);
var userSvc = new Mock<IUserService>();
userSvc.Setup(x => x.FindByApiKey(It.IsAny<Guid>())).Returns(user);
var controller = CreateController(userSvc: userSvc, packageSvc: packageSvc, packageFromInputStream: nuGetPackage.Object);
// Act
var result = controller.CreatePackagePut(Guid.NewGuid().ToString());
// Assert
Assert.IsType<HttpStatusCodeWithBodyResult>(result);
var statusCodeResult = (HttpStatusCodeWithBodyResult)result;
Assert.Equal(409, statusCodeResult.StatusCode);
Assert.Equal(String.Format(Strings.PackageExistsAndCannotBeModified, "theId", "1.0.42"), statusCodeResult.StatusDescription);
}
示例3: CreatePackageWillSavePackageFileToFileStorage
public async Task CreatePackageWillSavePackageFileToFileStorage()
{
// Arrange
var user = new User() { EmailAddress = "[email protected]" };
var packageRegistration = new PackageRegistration();
packageRegistration.Id = "theId";
packageRegistration.Owners.Add(user);
var package = new Package();
package.PackageRegistration = packageRegistration;
package.Version = "1.0.42";
packageRegistration.Packages.Add(package);
var controller = new TestableApiController();
controller.SetCurrentUser(user);
controller.MockPackageFileService.Setup(p => p.SavePackageFileAsync(It.IsAny<Package>(), It.IsAny<Stream>()))
.Returns(Task.CompletedTask).Verifiable();
controller.MockPackageService.Setup(p => p.FindPackageRegistrationById(It.IsAny<string>()))
.Returns(packageRegistration);
controller.MockPackageService.Setup(p => p.CreatePackageAsync(It.IsAny<PackageArchiveReader>(), It.IsAny<PackageStreamMetadata>(), It.IsAny<User>(), false))
.Returns(Task.FromResult(package));
var nuGetPackage = TestPackage.CreateTestPackageStream("theId", "1.0.42");
controller.SetupPackageFromInputStream(nuGetPackage);
// Act
await controller.CreatePackagePut();
// Assert
controller.MockPackageFileService.Verify();
}
示例4: ConfirmPackageOwner
public bool ConfirmPackageOwner(PackageRegistration package, User pendingOwner, string token)
{
if (package == null)
{
throw new ArgumentNullException("package");
}
if (pendingOwner == null)
{
throw new ArgumentNullException("pendingOwner");
}
if (String.IsNullOrEmpty(token))
{
throw new ArgumentNullException("token");
}
if (package.IsOwner(pendingOwner))
{
return true;
}
var request = FindExistingPackageOwnerRequest(package, pendingOwner);
if (request != null && request.ConfirmationCode == token)
{
AddPackageOwner(package, pendingOwner);
return true;
}
return false;
}
示例5: CreatePackage
public Package CreatePackage(IPackage nugetPackage, User currentUser)
{
ValidateNuGetPackage(nugetPackage);
var packageRegistration = CreateOrGetPackageRegistration(currentUser, nugetPackage);
var package = CreatePackageFromNuGetPackage(packageRegistration, nugetPackage);
packageRegistration.Packages.Add(package);
using (var tx = new TransactionScope())
{
using (var stream = nugetPackage.GetStream())
{
UpdateIsLatest(packageRegistration);
packageRegistrationRepo.CommitChanges();
packageFileSvc.SavePackageFile(package, stream);
tx.Complete();
}
}
if (package.Status != PackageStatusType.Approved && package.Status != PackageStatusType.Exempted) NotifyForModeration(package, comments: string.Empty);
NotifyIndexingService();
return package;
}
示例6: StartEditPackageRequest
public virtual void StartEditPackageRequest(Package p, EditPackageVersionRequest request, User editingUser)
{
PackageEdit edit = new PackageEdit
{
// Description
User = editingUser,
Authors = request.Authors,
Copyright = request.Copyright,
Description = request.Description,
IconUrl = request.IconUrl,
LicenseUrl = p.LicenseUrl, // Our current policy is not to allow editing the license URL, so just clone it from its previous value.
ProjectUrl = request.ProjectUrl,
ReleaseNotes = request.ReleaseNotes,
RequiresLicenseAcceptance = request.RequiresLicenseAcceptance,
Summary = request.Summary,
Tags = request.Tags,
Title = request.VersionTitle,
// Other
Package = p,
Timestamp = DateTime.UtcNow,
TriedCount = 0,
};
EntitiesContext.Set<PackageEdit>().Add(edit);
// Note: EditPackageRequests are completed asynchronously by the worker role.
}
示例7: GetUserProfiles
public IEnumerable<UserSiteProfile> GetUserProfiles(User user)
{
return profileRepo.GetAll().Where(x => x.Username == user.Username).ToList();
//return (from p in profileRepo.GetAll()
// where p.Username == user.Username
// select p).ToList();
}
示例8: 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);
}
示例9: ChangeEmailSubscription
public void ChangeEmailSubscription(User user, bool emailAllowed)
{
if (user == null)
{
throw new ArgumentNullException("user");
}
user.EmailAllowed = emailAllowed;
UserRepository.CommitChanges();
}
示例10: ChangeEmailAddress
public void ChangeEmailAddress(User user, string newEmailAddress)
{
var existingUsers = FindAllByEmailAddress(newEmailAddress);
if (existingUsers.AnySafe(u => u.Key != user.Key))
{
throw new EntityException(Strings.EmailAddressBeingUsed, newEmailAddress);
}
user.UpdateEmailAddress(newEmailAddress, Crypto.GenerateToken);
UserRepository.CommitChanges();
}
示例11: ChangeEmailSubscriptionAsync
public async Task ChangeEmailSubscriptionAsync(User user, bool emailAllowed, bool notifyPackagePushed)
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
user.EmailAllowed = emailAllowed;
user.NotifyPackagePushed = notifyPackagePushed;
await UserRepository.CommitChangesAsync();
}
示例12: AddPackageOwner
public void AddPackageOwner(PackageRegistration package, User user)
{
package.Owners.Add(user);
packageRepo.CommitChanges();
var request = FindExistingPackageOwnerRequest(package, user);
if (request != null)
{
packageOwnerRequestRepository.DeleteOnCommit(request);
packageOwnerRequestRepository.CommitChanges();
}
}
示例13: ThrowsForDuplicateConfirmedEmailAddresses
public async Task ThrowsForDuplicateConfirmedEmailAddresses()
{
var user = new User { Username = "User1", Key = 1, EmailAddress = "[email protected]", UnconfirmedEmailAddress = "[email protected]", EmailConfirmationToken = "token" };
var conflictingUser = new User { Username = "User2", Key = 2, EmailAddress = "[email protected]" };
var service = new TestableUserServiceWithDBFaking
{
Users = new[] { user, conflictingUser }
};
var ex = await AssertEx.Throws<EntityException>(() => service.ConfirmEmailAddress(user, "token"));
Assert.Equal(String.Format(Strings.EmailAddressBeingUsed, "[email protected]"), ex.Message);
}
示例14: IsInRoleReturnsCorrectValue
public void IsInRoleReturnsCorrectValue(string expectedRole, bool isInRole)
{
// Arrange
var user = new User("testuser");
user.Roles.Add(new Role { Key = 1, Name = "Admins" });
// Act
var result = user.IsInRole(expectedRole);
// Assert
Assert.True(result == isInRole);
}
示例15: SoftDeletePackagesAsync
public async Task SoftDeletePackagesAsync(IEnumerable<Package> packages, User deletedBy, string reason, string signature)
{
EntitiesConfiguration.SuspendExecutionStrategy = true;
using (var transaction = _entitiesContext.GetDatabase().BeginTransaction())
{
// Increase command timeout
_entitiesContext.SetCommandTimeout(seconds: 300);
// Keep package registrations
var packageRegistrations = packages
.GroupBy(p => p.PackageRegistration)
.Select(g => g.First().PackageRegistration)
.ToList();
// Backup the package binaries and remove from main storage
// We're doing this early in the process as we need the metadata to still exist in the DB.
await BackupPackageBinaries(packages);
// Store the soft delete in the database
var packageDelete = new PackageDelete
{
DeletedOn = DateTime.UtcNow,
DeletedBy = deletedBy,
Reason = reason,
Signature = signature
};
foreach (var package in packages)
{
package.Listed = false;
package.Deleted = true;
packageDelete.Packages.Add(package);
await _auditingService.SaveAuditRecord(CreateAuditRecord(package, package.PackageRegistration, AuditedPackageAction.SoftDelete, reason));
}
_packageDeletesRepository.InsertOnCommit(packageDelete);
// Update latest versions
await UpdateIsLatestAsync(packageRegistrations);
// Commit changes
await _packageRepository.CommitChangesAsync();
await _packageDeletesRepository.CommitChangesAsync();
transaction.Commit();
}
EntitiesConfiguration.SuspendExecutionStrategy = false;
// Force refresh the index
UpdateSearchIndex();
}