private async Task <ServiceInfo> GetFromServiceAsync() { IWebHealthVaultConnection webHealthVaultConnection = Ioc.Container.Locate <IWebHealthVaultConnection>( extraData: new { serviceLocator = _serviceLocator }); IPlatformClient platformClient = webHealthVaultConnection.CreatePlatformClient(); ServiceInfo serviceInfo = await platformClient.GetServiceDefinitionAsync(ServiceInfoSections.Topology).ConfigureAwait(false); return(serviceInfo); }
private async Task ProvisionForSodaAuthAsync() { // Set a temporary service instance for the NewApplicationCreationInfo and GetServiceDefinition calls. var defaultHealthVaultUrl = Configuration.DefaultHealthVaultUrl; var defaultHealthVaultShellUrl = Configuration.DefaultHealthVaultShellUrl; var masterApplicationId = Configuration.MasterApplicationId; ServiceInstance = new HealthServiceInstance( "1", "Default", "Default HealthVault instance", UrlUtilities.GetFullPlatformUrl(defaultHealthVaultUrl), defaultHealthVaultShellUrl); // Note: This apparent circular call is intentional. This method is called from AuthenticateAsync. // PlatformClient is calling HealthVaultConnectionBase.ExecuteAsync("NewApplicationCreationInfo"), // which avoids calling AuthenticateAsync because "NewApplicationCreationInfo" is an anonymous method. IPlatformClient platformClient = CreatePlatformClient(); ApplicationCreationInfo newApplicationCreationInfo = await platformClient.NewApplicationCreationInfoAsync().ConfigureAwait(false); string environmentInstanceId = await _shellAuthService.ProvisionApplicationAsync( defaultHealthVaultShellUrl, masterApplicationId, newApplicationCreationInfo.AppCreationToken, newApplicationCreationInfo.AppInstanceId.ToString()).ConfigureAwait(false); ServiceInfo serviceInfo = await platformClient.GetServiceDefinitionAsync(ServiceInfoSections.Topology).ConfigureAwait(false); HealthServiceInstance bouncedHealthServiceInstance; if (!serviceInfo.ServiceInstances.TryGetValue(environmentInstanceId, out bouncedHealthServiceInstance)) { // TODO: Come up with better error for Current HealthServiceException is restrictive. throw new HealthServiceException(HealthServiceStatusCode.Failed); } // We've successfully made it through the flow. Save all the information. await _localObjectStore.WriteAsync(ServiceInstanceKey, bouncedHealthServiceInstance).ConfigureAwait(false); ServiceInstance = bouncedHealthServiceInstance; await _localObjectStore.WriteAsync(ApplicationCreationInfoKey, newApplicationCreationInfo).ConfigureAwait(false); ApplicationCreationInfo = newApplicationCreationInfo; }
/// <summary> /// We will mock webhealthvaultconnection and substitute CreatePlatformClient call /// on the mock to return a mock platform client. Platform client will substitute /// call to platform "getservicedefintion" by returning a dummy serviceinstance with /// id set to "US instance". /// </summary> private async Task <HealthServiceInstance> GetHealthServiceInstanceAsync() { _webHealthVaultConnection = Substitute.For <IWebHealthVaultConnection>(); Ioc.Container.Configure(c => { c.ExportInstance(_webHealthVaultConnection).As <IWebHealthVaultConnection>(); }); IPlatformClient platformClient = Substitute.For <IPlatformClient>(); _webHealthVaultConnection.CreatePlatformClient().Returns(platformClient); ServiceInfo serviceInfo = Substitute.For <ServiceInfo>(); serviceInfo.ServiceInstances.Add(UsInstanceId, new HealthServiceInstance { Id = UsInstanceId }); platformClient .GetServiceDefinitionAsync(ServiceInfoSections.Topology) .Returns(serviceInfo); HealthServiceInstance serviceInstance = await _serviceInstanceProvider.GetHealthServiceInstanceAsync("1"); return(serviceInstance); }