public async Task taxaccountnumber_getbyidasync() { var httpclient = fixture.Client; if (String.IsNullOrEmpty(TokenTest.TokenValue)) { await TokenTest.token_get(httpclient); } // var util = new UtilityExt(); //MANUAL UPDATES REQUIRED! //todo - add if any parent of the entity //add entity var taxaccountnumberid = await util.addTaxAccountNumber(httpclient); // httpclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TokenTest.TokenValue); var response = await httpclient.GetAsync("/api/taxaccountnumberasync/" + taxaccountnumberid.ToString()); response.EnsureSuccessStatusCode(); Assert.Equal(HttpStatusCode.OK, response.StatusCode); var jsonString = await response.Content.ReadAsStringAsync(); var vmenitity = JsonConvert.DeserializeObject <TaxAccountNumberViewModel>(jsonString); Assert.True(vmenitity.TestText == "tt updated"); //clean await util.removeTaxAccountNumber(httpclient, taxaccountnumberid); //remove if any parent entity added }
public async Task taxaccountnumber_add_update_delete() { var httpclient = fixture.Client;; if (String.IsNullOrEmpty(TokenTest.TokenValue)) { await TokenTest.token_get(httpclient); } // TaxAccountNumberViewModel taxaccountnumber = new TaxAccountNumberViewModel { //MANUAL UPDATES REQUIRED! TestText = "tt updated" }; httpclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TokenTest.TokenValue); var response = await httpclient.PostAsync("/api/taxaccountnumber", new StringContent( JsonConvert.SerializeObject(taxaccountnumber), Encoding.UTF8, "application/json")); response.EnsureSuccessStatusCode(); Assert.Equal(HttpStatusCode.Created, response.StatusCode); var lastAddedId = await response.Content.ReadAsStringAsync(); Assert.True(int.Parse(lastAddedId) > 1); int id = 0; int.TryParse(lastAddedId, out id); //get inserted var util = new UtilityExt(); var vmentity = await util.GetTaxAccountNumber(httpclient, id); //update test vmentity.TestText = "tt updated"; response = await httpclient.PutAsync("/api/taxaccountnumber/" + id.ToString(), new StringContent(JsonConvert.SerializeObject(vmentity), Encoding.UTF8, "application/json")); response.EnsureSuccessStatusCode(); Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); //confirm update response = await httpclient.GetAsync("/api/taxaccountnumber/" + id.ToString()); response.EnsureSuccessStatusCode(); var jsonString = await response.Content.ReadAsStringAsync(); var oj = JObject.Parse(jsonString); var tt = oj["testText"].ToString(); Assert.Equal(tt, vmentity.TestText); //another update with same account - concurrency vmentity.TestText = "tt updated 2"; response = await httpclient.PutAsync("/api/taxaccountnumber/" + id.ToString(), new StringContent(JsonConvert.SerializeObject(vmentity), Encoding.UTF8, "application/json")); Assert.Equal(HttpStatusCode.PreconditionFailed, response.StatusCode); //delete test response = await httpclient.DeleteAsync("/api/taxaccountnumber/" + id.ToString()); response.EnsureSuccessStatusCode(); Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); }
public async Task taxaccountnumber_getallasync() { var httpclient = fixture.Client; if (String.IsNullOrEmpty(TokenTest.TokenValue)) { await TokenTest.token_get(httpclient); } // var util = new UtilityExt(); //MANUAL UPDATES REQUIRED! //todo - add parent of the entity if exist //add entity var taxaccountnumberid = await util.addTaxAccountNumber(httpclient); // httpclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", TokenTest.TokenValue); var response = await httpclient.GetAsync("/api/taxaccountnumberasync"); response.EnsureSuccessStatusCode(); Assert.Equal(HttpStatusCode.OK, response.StatusCode); var jsonString = await response.Content.ReadAsStringAsync(); var vmenititys = (ICollection <UserViewModel>)JsonConvert.DeserializeObject <IEnumerable <UserViewModel> >(jsonString); Assert.True(vmenititys.Count > 0); // lazy-loading test if entity has children response = await httpclient.GetAsync("/api/taxaccountnumberasync/" + taxaccountnumberid.ToString()); response.EnsureSuccessStatusCode(); Assert.Equal(HttpStatusCode.OK, response.StatusCode); jsonString = await response.Content.ReadAsStringAsync(); var vmenitity = JsonConvert.DeserializeObject <TaxAccountNumberViewModel>(jsonString); //Assert.True(vmenitity.Kids.Count == 1); //clean await util.removeTaxAccountNumber(httpclient, taxaccountnumberid); //remove if any parent entity added }