Exemplo n.º 1
0
        public async Task IsUpgradeableAsync_WhenArgumentsAreValid_ReturnsBoolean(bool expectedResult)
        {
            var    serviceBroker          = new Mock <IServiceBroker>();
            var    projectUpgraderService = new Mock <INuGetProjectUpgraderService>();
            var    project   = new Mock <IProjectContextInfo>();
            string projectId = Guid.NewGuid().ToString();

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

            projectUpgraderService.Setup(
                x => x.IsProjectUpgradeableAsync(
                    It.Is <string>(id => string.Equals(projectId, id)),
                    It.IsAny <CancellationToken>()))
            .Returns(new ValueTask <bool>(expectedResult));

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

            bool actualResult = await IProjectContextInfoExtensions.IsUpgradeableAsync(
                project.Object,
                serviceBroker.Object,
                CancellationToken.None);

            Assert.Equal(expectedResult, actualResult);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
 public async Task GetInstalledPackagesAsync_WhenProjectContextInfoIsNull_Throws()
 {
     await VerifyMicrosoftAssumesExceptionAsync(
         () => IProjectContextInfoExtensions.GetInstalledPackagesAsync(
             projectContextInfo : null,
             Mock.Of <IServiceBroker>(),
             CancellationToken.None)
         .AsTask());
 }
Exemplo n.º 4
0
 public async Task IsUpgradeableAsync_WhenCancellationTokenIsCancelled_Throws()
 {
     await Assert.ThrowsAsync <OperationCanceledException>(
         () => IProjectContextInfoExtensions.IsUpgradeableAsync(
             Mock.Of <IProjectContextInfo>(),
             Mock.Of <IServiceBroker>(),
             new CancellationToken(canceled: true))
         .AsTask());
 }
Exemplo n.º 5
0
 public async Task GetAllPackagesFolderAsync_WhenCancellationTokenIsCancelled_ThrowsAsync()
 {
     await Assert.ThrowsAsync <OperationCanceledException>(
         () => IProjectContextInfoExtensions.GetPackageFoldersAsync(
             Mock.Of <IProjectContextInfo>(),
             Mock.Of <IServiceBroker>(),
             new CancellationToken(canceled: true))
         .AsTask());
 }
Exemplo n.º 6
0
 public async Task IsUpgradeableAsync_WhenServiceBrokerIsNull_Throws()
 {
     await VerifyMicrosoftAssumesExceptionAsync(
         () => IProjectContextInfoExtensions.IsUpgradeableAsync(
             Mock.Of <IProjectContextInfo>(),
             serviceBroker : null,
             CancellationToken.None)
         .AsTask());
 }
Exemplo n.º 7
0
 public async Task TryGetInstalledPackageFilePathAsync_WhenCancellationTokenIsCancelled_Throws()
 {
     await Assert.ThrowsAsync <OperationCanceledException>(
         () => IProjectContextInfoExtensions.TryGetInstalledPackageFilePathAsync(
             Mock.Of <IProjectContextInfo>(),
             Mock.Of <IServiceBroker>(),
             PackageIdentity,
             new CancellationToken(canceled: true))
         .AsTask());
 }
Exemplo n.º 8
0
 public async Task TryGetInstalledPackageFilePathAsync_WhenPackageIdentityIsNull_Throws()
 {
     await VerifyMicrosoftAssumesExceptionAsync(
         () => IProjectContextInfoExtensions.TryGetInstalledPackageFilePathAsync(
             Mock.Of <IProjectContextInfo>(),
             Mock.Of <IServiceBroker>(),
             packageIdentity : null,
             CancellationToken.None)
         .AsTask());
 }
Exemplo n.º 9
0
        public async Task GetUniqueNameOrNameAsync_WhenArgumentsAreValid_ReturnsString(
            string uniqueName,
            string name)
        {
            var    serviceBroker         = new Mock <IServiceBroker>();
            var    projectManagerService = new Mock <INuGetProjectManagerService>();
            var    project         = new Mock <IProjectContextInfo>();
            string projectId       = Guid.NewGuid().ToString();
            var    projectMetadata = new Mock <IProjectMetadataContextInfo>();

            projectMetadata.SetupGet(x => x.Name)
            .Returns(name);

            projectMetadata.SetupGet(x => x.UniqueName)
            .Returns(uniqueName);

            string expectedResult = uniqueName ?? name;

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

            projectManagerService.Setup(
                x => x.GetMetadataAsync(
                    It.Is <string>(id => string.Equals(projectId, id)),
                    It.IsAny <CancellationToken>()))
            .Returns(new ValueTask <IProjectMetadataContextInfo>(projectMetadata.Object));

            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));

            string actualResult = await IProjectContextInfoExtensions.GetUniqueNameOrNameAsync(
                project.Object,
                serviceBroker.Object,
                CancellationToken.None);

            Assert.Equal(expectedResult, actualResult);
        }
Exemplo n.º 10
0
        public async Task GetPackageFoldersAsync_OneProject_ReturnsPackageFolderAsync(IReadOnlyCollection <string> folderCollection, int expected)
        {
            var serviceBroker         = Mock.Of <IServiceBroker>();
            var projectManagerService = Mock.Of <INuGetProjectManagerService>();
            var project = Mock.Of <IProjectContextInfo>();

            _ = Mock.Get(serviceBroker)
                .Setup(sb => sb.GetProxyAsync <INuGetProjectManagerService>(
                           It.Is <ServiceRpcDescriptor>(descriptor => descriptor == NuGetServices.ProjectManagerService),
                           It.IsAny <ServiceActivationOptions>(),
                           It.IsAny <CancellationToken>()))
                .Returns(new ValueTask <INuGetProjectManagerService>(projectManagerService));

            Mock.Get(projectManagerService)
            .Setup(prj => prj.GetPackageFoldersAsync(It.IsAny <IReadOnlyCollection <string> >(), It.IsAny <CancellationToken>()))
            .Returns(new ValueTask <IReadOnlyCollection <string> >(folderCollection));

            IReadOnlyCollection <string> folders = await IProjectContextInfoExtensions.GetPackageFoldersAsync(project, serviceBroker, CancellationToken.None);

            Assert.NotNull(folders);
            Assert.Equal(expected, folders.Count);
        }
Exemplo n.º 11
0
        public async Task TryGetInstalledPackageFilePathAsync_WhenArgumentsAreValid_ReturnsString()
        {
            var    serviceBroker         = new Mock <IServiceBroker>();
            var    projectManagerService = new Mock <INuGetProjectManagerService>();
            var    project   = new Mock <IProjectContextInfo>();
            string projectId = Guid.NewGuid().ToString();

            (bool, string)expectedResult = (true, "a");

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

            projectManagerService.Setup(
                x => x.TryGetInstalledPackageFilePathAsync(
                    It.Is <string>(id => string.Equals(projectId, id)),
                    It.Is <PackageIdentity>(pi => ReferenceEquals(PackageIdentity, pi)),
                    It.IsAny <CancellationToken>()))
            .Returns(new ValueTask <(bool, string)>(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));

            (bool, string)actualResult = await IProjectContextInfoExtensions.TryGetInstalledPackageFilePathAsync(
                project.Object,
                serviceBroker.Object,
                PackageIdentity,
                CancellationToken.None);

            Assert.Equal(expectedResult.Item1, actualResult.Item1);
            Assert.Equal(expectedResult.Item2, actualResult.Item2);
        }