mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
37 lines
1006 B
C#
37 lines
1006 B
C#
using System;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.TestHost;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Podsync.Tests.Controllers
|
|
{
|
|
public abstract class TestServer<TStartup> : TestBase, IDisposable where TStartup : class
|
|
{
|
|
private readonly TestServer _server;
|
|
|
|
protected TestServer()
|
|
{
|
|
var builder = new WebHostBuilder().UseStartup<TStartup>();
|
|
_server = new TestServer(builder);
|
|
|
|
Client = _server.CreateClient();
|
|
Client.BaseAddress = new Uri("http://localhost:5000");
|
|
}
|
|
|
|
protected HttpClient Client { get; }
|
|
|
|
public void Dispose()
|
|
{
|
|
Client.Dispose();
|
|
_server.Dispose();
|
|
}
|
|
|
|
public static HttpContent MakeHttpContent(object obj)
|
|
{
|
|
var json = JsonConvert.SerializeObject(obj);
|
|
return new StringContent(json, Encoding.UTF8, "application/json");
|
|
}
|
|
}
|
|
} |