Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Added public api tests #574

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="NSubstitute.Analyzers.CSharp" Version="1.0.17" />
<PackageVersion Include="Oracle.ManagedDataAccess.Core" Version="23.6.1" />
<PackageVersion Include="PublicApiGenerator" Version="11.3.0" />
<PackageVersion Include="StackExchange.Redis" Version="2.8.22" />
<PackageVersion Include="System.Data.SqlClient" Version="4.9.0" />
<PackageVersion Include="System.Text.Json" Version="9.0.0" />
Expand All @@ -60,4 +61,4 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0'">
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="8.0.10" />
</ItemGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion src/NetEvolve.HealthChecks.Abstractions/SqlCheckBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/// <summary>
/// Configurable implementation of <see cref="IHealthCheck"/> with focus on <see cref="DbConnection"/> based implementations.
/// </summary>
/// <typeparam name="TConfiguration"></typeparam>
/// <typeparam name="TConfiguration">Type of Configuration</typeparam>
public abstract class SqlCheckBase<TConfiguration> : IHealthCheck
where TConfiguration : class, ISqlCheckOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,6 @@
using System.Threading;
using ArchUnitNET.Domain;
using ArchUnitNET.Loader;
using NetEvolve.HealthChecks.Apache.Kafka;
using NetEvolve.HealthChecks.Azure.Blobs;
using NetEvolve.HealthChecks.Azure.Queues;
using NetEvolve.HealthChecks.Azure.Tables;
using NetEvolve.HealthChecks.ClickHouse;
using NetEvolve.HealthChecks.Dapr;
using NetEvolve.HealthChecks.Npgsql;
using NetEvolve.HealthChecks.Oracle;
using NetEvolve.HealthChecks.Redis;
using NetEvolve.HealthChecks.Redpanda;
using NetEvolve.HealthChecks.SQLite;
using NetEvolve.HealthChecks.SqlServer;
using NetEvolve.HealthChecks.SqlServer.Legacy;
using MySqlCheck = MySql.MySqlCheck;
using MySqlConnectorCheck = MySql.Connector.MySqlCheck;

internal static class HealthCheckArchitecture
{
Expand All @@ -34,23 +19,24 @@ private static Architecture LoadArchitecture()
{
System.Reflection.Assembly[] assemblies =
[
typeof(KafkaCheck).Assembly,
typeof(BlobContainerAvailableHealthCheck).Assembly,
typeof(QueueClientAvailableHealthCheck).Assembly,
typeof(TableClientAvailableHealthCheck).Assembly,
typeof(ClickHouseCheck).Assembly,
typeof(DaprHealthCheck).Assembly,
typeof(MySqlCheck).Assembly,
typeof(MySqlConnectorCheck).Assembly,
typeof(NpgsqlCheck).Assembly,
typeof(OracleCheck).Assembly,
typeof(RedisDatabaseHealthCheck).Assembly,
typeof(RedpandaCheck).Assembly,
typeof(SQLiteCheck).Assembly,
typeof(SqlServerCheck).Assembly,
typeof(SqlServerLegacyCheck).Assembly,
typeof(Apache.Kafka.KafkaCheck).Assembly,
typeof(Azure.Blobs.BlobContainerAvailableHealthCheck).Assembly,
typeof(Azure.Queues.QueueClientAvailableHealthCheck).Assembly,
typeof(Azure.Tables.TableClientAvailableHealthCheck).Assembly,
typeof(ClickHouse.ClickHouseCheck).Assembly,
typeof(Dapr.DaprHealthCheck).Assembly,
typeof(MySql.MySqlCheck).Assembly,
typeof(MySql.Connector.MySqlCheck).Assembly,
typeof(Npgsql.NpgsqlCheck).Assembly,
typeof(Oracle.OracleCheck).Assembly,
typeof(Redis.RedisDatabaseHealthCheck).Assembly,
typeof(Redpanda.RedpandaCheck).Assembly,
typeof(SQLite.SQLiteCheck).Assembly,
typeof(SqlServer.SqlServerCheck).Assembly,
typeof(SqlServer.Legacy.SqlServerLegacyCheck).Assembly,
];
var architecture = new ArchLoader()

return new ArchLoader()
.LoadAssembliesRecursively(
assemblies,
x =>
Expand All @@ -62,6 +48,5 @@ private static Architecture LoadArchitecture()
: FilterResult.SkipAndContinue
)
.Build();
return architecture;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageReference Include="Microsoft.Extensions.Azure" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NetEvolve.Extensions.XUnit" />
<PackageReference Include="PublicApiGenerator" />
<PackageReference Include="Testcontainers.Azurite" />
<PackageReference Include="Testcontainers.ClickHouse" />
<PackageReference Include="Testcontainers.Kafka" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
namespace NetEvolve.HealthChecks.Tests.Integration;

using System.ComponentModel;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using PublicApiGenerator;

public class PublicApiTests
{
private static readonly string[] _excludedAttributes =
[
typeof(InternalsVisibleToAttribute).FullName!,
"System.Runtime.CompilerServices.IsByRefLikeAttribute",
typeof(TargetFrameworkAttribute).FullName!,
typeof(CLSCompliantAttribute).FullName!,
typeof(AssemblyMetadataAttribute).FullName!,
typeof(NeutralResourcesLanguageAttribute).FullName!,
typeof(AttributeUsageAttribute).FullName!,
];

[Theory]
[MemberData(nameof(GetAssemblies))]
public Task PublicApi_HasNotChanged_Theory(Assembly assembly)
{
Assert.NotNull(assembly);

var types = assembly.GetTypes().Where(IsVisibleToIntelliSense).ToArray();

var options = new ApiGeneratorOptions
{
ExcludeAttributes = _excludedAttributes,
IncludeTypes = types,
};

var publicApi = assembly.GeneratePublicApi(options);

return Verify(publicApi).UseTypeName(assembly.GetName().Name);
}

public static TheoryData<Assembly> GetAssemblies
{
get
{
var assemblies = Assembly
.GetExecutingAssembly()!
.GetReferencedAssemblies()
.Where(a =>
a.Name?.StartsWith("NetEvolve.HealthChecks", StringComparison.OrdinalIgnoreCase)
== true
)
.Select(Assembly.Load)
.ToArray();

var data = new TheoryData<Assembly>();
data.AddRange(assemblies);
return data;
}
}

private static bool IsVisibleToIntelliSense(Type type)
{
var browsable = type.GetCustomAttribute<BrowsableAttribute>();
if (browsable is null || browsable.Browsable)
{
return true;
}

var editorBrowsable = type.GetCustomAttribute<EditorBrowsableAttribute>();
return editorBrowsable is null || editorBrowsable.State != EditorBrowsableState.Never;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace NetEvolve.HealthChecks.Apache.Kafka
{
public static class DependencyInjectionExtensions
{
public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddKafka([System.Diagnostics.CodeAnalysis.NotNull] this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, [System.Diagnostics.CodeAnalysis.NotNull] string name, System.Action<NetEvolve.HealthChecks.Apache.Kafka.KafkaOptions>? options = null, params string[] tags) { }
}
public class KafkaOptions
{
public KafkaOptions() { }
public Confluent.Kafka.ProducerConfig Configuration { get; set; }
public NetEvolve.HealthChecks.Apache.Kafka.ProducerHandleMode Mode { get; set; }
public int Timeout { get; set; }
public string Topic { get; set; }
}
public enum ProducerHandleMode
{
ServiceProvider = 0,
Create = 1,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace NetEvolve.HealthChecks.Azure.Blobs
{
public enum BlobClientCreationMode
{
ServiceProvider = 0,
DefaultAzureCredentials = 1,
ConnectionString = 2,
SharedKey = 3,
AzureSasCredential = 4,
}
public sealed class BlobContainerAvailableOptions
{
public BlobContainerAvailableOptions() { }
public string? AccountKey { get; set; }
public string? AccountName { get; set; }
public System.Action<Azure.Storage.Blobs.BlobClientOptions>? ConfigureClientOptions { get; set; }
public string? ConnectionString { get; set; }
public string? ContainerName { get; set; }
public NetEvolve.HealthChecks.Azure.Blobs.BlobClientCreationMode Mode { get; set; }
public System.Uri? ServiceUri { get; set; }
public int Timeout { get; set; }
}
public sealed class BlobServiceAvailableOptions
{
public BlobServiceAvailableOptions() { }
public string? AccountKey { get; set; }
public string? AccountName { get; set; }
public System.Action<Azure.Storage.Blobs.BlobClientOptions>? ConfigureClientOptions { get; set; }
public string? ConnectionString { get; set; }
public NetEvolve.HealthChecks.Azure.Blobs.BlobClientCreationMode Mode { get; set; }
public System.Uri? ServiceUri { get; set; }
public int Timeout { get; set; }
}
public static class DependencyInjectionExtensions
{
public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddBlobContainerAvailability([System.Diagnostics.CodeAnalysis.NotNull] this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, [System.Diagnostics.CodeAnalysis.NotNull] string name, System.Action<NetEvolve.HealthChecks.Azure.Blobs.BlobContainerAvailableOptions>? options = null, params string[] tags) { }
public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddBlobServiceAvailability([System.Diagnostics.CodeAnalysis.NotNull] this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, [System.Diagnostics.CodeAnalysis.NotNull] string name, System.Action<NetEvolve.HealthChecks.Azure.Blobs.BlobServiceAvailableOptions>? options = null, params string[] tags) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace NetEvolve.HealthChecks.Azure.Queues
{
public static class DependencyInjectionExtensions
{
public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddQueueClientAvailability([System.Diagnostics.CodeAnalysis.NotNull] this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, [System.Diagnostics.CodeAnalysis.NotNull] string name, System.Action<NetEvolve.HealthChecks.Azure.Queues.QueueClientAvailableOptions>? options = null, params string[] tags) { }
public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddQueueServiceAvailability([System.Diagnostics.CodeAnalysis.NotNull] this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, [System.Diagnostics.CodeAnalysis.NotNull] string name, System.Action<NetEvolve.HealthChecks.Azure.Queues.QueueServiceAvailableOptions>? options = null, params string[] tags) { }
}
public sealed class QueueClientAvailableOptions
{
public QueueClientAvailableOptions() { }
public string? AccountKey { get; set; }
public string? AccountName { get; set; }
public System.Action<Azure.Storage.Queues.QueueClientOptions>? ConfigureClientOptions { get; set; }
public string? ConnectionString { get; set; }
public NetEvolve.HealthChecks.Azure.Queues.QueueClientCreationMode Mode { get; set; }
public string? QueueName { get; set; }
public System.Uri? ServiceUri { get; set; }
public int Timeout { get; set; }
}
public enum QueueClientCreationMode
{
ServiceProvider = 0,
DefaultAzureCredentials = 1,
ConnectionString = 2,
SharedKey = 3,
AzureSasCredential = 4,
}
public sealed class QueueServiceAvailableOptions
{
public QueueServiceAvailableOptions() { }
public string? AccountKey { get; set; }
public string? AccountName { get; set; }
public System.Action<Azure.Storage.Queues.QueueClientOptions>? ConfigureClientOptions { get; set; }
public string? ConnectionString { get; set; }
public NetEvolve.HealthChecks.Azure.Queues.QueueClientCreationMode Mode { get; set; }
public System.Uri? ServiceUri { get; set; }
public int Timeout { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace NetEvolve.HealthChecks.Azure.Tables
{
public static class DependencyInjectionExtensions
{
public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddTableClientAvailability([System.Diagnostics.CodeAnalysis.NotNull] this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, [System.Diagnostics.CodeAnalysis.NotNull] string name, System.Action<NetEvolve.HealthChecks.Azure.Tables.TableClientAvailableOptions>? options = null, params string[] tags) { }
public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddTableServiceAvailability([System.Diagnostics.CodeAnalysis.NotNull] this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, [System.Diagnostics.CodeAnalysis.NotNull] string name, System.Action<NetEvolve.HealthChecks.Azure.Tables.TableServiceAvailableOptions>? options = null, params string[] tags) { }
}
public sealed class TableClientAvailableOptions
{
public TableClientAvailableOptions() { }
public string? AccountKey { get; set; }
public string? AccountName { get; set; }
public System.Action<Azure.Data.Tables.TableClientOptions>? ConfigureClientOptions { get; set; }
public string? ConnectionString { get; set; }
public NetEvolve.HealthChecks.Azure.Tables.TableClientCreationMode Mode { get; set; }
public System.Uri? ServiceUri { get; set; }
public string? TableName { get; set; }
public int Timeout { get; set; }
}
public enum TableClientCreationMode
{
ServiceProvider = 0,
DefaultAzureCredentials = 1,
ConnectionString = 2,
SharedKey = 3,
AzureSasCredential = 4,
}
public sealed class TableServiceAvailableOptions
{
public TableServiceAvailableOptions() { }
public string? AccountKey { get; set; }
public string? AccountName { get; set; }
public System.Action<Azure.Data.Tables.TableClientOptions>? ConfigureClientOptions { get; set; }
public string? ConnectionString { get; set; }
public NetEvolve.HealthChecks.Azure.Tables.TableClientCreationMode Mode { get; set; }
public System.Uri? ServiceUri { get; set; }
public int Timeout { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace NetEvolve.HealthChecks.ClickHouse
{
public sealed class ClickHouseOptions : NetEvolve.HealthChecks.Abstractions.ISqlCheckOptions
{
public ClickHouseOptions() { }
public string Command { get; }
public string ConnectionString { get; set; }
public int Timeout { get; set; }
}
public static class DependencyInjectionExtensions
{
public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddClickHouse([System.Diagnostics.CodeAnalysis.NotNull] this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, [System.Diagnostics.CodeAnalysis.NotNull] string name, System.Action<NetEvolve.HealthChecks.ClickHouse.ClickHouseOptions>? options = null, params string[] tags) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace NetEvolve.HealthChecks.MySql.Connector
{
public static class DependencyInjectionExtensions
{
public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddMySql([System.Diagnostics.CodeAnalysis.NotNull] this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, [System.Diagnostics.CodeAnalysis.NotNull] string name, System.Action<NetEvolve.HealthChecks.MySql.Connector.MySqlOptions>? options = null, params string[] tags) { }
}
public sealed class MySqlOptions : NetEvolve.HealthChecks.Abstractions.ISqlCheckOptions
{
public MySqlOptions() { }
public string Command { get; }
public string ConnectionString { get; set; }
public int Timeout { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace NetEvolve.HealthChecks.MySql
{
public static class DependencyInjectionExtensions
{
public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddMySql([System.Diagnostics.CodeAnalysis.NotNull] this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, [System.Diagnostics.CodeAnalysis.NotNull] string name, System.Action<NetEvolve.HealthChecks.MySql.MySqlOptions>? options = null, params string[] tags) { }
}
public sealed class MySqlOptions : NetEvolve.HealthChecks.Abstractions.ISqlCheckOptions
{
public MySqlOptions() { }
public string Command { get; }
public string ConnectionString { get; set; }
public int Timeout { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace NetEvolve.HealthChecks.Npgsql
{
public static class DependencyInjectionExtensions
{
public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddPostgreSql([System.Diagnostics.CodeAnalysis.NotNull] this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, [System.Diagnostics.CodeAnalysis.NotNull] string name, System.Action<NetEvolve.HealthChecks.Npgsql.NpgsqlOptions>? options = null, params string[] tags) { }
}
public sealed class NpgsqlOptions : NetEvolve.HealthChecks.Abstractions.ISqlCheckOptions
{
public NpgsqlOptions() { }
public string Command { get; }
public string ConnectionString { get; set; }
public int Timeout { get; set; }
}
}
Loading
Loading