main
wanggaofeng 9 months ago
parent 17a2348440
commit 7a97bfd1cd

@ -21,7 +21,7 @@ namespace HttpClientStudy.UnitTest
/// </summary>
public static HttpClient GetHttpClient = new HttpClient()
{
BaseAddress = new Uri("http://localhost:5189"),
BaseAddress = new Uri(TestConfig.WebApiBaseUrl),
};
/// <summary>

@ -12,6 +12,7 @@ namespace HttpClientStudy.UnitTest
public class NormalHttpClientTest
{
private readonly ITestOutputHelper _logger;
private readonly string baseAddress = "http://localhost:5189";
public NormalHttpClientTest(ITestOutputHelper outputHelper)
{
@ -19,9 +20,22 @@ namespace HttpClientStudy.UnitTest
}
[Fact]
public void Test()
public async Task GetAccount_Test()
{
HttpClient httpClient = new HttpClient()
{
BaseAddress = new Uri(TestConfig.WebApiBaseUrl),
};
var responseMessage = await httpClient.GetAsync("/api/Normal/GetAllAccounts");
responseMessage.EnsureSuccessStatusCode();
Assert.NotNull(responseMessage);
Assert.True(responseMessage.IsSuccessStatusCode);
var content = await responseMessage.Content.ReadAsStringAsync();
Assert.NotEmpty(content);
}
}
}

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HttpClientStudy.UnitTest
{
public class TestConfig
{
public const string WebApiBaseUrl = "http://localhost:5189";
}
}
Loading…
Cancel
Save