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