コード例 #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);
        }
コード例 #2
0
 public async Task IsUpgradeableAsync_WhenCancellationTokenIsCancelled_Throws()
 {
     await Assert.ThrowsAsync <OperationCanceledException>(
         () => IProjectContextInfoExtensions.IsUpgradeableAsync(
             Mock.Of <IProjectContextInfo>(),
             Mock.Of <IServiceBroker>(),
             new CancellationToken(canceled: true))
         .AsTask());
 }
コード例 #3
0
 public async Task IsUpgradeableAsync_WhenServiceBrokerIsNull_Throws()
 {
     await VerifyMicrosoftAssumesExceptionAsync(
         () => IProjectContextInfoExtensions.IsUpgradeableAsync(
             Mock.Of <IProjectContextInfo>(),
             serviceBroker : null,
             CancellationToken.None)
         .AsTask());
 }