예제 #1
0
        public async Task WhenCreateOfflineConnection_WithOfflinePersonId()
        {
            // Arrange
            WebHealthVaultConfiguration configuration = new WebHealthVaultConfiguration
            {
                DefaultHealthVaultShellUrl = new Uri("http://www.bing.com"),
                DefaultHealthVaultUrl      = new Uri("http://www.bing.com")
            };

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

            serviceLocator.GetInstance <WebHealthVaultConfiguration>().Returns(configuration);

            IOfflineHealthVaultConnection mokcedOfflineHealthVaultConnection = Substitute.For <OfflineHealthVaultConnection>(serviceLocator);

            Ioc.Container.Configure(c => c.ExportInstance(mokcedOfflineHealthVaultConnection).As <IOfflineHealthVaultConnection>());

            WebHealthVaultFactory factory = new WebHealthVaultFactory();
            string offlinePersonId        = Guid.NewGuid().ToString();

            // Act
            IOfflineHealthVaultConnection offlineHealthVaultConnection = await factory.CreateOfflineConnectionInternalAsync(
                offlinePersonId : offlinePersonId);

            // Assert
            Assert.AreEqual(offlinePersonId, offlineHealthVaultConnection.OfflinePersonId.ToString());

            // Assert that default service instance is created and is set to default shell url from web configuration
            Assert.AreEqual(configuration.DefaultHealthVaultShellUrl, ((OfflineHealthVaultConnection)offlineHealthVaultConnection).ServiceInstance.ShellUrl);
        }
        private async Task <IThingClient> CreateThingClientAsync()
        {
            IOfflineHealthVaultConnection offlineHealthVaultConnection =
                await WebHealthVaultFactory.CreateOfflineConnectionAsync(OfflinePersonId, InstanceId);

            IThingClient thingClient = offlineHealthVaultConnection.CreateThingClient();

            return(thingClient);
        }
예제 #3
0
        /// <summary>
        /// Creates the offline connection.
        /// </summary>
        /// <param name="offlinePersonId">The offline person identifier.</param>
        /// <param name="instanceId">The instance identifier.</param>
        /// <param name="sessionCredential">The session credential.</param>
        /// <returns></returns>
        public static async Task <IOfflineHealthVaultConnection> CreateOfflineConnectionAsync(
            string offlinePersonId,
            string instanceId = null,
            SessionCredential sessionCredential = null)
        {
            WebHealthVaultFactory         factory = new WebHealthVaultFactory();
            IOfflineHealthVaultConnection webHealthVaultConnection = await factory.CreateOfflineConnectionInternalAsync(
                offlinePersonId,
                instanceId,
                sessionCredential);

            return(webHealthVaultConnection);
        }
예제 #4
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);
        }
예제 #5
0
        public async Task WhenCreateOfflineConnection_WithOfflinePersonIdAndInstanceId()
        {
            // Arrange
            WebHealthVaultConfiguration configuration = new WebHealthVaultConfiguration
            {
                DefaultHealthVaultShellUrl = new Uri("http://www.bing.com"),
                DefaultHealthVaultUrl      = new Uri("http://www.bing.com")
            };

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

            serviceLocator.GetInstance <WebHealthVaultConfiguration>().Returns(configuration);

            IOfflineHealthVaultConnection mokcedOfflineHealthVaultConnection = Substitute.For <OfflineHealthVaultConnection>(serviceLocator);

            Ioc.Container.Configure(c => c.ExportInstance(mokcedOfflineHealthVaultConnection).As <IOfflineHealthVaultConnection>());

            WebHealthVaultFactory factory = new WebHealthVaultFactory();
            string offlinePersonId        = Guid.NewGuid().ToString();

            IServiceInstanceProvider serviceInstanceProvider = Substitute.For <IServiceInstanceProvider>();

            serviceInstanceProvider.GetHealthServiceInstanceAsync(Arg.Any <string>())
            .Returns(new HealthServiceInstance {
                Name = "Test"
            });
            Ioc.Container.Configure(c => c.ExportInstance(serviceInstanceProvider).As <IServiceInstanceProvider>());

            string instanceId = Guid.NewGuid().ToString();

            // Act
            IOfflineHealthVaultConnection offlineHealthVaultConnection = await factory.CreateOfflineConnectionInternalAsync(
                offlinePersonId : offlinePersonId,
                instanceId : instanceId);

            // Assert
            Assert.AreEqual(offlinePersonId, offlineHealthVaultConnection.OfflinePersonId.ToString());
            Assert.AreEqual("Test", ((OfflineHealthVaultConnection)offlineHealthVaultConnection).ServiceInstance.Name);
        }