public async Task GetMetadataAsync_WhenArgumentsAreValid_ReturnsProjectMetadata() { var serviceBroker = new Mock <IServiceBroker>(); var projectManagerService = new Mock <INuGetProjectManagerService>(); var project = new Mock <IProjectContextInfo>(); string projectId = Guid.NewGuid().ToString(); var expectedResult = Mock.Of <IProjectMetadataContextInfo>(); 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>(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)); IProjectMetadataContextInfo actualResult = await IProjectContextInfoExtensions.GetMetadataAsync( project.Object, serviceBroker.Object, CancellationToken.None); Assert.Same(expectedResult, actualResult); }
public async Task GetMetadataAsync_WhenCancellationTokenIsCancelled_Throws() { await Assert.ThrowsAsync <OperationCanceledException>( () => IProjectContextInfoExtensions.GetMetadataAsync( Mock.Of <IProjectContextInfo>(), Mock.Of <IServiceBroker>(), new CancellationToken(canceled: true)) .AsTask()); }
public async Task GetMetadataAsync_WhenServiceBrokerIsNull_Throws() { await VerifyMicrosoftAssumesExceptionAsync( () => IProjectContextInfoExtensions.GetMetadataAsync( Mock.Of <IProjectContextInfo>(), serviceBroker : null, CancellationToken.None) .AsTask()); }