using System.Net; using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using Shouldly; using Volo.Abp.AspNetCore.TestBase; namespace MyCompanyName.MyProjectName { public abstract class MyProjectNameWebTestBase : AbpAspNetCoreIntegratedTestBase { protected override IHostBuilder CreateHostBuilder() { return base .CreateHostBuilder() .UseContentRoot(WebContentDirectoryFinder.CalculateContentRootFolder()); } protected virtual async Task GetResponseAsObjectAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK) { var strResponse = await GetResponseAsStringAsync(url, expectedStatusCode); return JsonConvert.DeserializeObject(strResponse, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); } protected virtual async Task GetResponseAsStringAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK) { var response = await GetResponseAsync(url, expectedStatusCode); return await response.Content.ReadAsStringAsync(); } protected virtual async Task GetResponseAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK) { var response = await Client.GetAsync(url); response.StatusCode.ShouldBe(expectedStatusCode); return response; } } }