private VsService <TService, TInterface> CreateInstance <TService, TInterface>(IAsyncServiceProvider serviceProvider = null, IProjectThreadingService threadingService = null) { serviceProvider = serviceProvider ?? IAsyncServiceProviderFactory.Create(); threadingService = threadingService ?? IProjectThreadingServiceFactory.Create(); return(new VsService <TService, TInterface>(serviceProvider, threadingService.JoinableTaskContext.Context)); }
public void Constructor_NullAsJoinableTaskContext_ThrowsArgumentNull() { var serviceProvider = IAsyncServiceProviderFactory.Create(); Assert.Throws <ArgumentNullException>("joinableTaskContext", () => { return(new VsService <string, string>(serviceProvider, (JoinableTaskContext)null)); }); }
public void Constructor_NullAsThreadingService_ThrowsArgumentNull() { var serviceProvider = IAsyncServiceProviderFactory.Create(); Assert.Throws <ArgumentNullException>("threadingService", () => { return(new VsService <string, string>(serviceProvider, (IProjectThreadingService)null)); }); }
public async Task GetValueAsync_WhenMissingService_ReturnsNull() { var threadingService = IProjectThreadingServiceFactory.Create(); var serviceProvider = IAsyncServiceProviderFactory.ImplementGetServiceAsync(type => null); var service = CreateInstance <string, string>(serviceProvider: serviceProvider, threadingService: threadingService); var result = await service.GetValueAsync(); Assert.Null(result); }
public async Task GetValueAsync_CancelledToken_ThrowsOperationCanceled() { var threadingService = IProjectThreadingServiceFactory.Create(); var serviceProvider = IAsyncServiceProviderFactory.ImplementGetServiceAsync(type => null); var service = CreateInstance <string, string>(serviceProvider: serviceProvider, threadingService: threadingService); await Assert.ThrowsAnyAsync <OperationCanceledException>(() => { return(service.GetValueAsync(new CancellationToken(true))); }); }
public async Task GetValueAsync_CachesResult() { var threadingService = IProjectThreadingServiceFactory.Create(); var serviceProvider = IAsyncServiceProviderFactory.ImplementGetServiceAsync(type => { return(new object()); }); var service = CreateInstance <string, object>(serviceProvider: serviceProvider, threadingService: threadingService); var result1 = await service.GetValueAsync(); var result2 = await service.GetValueAsync(); Assert.Same(result1, result2); }
public async Task GetValueAsync_ReturnsGetService() { object input = new object(); var threadingService = IProjectThreadingServiceFactory.Create(); var serviceProvider = IAsyncServiceProviderFactory.ImplementGetServiceAsync(type => { if (type == typeof(string)) { return(input); } return(null); }); var service = CreateInstance <string, object>(serviceProvider: serviceProvider, threadingService: threadingService); var result = await service.GetValueAsync(); Assert.Same(input, result); }