本文整理汇总了C#中NuGetGallery.TestableApiController.CreatePackagePut方法的典型用法代码示例。如果您正苦于以下问题:C# TestableApiController.CreatePackagePut方法的具体用法?C# TestableApiController.CreatePackagePut怎么用?C# TestableApiController.CreatePackagePut使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NuGetGallery.TestableApiController
的用法示例。
在下文中一共展示了TestableApiController.CreatePackagePut方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: WillFindUserUsingFindByApiKey
public async Task WillFindUserUsingFindByApiKey()
{
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();
var apiKey = Guid.NewGuid();
var controller = new TestableApiController();
controller.MockUserService.Setup(x => x.FindByApiKey(apiKey)).Returns(user);
controller.SetupPackageFromInputStream(nuGetPackage);
ResultAssert.IsStatusCode(
await controller.CreatePackagePut(apiKey.ToString()),
HttpStatusCode.Created);
controller.MockPackageService.Verify(p =>
p.CreatePackage(nuGetPackage.Object, user, true));
}
示例3: WillReturn401IfTheApiKeyDoesNotExist
public async Task WillReturn401IfTheApiKeyDoesNotExist()
{
var controller = new TestableApiController();
controller.MockUserService.Setup(x => x.FindByApiKey(It.IsAny<Guid>())).Returns((User)null);
// Act
var result = await controller.CreatePackagePut(Guid.NewGuid().ToString());
// Assert
Assert.IsType<HttpStatusCodeWithBodyResult>(result);
var statusCodeResult = (HttpStatusCodeWithBodyResult)result;
Assert.Equal(String.Format(Strings.ApiKeyNotAuthorized, "push"), statusCodeResult.StatusDescription);
}
示例4: WillCreateAPackageWithTheUserMatchingTheApiKey
public void WillCreateAPackageWithTheUserMatchingTheApiKey()
{
var nuGetPackage = TestPackage.CreateTestPackageStream("theId", "1.0.42");
var user = new User() { EmailAddress = "[email protected]" };
var controller = new TestableApiController();
controller.SetCurrentUser(user);
controller.SetupPackageFromInputStream(nuGetPackage);
controller.CreatePackagePut();
controller.MockPackageService.Verify(x => x.CreatePackageAsync(It.IsAny<PackageArchiveReader>(), It.IsAny<PackageStreamMetadata>(), user, false));
controller.MockEntitiesContext.VerifyCommitted();
}
示例5: WillReturnConflictIfAPackageWithTheIdAndSameNormalizedVersionAlreadyExists
public async Task WillReturnConflictIfAPackageWithTheIdAndSameNormalizedVersionAlreadyExists()
{
var version = new SemanticVersion("1.0.042");
var nuGetPackage = new Mock<INupkg>();
nuGetPackage.Setup(x => x.Metadata.Id).Returns("theId");
nuGetPackage.Setup(x => x.Metadata.Version).Returns(version);
var user = new User() { EmailAddress = "[email protected]" };
var packageRegistration = new PackageRegistration
{
Packages = new List<Package> { new Package { Version = "01.00.42", NormalizedVersion = "1.0.42" } },
Owners = new List<User> { user }
};
var controller = new TestableApiController();
controller.SetCurrentUser(new User());
controller.MockPackageService.Setup(x => x.FindPackageRegistrationById("theId")).Returns(packageRegistration);
controller.SetupPackageFromInputStream(nuGetPackage);
// Act
var result = await controller.CreatePackagePut();
// Assert
ResultAssert.IsStatusCode(
result,
HttpStatusCode.Conflict,
String.Format(Strings.PackageExistsAndCannotBeModified, "theId", "1.0.42"));
}
示例6: 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();
}
示例7: 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));
}
示例8: 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 matchingUser = new User() { EmailAddress = "[email protected]" };
var controller = new TestableApiController();
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.MockUserService.Setup(x => x.FindByApiKey(It.IsAny<Guid>())).Returns(matchingUser);
controller.SetupPackageFromInputStream(nuGetPackage);
// Act
controller.CreatePackagePut(Guid.NewGuid().ToString());
// Assert
controller.MockNuGetExeDownloaderService.Verify();
}
示例9: 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 matchingUser = new User();
var controller = new TestableApiController();
controller.MockPackageService.Setup(p => p.CreatePackage(nuGetPackage.Object, It.IsAny<User>(), true))
.Returns(new Package { IsLatest = true, IsLatestStable = false });
controller.MockNuGetExeDownloaderService.Setup(s => s.UpdateExecutableAsync(nuGetPackage.Object)).Verifiable();
controller.MockUserService.Setup(x => x.FindByApiKey(It.IsAny<Guid>())).Returns(matchingUser);
controller.SetupPackageFromInputStream(nuGetPackage);
// Act
controller.CreatePackagePut(Guid.NewGuid().ToString());
// Assert
controller.MockNuGetExeDownloaderService.Verify(s => s.UpdateExecutableAsync(It.IsAny<INupkg>()), Times.Never());
}
示例10: CreatePackageWillSavePackageFileToFileStorage
public async Task CreatePackageWillSavePackageFileToFileStorage()
{
// Arrange
var guid = Guid.NewGuid().ToString();
var fakeUser = new User();
var userService = new Mock<IUserService>();
var packageRegistration = new PackageRegistration();
packageRegistration.Owners.Add(fakeUser);
var controller = new TestableApiController();
controller.MockPackageFileService.Setup(p => p.SavePackageFileAsync(It.IsAny<Package>(), It.IsAny<Stream>())).Returns(Task.FromResult(0)).Verifiable();
controller.MockUserService.Setup(x => x.FindByApiKey(It.IsAny<Guid>())).Returns(fakeUser);
controller.MockPackageService.Setup(p => p.FindPackageRegistrationById(It.IsAny<string>())).Returns(packageRegistration);
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"));
controller.SetupPackageFromInputStream(nuGetPackage);
// Act
await controller.CreatePackagePut(guid);
// Assert
controller.MockPackageFileService.Verify();
}
示例11: WillCreateAPackageFromTheNuGetPackage
public void WillCreateAPackageFromTheNuGetPackage()
{
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 = new TestableApiController();
controller.MockUserService.Setup(x => x.FindByApiKey(It.IsAny<Guid>())).Returns(new User());
controller.SetupPackageFromInputStream(nuGetPackage);
controller.CreatePackagePut(Guid.NewGuid().ToString());
controller.MockPackageService.Verify(x => x.CreatePackage(nuGetPackage.Object, It.IsAny<User>(), true));
}
示例12: WillReturnConflictIfAPackageWithTheIdAndSemanticVersionAlreadyExists
public async Task WillReturnConflictIfAPackageWithTheIdAndSemanticVersionAlreadyExists()
{
var version = new SemanticVersion("1.0.42");
var nuGetPackage = new Mock<INupkg>();
nuGetPackage.Setup(x => x.Metadata.Id).Returns("theId");
nuGetPackage.Setup(x => x.Metadata.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 controller = new TestableApiController();
controller.MockPackageService.Setup(x => x.FindPackageRegistrationById(It.IsAny<string>())).Returns(packageRegistration);
controller.MockUserService.Setup(x => x.FindByApiKey(It.IsAny<Guid>())).Returns(user);
controller.SetupPackageFromInputStream(nuGetPackage);
// Act
var result = await 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);
}
示例13: WillReturn401IfTheApiKeyIsNotAValidGuid
public async Task WillReturn401IfTheApiKeyIsNotAValidGuid(string guid)
{
var controller = new TestableApiController();
// Act
var result = await controller.CreatePackagePut(guid);
// Assert
Assert.IsType<HttpStatusCodeWithBodyResult>(result);
var statusCodeResult = (HttpStatusCodeWithBodyResult)result;
Assert.Equal(String.Format(Strings.InvalidApiKey, guid), statusCodeResult.StatusDescription);
}
示例14: WillUseUserFoundByAuthenticateCredentialOverFindByApiKey
public async Task WillUseUserFoundByAuthenticateCredentialOverFindByApiKey()
{
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 correctUser = new User();
var incorrectUser = new User();
var apiKey = Guid.NewGuid();
var controller = new TestableApiController();
controller.MockUserService
.Setup(x => x.AuthenticateCredential(
CredentialTypes.ApiKeyV1,
apiKey.ToString().ToLowerInvariant()))
.Returns(new Credential() { User = correctUser });
controller.MockUserService
.Setup(x => x.FindByApiKey(apiKey))
.Returns(incorrectUser);
controller.SetupPackageFromInputStream(nuGetPackage);
ResultAssert.IsStatusCode(
await controller.CreatePackagePut(apiKey.ToString().ToUpperInvariant()),
HttpStatusCode.Created);
controller.MockPackageService.Verify(p =>
p.CreatePackage(nuGetPackage.Object, correctUser, true));
}
示例15: 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));
}