Philipp Häfelfinger
09a7a40dff
adds CalculateOrphansAsync to AlbumApi removes some not needed log lines removes tests explicit login calls
62 lines
1.5 KiB
C#
62 lines
1.5 KiB
C#
using Flurl.Http.Configuration;
|
|
using Flurl.Http.Testing;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Newtonsoft.Json;
|
|
using Piwigo.Client.Contract;
|
|
|
|
namespace Piwigo.Client.Tests;
|
|
|
|
public class ApiTestsBase
|
|
{
|
|
private const string TestUri = "http://localhost:8080/ws.php?format=json";
|
|
private const string Username = "admin";
|
|
private const string Password = "admin";
|
|
private const bool UseHttpTest = true;
|
|
protected HttpTest? HttpTest { get; private set; }
|
|
protected IPiwigoContext Context { get; private set; } = null!;
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
if (UseHttpTest)
|
|
{
|
|
HttpTest = new HttpTest();
|
|
}
|
|
|
|
Context = new PiwigoContext(new PiwigoConfiguration(TestUri, Username, Password), new NullLogger<PiwigoContext>());
|
|
OnSetUp();
|
|
}
|
|
|
|
protected virtual void OnSetUp()
|
|
{
|
|
}
|
|
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
HttpTest?.Dispose();
|
|
}
|
|
|
|
|
|
internal void SetOkResult()
|
|
{
|
|
SetJsonResult(@"{stat: ""ok""}");
|
|
}
|
|
|
|
internal void SetJsonResult(string json)
|
|
{
|
|
HttpTest?.RespondWith(json);
|
|
}
|
|
|
|
internal void SetJsonResult<T>(PiwigoResponse<T> serverResponse)
|
|
{
|
|
var settings = new JsonSerializerSettings
|
|
{
|
|
Formatting = Formatting.Indented,
|
|
NullValueHandling = NullValueHandling.Ignore
|
|
};
|
|
var serializer = new NewtonsoftJsonSerializer(settings);
|
|
var jsonResponse = serializer.Serialize(serverResponse);
|
|
HttpTest?.RespondWith(jsonResponse);
|
|
}
|
|
} |