예제 #1
0
        public async Task ShouldOAuthRequest()
        {
			await FHClient.Init();

            //given
            ServiceFinder.RegisterType<IOAuthClientHandlerService, MockOAuthClient>();

            var json = JObject.Parse(@"{
                ""hosts"": {""host"": ""HOST""}
             }");
            var config = new FHConfig(new MockDeviceService());
            var props = new CloudProps(json, config);
            var authRequest = new FHAuthRequest(props);

            authRequest.SetAuthUser("gmail", "user", "password");

            var mockHttpCLient =
                new MockHttpClient {Content = "{\"status\": \"ok\", \"url\": \"http://oauthurl.url\"}"};
            FHHttpClientFactory.Get = () => mockHttpCLient;

            //when
            var response = await authRequest.ExecAsync();

            //then
            Assert.IsNotNull(response);
            var responseParams = response.GetResponseAsDictionary();
            Assert.IsNotNull(responseParams);
            Assert.AreEqual("token", responseParams["sessionToken"]);
        }
예제 #2
0
 /// <summary>
 ///     Return the singleton instance of the class
 /// </summary>
 /// <returns></returns>
 public static FHConfig GetInstance()
 {
     if (null != _instance) return _instance;
     var deviceService = ServiceFinder.Resolve<IDeviceService>();
     var props = deviceService.ReadAppProps();
     var dest = deviceService.GetDeviceDestination();
     var uuid = deviceService.GetDeviceId();
     _instance = new FHConfig(props, dest, uuid);
     return _instance;
 }
예제 #3
0
        /// <summary>
        ///     Return the singleton instance of the class
        /// </summary>
        /// <returns></returns>
        public static FHConfig GetInstance()
        {
            if (null != _instance)
            {
                return(_instance);
            }
            var deviceService = ServiceFinder.Resolve <IDeviceService>();
            var props         = deviceService.ReadAppProps();
            var dest          = deviceService.GetDeviceDestination();
            var uuid          = deviceService.GetDeviceId();

            _instance = new FHConfig(props, dest, uuid);
            return(_instance);
        }
예제 #4
0
        public void TestURLFormatting()
        {
            // given
            var json = JObject.Parse(@"{
                'url': 'http://someserver.com/',
                'hosts': {'host': 'HOST',  'environment': 'ENV'}
             }");
            var config = new FHConfig(new MockDeviceService());
            var props = new CloudProps(json, config);

            // when
            var host = props.GetCloudHost();

            // then
            Assert.AreEqual("http://someserver.com", host);
        }
예제 #5
0
        public void TestReadConfigWithMockedDevice()
        {
            // given a mocked DeviceService
            var config = new FHConfig(new MockDeviceService());

            // when
            // default instanciation

            // then
            Assert.AreEqual(MockDeviceService.Host, config.GetHost());
            Assert.AreEqual(MockDeviceService.ProjectId, config.GetProjectId());
            Assert.AreEqual(MockDeviceService.AppKey, config.GetAppKey());
            Assert.AreEqual(MockDeviceService.AppId, config.GetAppId());
            Assert.AreEqual(MockDeviceService.ConnectionTag, config.GetConnectionTag());
            Assert.AreEqual(MockDeviceService.DeviceDestination, config.GetDestination());
            Assert.AreEqual(MockDeviceService.DeviceId, config.GetDeviceId());
        }
예제 #6
0
        public void TestReadCloudPropsWithJsonEmptyValuesForUrlAndHostWithoutUrl()
        {
            // given
            var json = JObject.Parse(@"{
                'hosts': {'host': 'HOST',  'environment': 'ENV', 'releaseCloudUrl': 'RELEASE_CLOUD_URL'}
             }");
            var config = new FHConfig(new MockDeviceService());
            var props = new CloudProps(json, config);

            // when
            var host = props.GetCloudHost();
            var env = props.GetEnv();

            // then
            Assert.AreEqual("RELEASE_CLOUD_URL", host);
            Assert.AreEqual("ENV", env);
        }
예제 #7
0
        public void TestReadCloudPropsWithJsonContainingValues()
        {
            // given
            var json = JObject.Parse(@"{
                'url': 'URL',
                'hosts': {'host': 'HOST',  'environment': 'ENV'}
             }");
            var config = new FHConfig(new MockDeviceService());
            var props = new CloudProps(json, config);

            // when
            var host = props.GetCloudHost();
            var env = props.GetEnv();

            // then
            Assert.AreEqual("URL", host);
            Assert.AreEqual("ENV", env);
        }
예제 #8
0
 /// <summary>
 /// Constructor used for unit testing and injecting mock.
 /// </summary>
 /// <param name="props"></param>
 public CloudProps(JObject props, FHConfig config)
 {
     _cloudPropsJson = props;
     _config = config;
 }
예제 #9
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="props">The json format of the cloud host info</param>
 public CloudProps(JObject props)
 {
     _cloudPropsJson = props;
     _config = FHConfig.GetInstance();
 }