57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
using CPATapi.Client.Models;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace CPATapi.Client.Tests;
|
|
|
|
public class CPATapiClientTests
|
|
{
|
|
private IServiceScope CreateServices()
|
|
{
|
|
var services = new ServiceCollection();
|
|
services.AddCPATapiClient(((provider, client) =>
|
|
{
|
|
client.BaseAddress = new Uri("https://3cxtapi.cp-austria.at/");
|
|
}));
|
|
var sp = services.BuildServiceProvider();
|
|
return sp.CreateScope();
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestContactsGet()
|
|
{
|
|
using var scope = CreateServices();
|
|
var client = scope.ServiceProvider.GetRequiredService<CPATapiClient>();
|
|
var contacts = await client.Contact.GetAsync();
|
|
Assert.That(contacts, Is.Not.Null);
|
|
Assert.That(contacts, Is.Not.Empty);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestAvailabilityGet()
|
|
{
|
|
using var scope = CreateServices();
|
|
var client = scope.ServiceProvider.GetRequiredService<CPATapiClient>();
|
|
var availability = await client.Availability["CPATRD"].GetAsync();
|
|
Assert.That(availability, Is.Not.Null);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestAvailabilityGetUnknown()
|
|
{
|
|
using var scope = CreateServices();
|
|
var client = scope.ServiceProvider.GetRequiredService<CPATapiClient>();
|
|
Assert.ThrowsAsync<ProblemDetails>(async () => await client.Availability["Unknown"].GetAsync());
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestAvailabilityGetAll()
|
|
{
|
|
using var scope = CreateServices();
|
|
var client = scope.ServiceProvider.GetRequiredService<CPATapiClient>();
|
|
var availability = await client.Availability.GetAsync();
|
|
Assert.That(availability, Is.Not.Null);
|
|
Assert.That(availability, Is.Not.Empty);
|
|
Assert.That(availability, Has.Count.GreaterThan(1));
|
|
}
|
|
}
|