public void Can_serialize_with_Json_NET()
 {
     const string expected = "{\"CredentialsValue\":\"ZmFrZWl0OmZha2VpdA==\",\"BaseUri\":\"https://fakeit.harvestapp.com\",\"Subdomain\":\"fakeit\",\"Username\":\"fakeit\",\"MaxResponseContentBufferSize\":256000,\"HttpAcceptValue\":\"application/json\",\"RequestHeaderUserAgent\":\"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)\"}";
     var settings = new ApiBasicAuthSettings("fakeit");
     settings.SetCredentials("fakeit", "fakeit");
     var actual = JsonConvert.SerializeObject(settings);
     Assert.AreEqual(expected, actual);
 }
 public void Can_deserialize_with_Json_NET()
 {
     var settings = new ApiBasicAuthSettings("fakeit");
     settings.SetCredentials("fakeit", "fakeit");
     var json = JsonConvert.SerializeObject(settings);
     var deserializedSettings = JsonConvert.DeserializeObject<ApiBasicAuthSettings>(json);
     Assert.IsNotNull(deserializedSettings);
     Assert.AreEqual(settings.Subdomain, settings.Subdomain);
     Assert.AreEqual(settings.Username, settings.Username);
     Assert.AreEqual(settings.BaseUri, deserializedSettings.BaseUri);
     Assert.AreEqual(settings.CredentialsValue, deserializedSettings.CredentialsValue);
 }
Ejemplo n.º 3
0
        private async Task Get <T>(Expression <Func <IHarvestResourcePathFactory, string> > uriFactoryExpression)
        {
            if (!string.IsNullOrWhiteSpace(SubdomainBox.Text) && !string.IsNullOrWhiteSpace(UsernameBox.Text) &&
                !string.IsNullOrWhiteSpace(PasswordBox.Password))
            {
                var harvestAuthInfo = new ApiBasicAuthSettings(SubdomainBox.Text);
                harvestAuthInfo.SetCredentials(UsernameBox.Text, PasswordBox.Password);
                ApiSettings = harvestAuthInfo;
            }
            if (_harvestApi == null)
            {
                // TODO: tell user that authentication is hosed
                return;
            }

            // ideally this low-level abstraction would be hidden somewhere and DIed into a Core.IRT interface impl
            var response = await _harvestApi.Get <T>(ApiSettings, uriFactoryExpression);

            OutputBox.DataContext = response;
        }
 public void Ctor_sets_BaseUri()
 {
     const string subdomain = "fakeit";
     var settings = new ApiBasicAuthSettings(subdomain);
     Assert.AreEqual(new Uri("https://" + subdomain + ".harvestapp.com"), settings.BaseUri);
 }
 public void SetCredentials_can_hash_username_and_password()
 {
     var settings = new ApiBasicAuthSettings("fakeit");
     settings.SetCredentials("fakeit", "fakeit");
     Assert.AreEqual("ZmFrZWl0OmZha2VpdA==", settings.CredentialsValue);
 }