Untitled
unknown
csharp
3 years ago
4.3 kB
4
Indexable
public void TestCreateWageType() { WageTypeData initialData = new WageTypeData { Name = "TestCreateWageType1", Description = "TestCreateWageType()" }; string query1; using (FormUrlEncodedContent content = new FormUrlEncodedContent(new Dictionary<string, string> { { "InOrgUnit_orgUnitId", Constants.KlinikOrgUnitId }, }) ) { query1 = "?" + content.ReadAsStringAsync().Result; } if (query1 == "?") query1 = string.Empty; HttpResponseMessage apiResponse1 = default(HttpResponseMessage); // remove this if no complex type parameter is used StringContent dataObject1 = new StringContent(JsonConvert.SerializeObject(initialData), Encoding.UTF8, "application/json"); Assert.DoesNotThrowAsync(async () => apiResponse1 = await HttpClient .PostAsync(Settings.Default.OpenApiRest_Url + "Time_WageType/InOrgUnit(orgUnitId)/Create/UpdateWageType(data)/ReadWageType/" + query1, dataObject1)); Assert.That(apiResponse1, Is.Not.Null); Assert.That(apiResponse1.StatusCode, Is.Not.EqualTo(HttpStatusCode.NotFound), "Method 'Time_WageType/InOrgUnit(orgUnitId)/Create/UpdateWageType(data)/ReadWageType/' was not found! If it contains character '|', please select one of the proposed parameters."); Assert.That(apiResponse1.StatusCode, Is.Not.EqualTo(HttpStatusCode.InternalServerError), apiResponse1.StatusCode == HttpStatusCode.InternalServerError ? JsonObjectDeserializer .DeserializeObject<ApiExceptionObject>(apiResponse1.Content.ReadAsStringAsync().Result) .Error : string.Empty); string apiResult1 = apiResponse1.Content.ReadAsStringAsync().Result; Assert.That(apiResult1, Is.Not.Null); WageTypeData wageType = default(WageTypeData); Assert.DoesNotThrow(() => { wageType = JsonObjectDeserializer.DeserializeObject<WageTypeData>(apiResult1); }); string query2; using (FormUrlEncodedContent content = new FormUrlEncodedContent(new Dictionary<string, string> { { "ById_id", wageType.Id.ToString() }, }) ) { query2 = "?" + content.ReadAsStringAsync().Result; } if (query2 == "?") query2 = string.Empty; HttpResponseMessage apiResponse2 = default(HttpResponseMessage); Assert.DoesNotThrowAsync(async () => apiResponse2 = await HttpClient .GetAsync(Settings.Default.OpenApiRest_Url + "Time_WageType/ById(id)/ReadWageType/" + query2)); Assert.That(apiResponse2, Is.Not.Null); Assert.That(apiResponse2.StatusCode, Is.Not.EqualTo(HttpStatusCode.NotFound), "Method 'Time_WageType/ById(id)/ReadWageType/' was not found! If it contains character '|', please select one of the proposed parameters."); Assert.That(apiResponse2.StatusCode, Is.Not.EqualTo(HttpStatusCode.InternalServerError), apiResponse2.StatusCode == HttpStatusCode.InternalServerError ? JsonObjectDeserializer .DeserializeObject<ApiExceptionObject>(apiResponse2.Content.ReadAsStringAsync().Result) .Error : string.Empty); string apiResult2 = apiResponse2.Content.ReadAsStringAsync().Result; Assert.That(apiResult2, Is.Not.Null); Assert.DoesNotThrow(() => { wageType = JsonObjectDeserializer.DeserializeObject<WageTypeData>(apiResult2); }); Assert.That(wageType.Name, Is.EqualTo("TestCreateWageType1")); Assert.That(wageType.Description, Is.EqualTo("TestCreateWageType()")); }
Editor is loading...