public async Task WhenTokenAndInstanceId()
        {
            // Arrange
            IServiceLocator serviceLocator = Substitute.For <IServiceLocator>();

            WebHealthVaultConfiguration webHealthVaultConfiguration = Substitute.For <WebHealthVaultConfiguration>();
            ICookieDataManager          cookieDataManager           = Substitute.For <ICookieDataManager>();

            serviceLocator.GetInstance <WebHealthVaultConfiguration>().Returns(webHealthVaultConfiguration);
            serviceLocator.GetInstance <ICookieDataManager>().Returns(cookieDataManager);

            WebHealthVaultConnection webHealthVaultConnection = Substitute.For <WebHealthVaultConnection>(serviceLocator);

            Ioc.Container.Configure(c => c.ExportInstance(webHealthVaultConnection).As <IWebHealthVaultConnection>());

            IPersonClient mockedPersonClient = Substitute.For <IPersonClient>();

            mockedPersonClient.GetPersonInfoAsync().Returns(Task.FromResult(new PersonInfo()));

            Ioc.Container.Configure(c => c.ExportInstance(mockedPersonClient).As <IPersonClient>());

            // Act
            IWebConnectionInfoProvider webConnectionInfoProvider = new WebConnectionInfoProvider(serviceLocator);
            WebConnectionInfo          webConnectionInfo         = await webConnectionInfoProvider.CreateWebConnectionInfoAsync("someToken", "1");

            // Assert
            Assert.AreEqual("someToken", webConnectionInfo.UserAuthToken);
        }
Ejemplo n.º 2
0
        public WebConnectionInfoProvider(IServiceLocator serviceLocator)
        {
            _serviceLocator = serviceLocator;

            _webHealthVaultConfiguration = serviceLocator.GetInstance <WebHealthVaultConfiguration>();
            _cookieDataManager           = serviceLocator.GetInstance <ICookieDataManager>();

            _useSession = _webHealthVaultConfiguration.UseAspSession;
            _cookieName = _webHealthVaultConfiguration.CookieName;

            _serializerSettings = new JsonSerializerSettings();
            _serializerSettings.Converters.Add(new WebConnectionInfoConverter());
        }
        private static WebConnectionInfo MockCookieDataManager(IServiceLocator serviceLocator)
        {
            WebConnectionInfo webConnectionInfo = new WebConnectionInfo {
                UserAuthToken = "test"
            };
            string serializedWebConnectionInfo = JsonConvert.SerializeObject(
                webConnectionInfo,
                new JsonSerializerSettings {
                Converters = { new WebConnectionInfoConverter() }
            });

            ICookieDataManager cookieDataManager = Substitute.For <ICookieDataManager>();

            cookieDataManager.Decompress(Arg.Any <string>()).Returns(serializedWebConnectionInfo);

            serviceLocator.GetInstance <ICookieDataManager>().Returns(cookieDataManager);
            return(webConnectionInfo);
        }