本文整理汇总了C#中NuGetGallery.TestableApiController.SetCurrentUser方法的典型用法代码示例。如果您正苦于以下问题:C# TestableApiController.SetCurrentUser方法的具体用法?C# TestableApiController.SetCurrentUser怎么用?C# TestableApiController.SetCurrentUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NuGetGallery.TestableApiController
的用法示例。
在下文中一共展示了TestableApiController.SetCurrentUser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatePackageWillSavePackageFileToFileStorage
public async Task CreatePackageWillSavePackageFileToFileStorage()
{
// Arrange
var user = new User() { EmailAddress = "[email protected]" };
var packageRegistration = new PackageRegistration();
packageRegistration.Owners.Add(user);
var controller = new TestableApiController();
controller.SetCurrentUser(user);
controller.MockPackageFileService.Setup(p => p.SavePackageFileAsync(It.IsAny<Package>(), It.IsAny<Stream>())).Returns(Task.FromResult(0)).Verifiable();
controller.MockPackageService.Setup(p => p.FindPackageRegistrationById(It.IsAny<string>())).Returns(packageRegistration);
var nuGetPackage = TestPackage.CreateTestPackageStream("theId", "1.0.42");
controller.SetupPackageFromInputStream(nuGetPackage);
// Act
await controller.CreatePackagePut();
// Assert
controller.MockPackageFileService.Verify();
}
示例2: WillThrowIfAPackageWithTheIdAndSemanticVersionDoesNotExist
public void WillThrowIfAPackageWithTheIdAndSemanticVersionDoesNotExist()
{
var controller = new TestableApiController();
controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion("theId", "1.0.42", true)).Returns((Package)null);
controller.SetCurrentUser(new User());
var result = controller.DeletePackage("theId", "1.0.42");
Assert.IsType<HttpStatusCodeWithBodyResult>(result);
var statusCodeResult = (HttpStatusCodeWithBodyResult)result;
Assert.Equal(404, statusCodeResult.StatusCode);
Assert.Equal(String.Format(Strings.PackageWithIdAndVersionNotFound, "theId", "1.0.42"), statusCodeResult.StatusDescription);
controller.MockPackageService.Verify(x => x.MarkPackageUnlisted(It.IsAny<Package>(), true), Times.Never());
}
示例3: CreatePackageDoesNotRefreshNuGetExeIfItIsNotLatestStable
public void CreatePackageDoesNotRefreshNuGetExeIfItIsNotLatestStable()
{
// Arrange
var nuGetPackage = new Mock<INupkg>();
nuGetPackage.Setup(x => x.Metadata.Id).Returns("NuGet.CommandLine");
nuGetPackage.Setup(x => x.Metadata.Version).Returns(new SemanticVersion("2.0.0-alpha"));
var user = new User() { EmailAddress = "[email protected]" };
var controller = new TestableApiController();
var apiKey = Guid.NewGuid();
controller.MockPackageService.Setup(p => p.CreatePackage(nuGetPackage.Object, It.IsAny<User>(), false))
.Returns(new Package { IsLatest = true, IsLatestStable = false });
controller.MockNuGetExeDownloaderService.Setup(s => s.UpdateExecutableAsync(nuGetPackage.Object)).Verifiable();
controller.SetCurrentUser(user);
controller.SetupPackageFromInputStream(nuGetPackage);
// Act
controller.CreatePackagePut();
// Assert
controller.MockNuGetExeDownloaderService.Verify(s => s.UpdateExecutableAsync(It.IsAny<INupkg>()), Times.Never());
controller.MockEntitiesContext.VerifyCommitted();
}
示例4: WillCreateAPackageWithTheUserMatchingTheApiKey
public void WillCreateAPackageWithTheUserMatchingTheApiKey()
{
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 user = new User() { EmailAddress = "[email protected]" };
var controller = new TestableApiController();
var apiKey = Guid.NewGuid();
controller.SetCurrentUser(user);
controller.SetupPackageFromInputStream(nuGetPackage);
controller.CreatePackagePut();
controller.MockPackageService.Verify(x => x.CreatePackage(It.IsAny<INupkg>(), user, false));
controller.MockEntitiesContext.VerifyCommitted();
}
示例5: CreatePackageRefreshesNuGetExeIfCommandLinePackageIsUploaded
public void CreatePackageRefreshesNuGetExeIfCommandLinePackageIsUploaded()
{
// Arrange
var nuGetPackage = new Mock<INupkg>();
nuGetPackage.Setup(x => x.Metadata.Id).Returns("NuGet.CommandLine");
nuGetPackage.Setup(x => x.Metadata.Version).Returns(new SemanticVersion("1.0.42"));
var user = new User() { EmailAddress = "[email protected]" };
var controller = new TestableApiController();
var apiKey = Guid.NewGuid();
controller.MockPackageService.Setup(p => p.CreatePackage(nuGetPackage.Object, It.IsAny<User>(), true))
.Returns(new Package { IsLatestStable = true });
controller.MockNuGetExeDownloaderService.Setup(s => s.UpdateExecutableAsync(nuGetPackage.Object)).Verifiable();
controller.SetCurrentUser(user);
controller.SetupPackageFromInputStream(nuGetPackage);
// Act
controller.CreatePackagePut();
// Assert
controller.MockNuGetExeDownloaderService.Verify();
}
示例6: VerifyPackageKeyReturns403IfUserIsNotAnOwner
public void VerifyPackageKeyReturns403IfUserIsNotAnOwner()
{
// Arrange
var controller = new TestableApiController();
var owner = new User();
var nonOwner = new User();
controller.SetCurrentUser(nonOwner);
controller.MockPackageService.Setup(s => s.FindPackageByIdAndVersion("foo", "1.0.0", true)).Returns(
new Package { PackageRegistration = new PackageRegistration() });
// Act
var result = controller.VerifyPackageKey("foo", "1.0.0");
// Assert
ResultAssert.IsStatusCode(
result,
HttpStatusCode.Forbidden,
Strings.ApiKeyNotAuthorized);
}
示例7: WillListThePackageIfUserIsAnOwner
public void WillListThePackageIfUserIsAnOwner()
{
// Arrange
var owner = new User { Key = 1 };
var package = new Package
{
PackageRegistration = new PackageRegistration { Owners = new[] { new User(), owner } }
};
var controller = new TestableApiController();
controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion(It.IsAny<string>(), It.IsAny<string>(), true)).Returns(package);
controller.SetCurrentUser(owner);
// Act
var result = controller.PublishPackage("theId", "1.0.42");
// Assert
ResultAssert.IsEmpty(result);
controller.MockPackageService.Verify(x => x.MarkPackageListed(package, It.IsAny<bool>()));
controller.MockIndexingService.Verify(i => i.UpdatePackage(package));
}
示例8: CreatePackageWillReturn400IfPackageIsInvalid
public async Task CreatePackageWillReturn400IfPackageIsInvalid()
{
// Arrange
var user = new User() { EmailAddress = "[email protected]" };
var packageRegistration = new PackageRegistration();
packageRegistration.Owners.Add(user);
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);
byte[] data = new byte[100];
controller.SetupPackageFromInputStream(new MemoryStream(data));
// Act
ActionResult result = await controller.CreatePackagePut();
// Assert
ResultAssert.IsStatusCode(result, HttpStatusCode.BadRequest);
}
示例9: CreatePackageWillSendPackageAddedNotice
public async Task CreatePackageWillSendPackageAddedNotice()
{
// 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.MockMessageService.Setup(p => p.SendPackageAddedNotice(package, It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.Verifiable();
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.MockMessageService.Verify();
}
示例10: WritesAnAuditRecord
public async Task WritesAnAuditRecord()
{
// 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.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
Assert.True(controller.AuditingService.WroteRecord<PackageAuditRecord>(ar =>
ar.Action == AuditedPackageAction.Create
&& ar.Id == package.PackageRegistration.Id
&& ar.Version == package.Version));
}
示例11: WillCurateThePackageViaAPI
public void WillCurateThePackageViaAPI()
{
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 user = new User() { EmailAddress = "[email protected]" };
var controller = new TestableApiController();
var apiKey = Guid.NewGuid();
controller.SetCurrentUser(user);
controller.SetupPackageFromInputStream(nuGetPackage);
controller.CreatePackagePost();
controller.MockAutoCuratePackage.Verify(x => x.Execute(It.IsAny<Package>(), nuGetPackage.Object, false));
controller.MockEntitiesContext.VerifyCommitted();
}
示例12: WillReturnConflictIfAPackageWithTheIdExistsBelongingToAnotherUser
public async Task WillReturnConflictIfAPackageWithTheIdExistsBelongingToAnotherUser()
{
// Arrange
var user = new User { EmailAddress = "[email protected]" };
var packageId = "theId";
var packageRegistration = new PackageRegistration();
packageRegistration.Id = packageId;
var package = new Package();
package.PackageRegistration = packageRegistration;
package.Version = "1.0.42";
packageRegistration.Packages.Add(package);
var controller = new TestableApiController();
controller.SetCurrentUser(user);
controller.MockPackageService.Setup(p => p.FindPackageRegistrationById(It.IsAny<string>()))
.Returns(packageRegistration);
var nuGetPackage = TestPackage.CreateTestPackageStream(packageId, "1.0.42");
controller.SetCurrentUser(new User());
controller.SetupPackageFromInputStream(nuGetPackage);
// Act
var result = await controller.CreatePackagePut();
// Assert
ResultAssert.IsStatusCode(
result,
HttpStatusCode.Conflict,
String.Format(Strings.PackageIdNotAvailable, packageId));
}
示例13: WillNotDeleteThePackageIfApiKeyDoesNotBelongToAnOwner
public void WillNotDeleteThePackageIfApiKeyDoesNotBelongToAnOwner()
{
var notOwner = new User { Key = 1 };
var package = new Package
{
PackageRegistration = new PackageRegistration { Owners = new[] { new User() } }
};
var apiKey = Guid.NewGuid();
var controller = new TestableApiController();
controller.SetCurrentUser(notOwner);
controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion("theId", "1.0.42", true)).Returns(package);
var result = controller.DeletePackage("theId", "1.0.42");
Assert.IsType<HttpStatusCodeWithBodyResult>(result);
var statusCodeResult = (HttpStatusCodeWithBodyResult)result;
Assert.Equal(String.Format(Strings.ApiKeyNotAuthorized, "delete"), statusCodeResult.StatusDescription);
controller.MockPackageService.Verify(x => x.MarkPackageUnlisted(package, true), Times.Never());
}
示例14: WillWriteAnAuditRecordIfUserIsNotPackageOwner
public async Task WillWriteAnAuditRecordIfUserIsNotPackageOwner()
{
// Arrange
var user = new User { EmailAddress = "[email protected]" };
var packageRegistration = new PackageRegistration();
packageRegistration.Id = "theId";
var package = new Package();
package.PackageRegistration = packageRegistration;
package.Version = "1.0.42";
packageRegistration.Packages.Add(package);
var controller = new TestableApiController();
controller.SetCurrentUser(user);
controller.MockPackageService.Setup(p => p.FindPackageRegistrationById(It.IsAny<string>()))
.Returns(packageRegistration);
var nuGetPackage = TestPackage.CreateTestPackageStream("theId", "1.0.42");
controller.SetupPackageFromInputStream(nuGetPackage);
// Act
await controller.CreatePackagePut();
// Assert
Assert.True(controller.AuditingService.WroteRecord<FailedAuthenticatedOperationAuditRecord>(ar =>
ar.Action == AuditedAuthenticatedOperationAction.PackagePushAttemptByNonOwner
&& ar.AttemptedPackage.Id == package.PackageRegistration.Id
&& ar.AttemptedPackage.Version == package.Version));
}
示例15: WillUnlistThePackageIfApiKeyBelongsToAnOwner
public void WillUnlistThePackageIfApiKeyBelongsToAnOwner()
{
var owner = new User { Key = 1 };
var package = new Package
{
PackageRegistration = new PackageRegistration { Owners = new[] { new User(), owner } }
};
var controller = new TestableApiController();
controller.MockPackageService.Setup(x => x.FindPackageByIdAndVersion(It.IsAny<string>(), It.IsAny<string>(), true)).Returns(package);
controller.SetCurrentUser(owner);
ResultAssert.IsEmpty(controller.DeletePackage("theId", "1.0.42"));
controller.MockPackageService.Verify(x => x.MarkPackageUnlisted(package, true));
controller.MockIndexingService.Verify(i => i.UpdatePackage(package));
}