当前位置: 首页>>代码示例>>C#>>正文


C# TestableApiController.SetCurrentUser方法代码示例

本文整理汇总了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();
            }
开发者ID:atrevisan,项目名称:NuGetGallery,代码行数:21,代码来源:ApiControllerFacts.cs

示例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());
            }
开发者ID:segilbert,项目名称:NuGetGallery,代码行数:14,代码来源:ApiControllerFacts.cs

示例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();
            }
开发者ID:segilbert,项目名称:NuGetGallery,代码行数:22,代码来源:ApiControllerFacts.cs

示例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();
            }
开发者ID:segilbert,项目名称:NuGetGallery,代码行数:16,代码来源:ApiControllerFacts.cs

示例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();
            }
开发者ID:heneryville,项目名称:NuGetGallery,代码行数:21,代码来源:ApiControllerFacts.cs

示例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);
            }
开发者ID:segilbert,项目名称:NuGetGallery,代码行数:19,代码来源:ApiControllerFacts.cs

示例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));
            }
开发者ID:segilbert,项目名称:NuGetGallery,代码行数:21,代码来源:ApiControllerFacts.cs

示例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);
            }
开发者ID:ZhiYuanHuang,项目名称:NuGetGallery,代码行数:23,代码来源:ApiControllerFacts.cs

示例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();
            }
开发者ID:ZhiYuanHuang,项目名称:NuGetGallery,代码行数:28,代码来源:ApiControllerFacts.cs

示例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));
            }
开发者ID:ZhiYuanHuang,项目名称:NuGetGallery,代码行数:29,代码来源:ApiControllerFacts.cs

示例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();
            }
开发者ID:ryanspletzer,项目名称:NuGetGallery,代码行数:16,代码来源:ApiControllerFacts.cs

示例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));
            }
开发者ID:rhysawilliams2010,项目名称:NuGetGallery,代码行数:30,代码来源:ApiControllerFacts.cs

示例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());
            }
开发者ID:segilbert,项目名称:NuGetGallery,代码行数:20,代码来源:ApiControllerFacts.cs

示例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));
            }
开发者ID:ZhiYuanHuang,项目名称:NuGetGallery,代码行数:28,代码来源:ApiControllerFacts.cs

示例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));
            }
开发者ID:segilbert,项目名称:NuGetGallery,代码行数:16,代码来源:ApiControllerFacts.cs


注:本文中的NuGetGallery.TestableApiController.SetCurrentUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。