public async Task GetBuildDefinitionsTest() { var service = new VstsService(); await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetBuildDefinitionsAsync(null, "myproject", this.token)); await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetBuildDefinitionsAsync("myaccount", null, this.token)); await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetBuildDefinitionsAsync("myaccount", "myproject", null)); using (ShimsContext.Create()) { var expected = new List <BuildDefinitionReference>(); var clients = new VssHttpClientBase[] { new ShimBuildHttpClient { GetDefinitionsAsyncStringStringStringStringNullableOfDefinitionQueryOrderNullableOfInt32StringNullableOfDateTimeIEnumerableOfInt32StringNullableOfDateTimeNullableOfDateTimeObjectCancellationToken = (s, s1, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, cancellationToken) => Task.Run(() => expected, cancellationToken) }.Instance }; InitializeConnectionShim(clients); IEnumerable <BuildDefinitionReference> actual = await service.GetBuildDefinitionsAsync("myaccount", "myproject", this.token); expected.ShouldAllBeEquivalentTo(actual); } }
public async Task GetProjectsTest() { var account = "anaccount"; var service = new VstsService(); await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetProjects(null, this.token)); await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await service.GetProjects(account, null)); using (ShimsContext.Create()) { var accounts = new List <Account> { new Account(Guid.Empty) { AccountName = "myaccount", AccountUri = new Uri("https://myaccount.visualstudio.com") } }; var expected = new List <TeamProjectReference> { new TeamProjectReference { Id = Guid.NewGuid(), Name = "My Project", Url = "https://myaccount.visualstudio.com/my%20project" } }; var clients = new VssHttpClientBase[] { GetAccountHttpClient(accounts), GetProjectHttpClient(expected), GetProfileHttpClient(new Profile()) }; InitializeConnectionShim(clients); // await Assert.ThrowsExceptionAsync<ArgumentOutOfRangeException>(async () => await service.GetProjects("someaccount", this.token)); IEnumerable <TeamProjectReference> actual = await service.GetProjects(accounts[0].AccountName, this.token); expected.ShouldAllBeEquivalentTo(actual); } }
/// <summary> /// /// </summary> /// <param name="managedType"></param> /// <returns></returns> private async Task <Object> GetClientInstanceAsync( Type managedType, Guid serviceIdentifier, CancellationToken cancellationToken, VssHttpRequestSettings settings, DelegatingHandler[] handlers) { CheckForDisposed(); ILocationService locationService = await GetServiceAsync <ILocationService>(cancellationToken).ConfigureAwait(false); ILocationDataProvider locationData = await locationService.GetLocationDataAsync(serviceIdentifier, cancellationToken).ConfigureAwait(false); if (locationData == null) { throw new VssServiceException(WebApiResources.ServerDataProviderNotFound(serviceIdentifier)); } String serviceLocationString = await locationData.LocationForCurrentConnectionAsync( ServiceInterfaces.LocationService2, LocationServiceConstants.SelfReferenceIdentifier, cancellationToken).ConfigureAwait(false); // This won't ever be null because of compat code in ServerDataProvider Uri clientBaseUri = new Uri(serviceLocationString); VssHttpClientBase toReturn = null; if (settings != null) { toReturn = (VssHttpClientBase)Activator.CreateInstance(managedType, clientBaseUri, Credentials, settings, handlers); } else { toReturn = (VssHttpClientBase)Activator.CreateInstance(managedType, clientBaseUri, m_pipeline, false /* disposeHandler */); } ApiResourceLocationCollection resourceLocations = await locationData.GetResourceLocationsAsync(cancellationToken).ConfigureAwait(false); toReturn.SetResourceLocations(resourceLocations); return(toReturn); }
private static void InitializeConnectionShim(VssHttpClientBase client) { InitializeConnectionShim(new[] { client }); }