예제 #1
0
        public async Task GetInstalledPackagesAsync_WhenArgumentsAreValid_ReturnsInstalledPackages()
        {
            var    serviceBroker         = new Mock <IServiceBroker>();
            var    projectManagerService = new Mock <INuGetProjectManagerService>();
            var    project        = new Mock <IProjectContextInfo>();
            string projectId      = Guid.NewGuid().ToString();
            var    expectedResult = new List <IPackageReferenceContextInfo>();

            project.SetupGet(x => x.ProjectId)
            .Returns(projectId);

            projectManagerService.Setup(
                x => x.GetInstalledPackagesAsync(
                    It.Is <string[]>(projectIds => projectIds.Length == 1 && string.Equals(projectId, projectIds[0])),
                    It.IsAny <CancellationToken>()))
            .Returns(new ValueTask <IReadOnlyCollection <IPackageReferenceContextInfo> >(expectedResult));

            serviceBroker.Setup(
#pragma warning disable ISB001 // Dispose of proxies
                x => x.GetProxyAsync <INuGetProjectManagerService>(
                    It.Is <ServiceRpcDescriptor>(descriptor => descriptor == NuGetServices.ProjectManagerService),
                    It.IsAny <ServiceActivationOptions>(),
                    It.IsAny <CancellationToken>()))
#pragma warning restore ISB001 // Dispose of proxies
            .Returns(new ValueTask <INuGetProjectManagerService>(projectManagerService.Object));

            IReadOnlyCollection <IPackageReferenceContextInfo> actualResult = await IProjectContextInfoExtensions.GetInstalledPackagesAsync(
                project.Object,
                serviceBroker.Object,
                CancellationToken.None);

            Assert.Same(expectedResult, actualResult);
        }
예제 #2
0
 public async Task GetInstalledPackagesAsync_WhenProjectContextInfoIsNull_Throws()
 {
     await VerifyMicrosoftAssumesExceptionAsync(
         () => IProjectContextInfoExtensions.GetInstalledPackagesAsync(
             projectContextInfo : null,
             Mock.Of <IServiceBroker>(),
             CancellationToken.None)
         .AsTask());
 }
예제 #3
0
 public async Task GetInstalledPackagesAsync_WhenCancellationTokenIsCancelled_Throws()
 {
     await Assert.ThrowsAsync <OperationCanceledException>(
         () => IProjectContextInfoExtensions.GetInstalledPackagesAsync(
             Mock.Of <IProjectContextInfo>(),
             Mock.Of <IServiceBroker>(),
             new CancellationToken(canceled: true))
         .AsTask());
 }