public void TestInitialize()
        {
            // Arrange
            Ioc.Container = new DependencyInjectionContainer();

            IServiceLocator serviceLocator = Substitute.For <IServiceLocator>();

            serviceLocator.GetInstance <WebHealthVaultConfiguration>().Returns(new WebHealthVaultConfiguration
            {
                DefaultHealthVaultUrl      = new Uri("http://www.bing.com"),
                DefaultHealthVaultShellUrl = new Uri("http://www.bing.com")
            });

            HealthServiceInstance healthServiceInstance = new HealthServiceInstance();
            SessionCredential     sessionCredential     = new SessionCredential
            {
                ExpirationUtc = DateTimeOffset.UtcNow.AddHours(4),
                SharedSecret  = SessionSharedSecret,
                Token         = SessionToken
            };

            _offlineHealthVaultConnection =
                new OfflineHealthVaultConnection(serviceLocator)
            {
                OfflinePersonId   = OfflinePersonId,
                ServiceInstance   = healthServiceInstance,
                SessionCredential = sessionCredential
            };
        }
예제 #2
0
        // Enables unit test
        internal async Task <IOfflineHealthVaultConnection> CreateOfflineConnectionInternalAsync(
            string offlinePersonId,
            string instanceId = null,
            SessionCredential sessionCredential = null)
        {
            Guid parsedOfflinePersonId;

            if (!Guid.TryParse(offlinePersonId, out parsedOfflinePersonId))
            {
                throw new ArgumentException("Unable to parse offline person id to Guid", nameof(offlinePersonId));
            }

            IServiceLocator serviceLocator = new ServiceLocator();

            HealthServiceInstance serviceInstance = null;

            if (!string.IsNullOrEmpty(instanceId))
            {
                // Get ServiceInstance
                IServiceInstanceProvider serviceInstanceProvider = serviceLocator.GetInstance <IServiceInstanceProvider>();
                serviceInstance = await serviceInstanceProvider.GetHealthServiceInstanceAsync(instanceId);
            }

            IOfflineHealthVaultConnection offlineHealthVaultConnection = Ioc.Container.Locate <IOfflineHealthVaultConnection>(
                extraData: new { serviceLocator = serviceLocator });

            OfflineHealthVaultConnection connection = offlineHealthVaultConnection as OfflineHealthVaultConnection;

            connection.SessionCredential = sessionCredential;
            connection.OfflinePersonId   = parsedOfflinePersonId;

            // By default, service instance is "US", so do not override in case the instance id is not set
            if (serviceInstance != null)
            {
                connection.ServiceInstance = serviceInstance;
            }

            return(offlineHealthVaultConnection);
        }