當前位置: 首頁>>代碼示例>>C#>>正文


C# TestableApiController.CreatePackagePut方法代碼示例

本文整理匯總了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();
            }
開發者ID:ZhiYuanHuang,項目名稱:NuGetGallery,代碼行數:30,代碼來源:ApiControllerFacts.cs

示例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));
            }
開發者ID:nicholaspei,項目名稱:NuGetGallery,代碼行數:20,代碼來源:ApiControllerFacts.cs

示例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);
            }
開發者ID:BryanAvery,項目名稱:NuGetGallery,代碼行數:13,代碼來源:ApiControllerFacts.cs

示例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();
            }
開發者ID:ZhiYuanHuang,項目名稱:NuGetGallery,代碼行數:14,代碼來源:ApiControllerFacts.cs

示例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"));
            }
開發者ID:segilbert,項目名稱:NuGetGallery,代碼行數:29,代碼來源:ApiControllerFacts.cs

示例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();
            }
開發者ID:segilbert,項目名稱:NuGetGallery,代碼行數:22,代碼來源:ApiControllerFacts.cs

示例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));
            }
開發者ID:rhysawilliams2010,項目名稱:NuGetGallery,代碼行數:30,代碼來源:ApiControllerFacts.cs

示例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();
            }
開發者ID:nicholaspei,項目名稱:NuGetGallery,代碼行數:20,代碼來源:ApiControllerFacts.cs

示例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());
            }
開發者ID:BryanAvery,項目名稱:NuGetGallery,代碼行數:20,代碼來源:ApiControllerFacts.cs

示例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();
            }
開發者ID:BryanAvery,項目名稱:NuGetGallery,代碼行數:25,代碼來源:ApiControllerFacts.cs

示例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));
            }
開發者ID:BryanAvery,項目名稱:NuGetGallery,代碼行數:14,代碼來源:ApiControllerFacts.cs

示例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);
            }
開發者ID:BryanAvery,項目名稱:NuGetGallery,代碼行數:29,代碼來源:ApiControllerFacts.cs

示例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);
            }
開發者ID:BryanAvery,項目名稱:NuGetGallery,代碼行數:12,代碼來源:ApiControllerFacts.cs

示例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));
            }
開發者ID:nicholaspei,項目名稱:NuGetGallery,代碼行數:29,代碼來源:ApiControllerFacts.cs

示例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));
            }
開發者ID:ZhiYuanHuang,項目名稱:NuGetGallery,代碼行數:29,代碼來源:ApiControllerFacts.cs


注:本文中的NuGetGallery.TestableApiController.CreatePackagePut方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。