-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Xunit; | ||
|
||
namespace TransformerBeeClient.IntegrationTest; | ||
|
||
/// <summary> | ||
/// A fixture that sets up the http client factory and an injectable service collection | ||
/// </summary> | ||
public class ClientFixture : IClassFixture<ClientFixture> | ||
{ | ||
public readonly IHttpClientFactory HttpClientFactory; | ||
|
||
public readonly ServiceCollection ServiceCollection; | ||
|
||
public ClientFixture() | ||
Check warning on line 15 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 15 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 15 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 15 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 15 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 15 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 15 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 8.0.100)
Check warning on line 15 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 8.0.100)
Check warning on line 15 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 15 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 15 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 8.0.100)
Check warning on line 15 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 8.0.100)
|
||
{ | ||
var services = new ServiceCollection(); | ||
services.AddHttpClient("TransformerBee", client => | ||
{ | ||
client.BaseAddress = new Uri("http://localhost:5021"); // Check docker-compose.yml | ||
}); | ||
var serviceProvider = services.BuildServiceProvider(); | ||
ServiceCollection = services; | ||
HttpClientFactory = serviceProvider.GetService<IHttpClientFactory>(); | ||
Check warning on line 24 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 24 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 24 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 24 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 24 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 24 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 24 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 8.0.100)
Check warning on line 24 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 8.0.100)
Check warning on line 24 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 24 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 24 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ClientFixture.cs GitHub Actions / test (ubuntu-latest, 8.0.100)
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using FluentAssertions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Xunit; | ||
|
||
namespace TransformerBeeClient.IntegrationTest; | ||
|
||
/// <summary> | ||
/// Tests that a connection to the API can be established | ||
/// </summary> | ||
public class ConnectionTests : IClassFixture<ClientFixture> | ||
{ | ||
|
||
private readonly ClientFixture _client; | ||
|
||
public ConnectionTests(ClientFixture clientFixture) | ||
{ | ||
_client = clientFixture; | ||
} | ||
|
||
[Fact] | ||
public async Task IsAvailable_Returns_True_If_Service_Is_Available() | ||
{ | ||
var httpClientFactory = _client.HttpClientFactory; | ||
var client = new TransformerBeeRestClient(httpClientFactory); | ||
var result = await client.IsAvailable(); | ||
result.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public async Task IsAvailable_Throws_Exception_If_Host_Is_Unavailable() | ||
{ | ||
var services = new ServiceCollection(); | ||
services.AddHttpClient("TransformerBee", client => | ||
{ | ||
client.BaseAddress = new Uri("http://localhost:1234"); // <-- no service running under this address | ||
}); | ||
var serviceProvider = services.BuildServiceProvider(); | ||
var client = new TransformerBeeRestClient(serviceProvider.GetService<IHttpClientFactory>()); | ||
Check warning on line 38 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ConnectionTests.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 38 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ConnectionTests.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 38 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ConnectionTests.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 38 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ConnectionTests.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 38 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ConnectionTests.cs GitHub Actions / test (ubuntu-latest, 8.0.100)
Check warning on line 38 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ConnectionTests.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 38 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ConnectionTests.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 38 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ConnectionTests.cs GitHub Actions / test (ubuntu-latest, 8.0.100)
Check warning on line 38 in TransformerBeeClient/TransformerBeeClient.IntegrationTest/ConnectionTests.cs GitHub Actions / test (ubuntu-latest, 8.0.100)
|
||
var checkIfIsAvailable = async () => await client.IsAvailable(); | ||
await checkIfIsAvailable.Should().ThrowAsync<HttpRequestException>(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using FluentAssertions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Xunit; | ||
|
||
namespace TransformerBeeClient.UnitTest; | ||
|
||
public class ConnectionTests | ||
{ | ||
[Fact] | ||
public void IsAvailable_Throws_ArgumentNullException_If_BaseAddress_Is_Not_Configured() | ||
{ | ||
var services = new ServiceCollection(); | ||
services.AddHttpClient("TransformerBee", client => | ||
{ | ||
client.BaseAddress = null; | ||
}); | ||
var serviceProvider = services.BuildServiceProvider(); | ||
var instantiateClient = () => new TransformerBeeRestClient(serviceProvider.GetService<IHttpClientFactory>()); | ||
Check warning on line 18 in TransformerBeeClient/TransformerBeeClient.UnitTest/ConnectionTests.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 18 in TransformerBeeClient/TransformerBeeClient.UnitTest/ConnectionTests.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 18 in TransformerBeeClient/TransformerBeeClient.UnitTest/ConnectionTests.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 18 in TransformerBeeClient/TransformerBeeClient.UnitTest/ConnectionTests.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 18 in TransformerBeeClient/TransformerBeeClient.UnitTest/ConnectionTests.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 18 in TransformerBeeClient/TransformerBeeClient.UnitTest/ConnectionTests.cs GitHub Actions / test (ubuntu-latest, 8.0.100)
Check warning on line 18 in TransformerBeeClient/TransformerBeeClient.UnitTest/ConnectionTests.cs GitHub Actions / test (ubuntu-latest, 8.0.100)
Check warning on line 18 in TransformerBeeClient/TransformerBeeClient.UnitTest/ConnectionTests.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 18 in TransformerBeeClient/TransformerBeeClient.UnitTest/ConnectionTests.cs GitHub Actions / test (ubuntu-latest, 8.0.100)
|
||
instantiateClient.Should().Throw<ArgumentNullException>(); | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=de4efd69_002D9f4a_002D4e00_002D83fa_002Ddaa381865bd8/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="ConnectionTest" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
 | ||
<TestAncestor>
 | ||
<TestId>xUnit::80EF1570-CB4E-4E56-A8BC-56C787A48543::net8.0::TransformerBeeClient.UnitTest.ConnectionTests</TestId>
 | ||
</TestAncestor>
 | ||
</SessionState></s:String></wpf:ResourceDictionary> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
namespace TransformerBeeClient; | ||
|
||
/// <summary> | ||
/// a client for the transformer.bee REST API | ||
/// </summary> | ||
public class TransformerBeeRestClient | ||
{ | ||
private readonly HttpClient _httpClient; | ||
|
||
/// <summary> | ||
/// Provide the constructor with a http client factory. | ||
/// It will create a client from said factory and use the <paramref name="clientName"/> for that. | ||
/// </summary> | ||
/// <param name="httpClientFactory">factory to create the http client from</param> | ||
/// <param name="clientName">name used to create the client</param> | ||
public TransformerBeeRestClient(IHttpClientFactory httpClientFactory, string clientName = "TransformerBee") | ||
{ | ||
_httpClient = httpClientFactory.CreateClient(clientName); | ||
if (_httpClient.BaseAddress == null) | ||
{ | ||
throw new ArgumentNullException(nameof(httpClientFactory), $"The http client factory must provide a base address for the client with name '{clientName}'"); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// tests if transformer bee is available | ||
/// </summary> | ||
/// <remarks> | ||
/// Note that this does _not_ check if you're authenticated. | ||
/// The method will probably throw an <see cref="HttpRequestException"/> if the host cannot be found. | ||
/// </remarks> | ||
/// <returns> | ||
/// Returns true iff the transformer bee is available under the configured base address. | ||
/// </returns> | ||
public async Task<bool> IsAvailable() | ||
{ | ||
var uriBuilder = new UriBuilder(_httpClient!.BaseAddress) | ||
Check warning on line 37 in TransformerBeeClient/TransformerBeeClient/RestClient.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 37 in TransformerBeeClient/TransformerBeeClient/RestClient.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 37 in TransformerBeeClient/TransformerBeeClient/RestClient.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 37 in TransformerBeeClient/TransformerBeeClient/RestClient.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 37 in TransformerBeeClient/TransformerBeeClient/RestClient.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 37 in TransformerBeeClient/TransformerBeeClient/RestClient.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 37 in TransformerBeeClient/TransformerBeeClient/RestClient.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 37 in TransformerBeeClient/TransformerBeeClient/RestClient.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 37 in TransformerBeeClient/TransformerBeeClient/RestClient.cs GitHub Actions / test (ubuntu-latest, 7.0.100)
Check warning on line 37 in TransformerBeeClient/TransformerBeeClient/RestClient.cs GitHub Actions / test (ubuntu-latest, 8.0.100)
Check warning on line 37 in TransformerBeeClient/TransformerBeeClient/RestClient.cs GitHub Actions / test (ubuntu-latest, 8.0.100)
Check warning on line 37 in TransformerBeeClient/TransformerBeeClient/RestClient.cs GitHub Actions / test (ubuntu-latest, 8.0.100)
Check warning on line 37 in TransformerBeeClient/TransformerBeeClient/RestClient.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 37 in TransformerBeeClient/TransformerBeeClient/RestClient.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 37 in TransformerBeeClient/TransformerBeeClient/RestClient.cs GitHub Actions / test (ubuntu-latest, 6.0.201)
Check warning on line 37 in TransformerBeeClient/TransformerBeeClient/RestClient.cs GitHub Actions / test (ubuntu-latest, 8.0.100)
Check warning on line 37 in TransformerBeeClient/TransformerBeeClient/RestClient.cs GitHub Actions / test (ubuntu-latest, 8.0.100)
|
||
{ | ||
Path = "/version" | ||
}; | ||
|
||
var versionUrl = uriBuilder.Uri.AbsoluteUri; | ||
var response = await _httpClient.GetAsync(versionUrl); | ||
return response.IsSuccessStatusCode; | ||
} | ||
} |