Added CPATapi.Server API Client

This commit is contained in:
2026-04-09 14:12:21 +02:00
parent 6d1d165aba
commit d8b9fd7664
18 changed files with 1096 additions and 1 deletions
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.7.0" />
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\CPATapi.Client\CPATapi.Client.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>
</Project>
@@ -0,0 +1,45 @@
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>();
var availability = await client.Availability["Unknown"].GetAsync();
Assert.That(availability, Is.Not.Null);
}
}