public async Task TryGetInstalledPackageFilePathAsync_WhenCancellationTokenIsCancelled_Throws() { await Assert.ThrowsAsync <OperationCanceledException>( () => IProjectContextInfoExtensions.TryGetInstalledPackageFilePathAsync( Mock.Of <IProjectContextInfo>(), Mock.Of <IServiceBroker>(), PackageIdentity, new CancellationToken(canceled: true)) .AsTask()); }
public async Task TryGetInstalledPackageFilePathAsync_WhenPackageIdentityIsNull_Throws() { await VerifyMicrosoftAssumesExceptionAsync( () => IProjectContextInfoExtensions.TryGetInstalledPackageFilePathAsync( Mock.Of <IProjectContextInfo>(), Mock.Of <IServiceBroker>(), packageIdentity : null, CancellationToken.None) .AsTask()); }
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); }