34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using System.Net;
|
|
using LehrerApp.Desktop.Services;
|
|
using LehrerApp.Sync;
|
|
using Xunit;
|
|
|
|
namespace LehrerApp.Desktop.Tests;
|
|
|
|
public sealed class SyncAuthServiceProtocolTests
|
|
{
|
|
[Fact]
|
|
public async Task TestConnectionAsync_InkompatibleVersion_WirdNichtAlsOfflineGemeldet()
|
|
{
|
|
HttpRequestMessage? sent = null;
|
|
var service = new SyncAuthService(new HttpClient(new Handler(request =>
|
|
{
|
|
sent = request;
|
|
return new HttpResponseMessage(HttpStatusCode.UpgradeRequired);
|
|
})));
|
|
|
|
var result = await service.TestConnectionAsync("https://sync.example.invalid", "token");
|
|
|
|
Assert.Equal(SyncConnectionTestResult.IncompatibleVersion, result);
|
|
Assert.Equal(SyncProtocol.CurrentVersion,
|
|
sent!.Headers.GetValues(SyncProtocol.VersionHeaderName).Single());
|
|
}
|
|
|
|
private sealed class Handler(Func<HttpRequestMessage, HttpResponseMessage> response) : HttpMessageHandler
|
|
{
|
|
protected override Task<HttpResponseMessage> SendAsync(
|
|
HttpRequestMessage request, CancellationToken cancellationToken) =>
|
|
Task.FromResult(response(request));
|
|
}
|
|
}
|