public virtual void GivenDefaultCustomer() { var responseCustomers = this._client.GetAsync("/customers/lite").Result; var customers = HttpClientExtension.ParseHttpContentToList <Dictionary <string, object> >(responseCustomers.Content); var defaultCustomer = customers.FirstOrDefault(c => c.Where(d => d.Key == "name" && (string)d.Value == "Default Customer").Count() > 0); if (defaultCustomer == null) { var jsonContent = HttpClientExtension.ParseModelToHttpContent(new { Name = "Default Customer" }); var result = this._client.PostAsync("/customers", jsonContent).Result; if (!result.IsSuccessStatusCode) { throw new ApplicationException(result.Content.ReadAsStringAsync().Result); } var customerModel = HttpClientExtension.ParseHttpContentToModel <Dictionary <string, object> >(result.Content); this.DefaultCustomerId = Convert.ToInt32(customerModel["id"]); } else { this.DefaultCustomerId = Convert.ToInt32(defaultCustomer["id"]); } }
public void on_login() { if (Shell.IsDevelopment()) { _client.SetFakeBearerToken(this.GetAdminToken()); } else { var formContent = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("grant_type", "client_credentials"), new KeyValuePair <string, string>("scope", "api"), new KeyValuePair <string, string>("client_id", "CF4A9ED44148438A99919FF285D8B48D"), new KeyValuePair <string, string>("client_secret", "0da45603-282a-4fa6-a20b-2d4c3f2a2127") }); var response = this._client.PostAsync(Shell.IdentityHost() + "/connect/token", formContent).Result; if (!response.IsSuccessStatusCode) { throw new ApplicationException(response.StatusCode.ToString()); } var token = HttpClientExtension.ParseHttpContentToModel <Dictionary <string, string> >(response.Content); _client.SetToken("Bearer", token["access_token"]); } }
public virtual void GivenDefaultUser() { var jsonContent = HttpClientExtension.ParseModelToHttpContent(new { email = KeyConstants.UserEmail, }); var result = this._client.PostAsync("/users", jsonContent).Result; if (!result.IsSuccessStatusCode) { throw new ApplicationException(result.Content.ReadAsStringAsync().Result); } var model = HttpClientExtension.ParseHttpContentToModel <Dictionary <string, object> >(result.Content); this.DefaultMemberId = Convert.ToInt32(model["id"]); }
public virtual void GivenDefaultSquad() { var jsonContent = HttpClientExtension.ParseModelToHttpContent(new { Name = KeyConstants.SquadName, customerId = this.DefaultCustomerId }); var result = this._client.PostAsync("/squads", jsonContent).Result; if (!result.IsSuccessStatusCode) { throw new ApplicationException(result.Content.ReadAsStringAsync().Result); } var model = HttpClientExtension.ParseHttpContentToModel <Dictionary <string, object> >(result.Content); this.DefaultSquadId = Convert.ToInt32(model["id"]); }