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

Adding public API test coverage #5407

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cf7703c
Aspire.Pomelo.EntityFrameworkCore.MySql
Zombach Aug 23, 2024
7305248
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Zombach Aug 24, 2024
153120b
Aspire.Qdrant.Client
Zombach Aug 24, 2024
8e4b27b
Aspire.RabbitMQ.Client
Zombach Aug 24, 2024
eb0895e
Aspire.Seq
Zombach Aug 24, 2024
218deb1
Aspire.StackExchange.Redis
Zombach Aug 24, 2024
f22026e
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Zombach Aug 25, 2024
023da20
Aspire.Hosting.Oracle
Zombach Aug 25, 2024
14c84ec
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Zombach Aug 27, 2024
c3239e0
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Zombach Aug 29, 2024
3650093
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Zombach Aug 31, 2024
72d128e
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Zombach Sep 8, 2024
3ed38d3
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Zombach Sep 12, 2024
63639c8
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Zombach Sep 16, 2024
6e765c3
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Zombach Sep 19, 2024
fe3857b
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Zombach Sep 21, 2024
14438c4
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Zombach Sep 25, 2024
67a3477
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Zombach Sep 26, 2024
8701d01
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Zombach Sep 29, 2024
89f49b7
Merge branch 'main' into validate-arguments-of-public-methods#part-3
Zombach Oct 14, 2024
eec2a04
Fix merge main
Zombach Oct 14, 2024
261c14b
fix merge
Zombach Oct 14, 2024
527ec96
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Zombach Oct 15, 2024
8d1d5de
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Zombach Oct 16, 2024
d0fa4db
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Zombach Oct 19, 2024
7731160
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Zombach Oct 24, 2024
2f28f1c
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Zombach Oct 27, 2024
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
34 changes: 30 additions & 4 deletions src/Aspire.Hosting.Oracle/OracleDatabaseBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public static class OracleDatabaseBuilderExtensions
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<OracleDatabaseServerResource> AddOracle(this IDistributedApplicationBuilder builder, [ResourceName] string name, IResourceBuilder<ParameterResource>? password = null, int? port = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(name);

var passwordParameter = password?.Resource ?? ParameterResourceBuilderExtensions.CreateDefaultPasswordParameter(builder, $"{name}-password");

var oracleDatabaseServer = new OracleDatabaseServerResource(name, passwordParameter);
Expand Down Expand Up @@ -67,6 +70,9 @@ public static IResourceBuilder<OracleDatabaseServerResource> AddOracle(this IDis
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<OracleDatabaseResource> AddDatabase(this IResourceBuilder<OracleDatabaseServerResource> builder, [ResourceName] string name, string? databaseName = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(name);

// Use the resource name as the database name if it's not provided
databaseName ??= name;

Expand All @@ -82,7 +88,12 @@ public static IResourceBuilder<OracleDatabaseResource> AddDatabase(this IResourc
/// <param name="name">The name of the volume. Defaults to an auto-generated name based on the application and resource names.</param>
/// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<OracleDatabaseServerResource> WithDataVolume(this IResourceBuilder<OracleDatabaseServerResource> builder, string? name = null)
=> builder.WithVolume(name ?? VolumeNameGenerator.CreateVolumeName(builder, "data"), "/opt/oracle/oradata", false);
{
ArgumentNullException.ThrowIfNull(builder);

return builder.WithVolume(name ?? VolumeNameGenerator.CreateVolumeName(builder, "data"), "/opt/oracle/oradata",
false);
}

/// <summary>
/// Adds a bind mount for the data folder to a Oracle Database server container resource.
Expand All @@ -91,7 +102,12 @@ public static IResourceBuilder<OracleDatabaseServerResource> WithDataVolume(this
/// <param name="source">The source directory on the host to mount into the container.</param>
/// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<OracleDatabaseServerResource> WithDataBindMount(this IResourceBuilder<OracleDatabaseServerResource> builder, string source)
=> builder.WithBindMount(source, "/opt/oracle/oradata", false);
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(source);

return builder.WithBindMount(source, "/opt/oracle/oradata", false);
}

/// <summary>
/// Adds a bind mount for the init folder to a Oracle Database server container resource.
Expand All @@ -100,7 +116,12 @@ public static IResourceBuilder<OracleDatabaseServerResource> WithDataBindMount(t
/// <param name="source">The source directory on the host to mount into the container.</param>
/// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<OracleDatabaseServerResource> WithInitBindMount(this IResourceBuilder<OracleDatabaseServerResource> builder, string source)
=> builder.WithBindMount(source, "/opt/oracle/scripts/startup", false);
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(source);

return builder.WithBindMount(source, "/opt/oracle/scripts/startup", false);
}

/// <summary>
/// Adds a bind mount for the database setup folder to a Oracle Database server container resource.
Expand All @@ -109,5 +130,10 @@ public static IResourceBuilder<OracleDatabaseServerResource> WithInitBindMount(t
/// <param name="source">The source directory on the host to mount into the container.</param>
/// <returns>The <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<OracleDatabaseServerResource> WithDbSetupBindMount(this IResourceBuilder<OracleDatabaseServerResource> builder, string source)
=> builder.WithBindMount(source, "/opt/oracle/scripts/setup", false);
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(source);

return builder.WithBindMount(source, "/opt/oracle/scripts/setup", false);
}
}
23 changes: 20 additions & 3 deletions src/Aspire.Hosting.Oracle/OracleDatabaseResource.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace Aspire.Hosting.ApplicationModel;

/// <summary>
Expand All @@ -9,12 +12,12 @@ namespace Aspire.Hosting.ApplicationModel;
/// <param name="name">The name of the resource.</param>
/// <param name="databaseName">The database name.</param>
/// <param name="parent">The Oracle Database parent resource associated with this database.</param>
public class OracleDatabaseResource(string name, string databaseName, OracleDatabaseServerResource parent) : Resource(name), IResourceWithParent<OracleDatabaseServerResource>, IResourceWithConnectionString
public class OracleDatabaseResource(string name, string databaseName, OracleDatabaseServerResource parent) : Resource(ThrowIfNullOrEmpty(name)), IResourceWithParent<OracleDatabaseServerResource>, IResourceWithConnectionString
{
/// <summary>
/// Gets the parent Oracle container resource.
/// </summary>
public OracleDatabaseServerResource Parent { get; } = parent;
public OracleDatabaseServerResource Parent { get; } = ThrowIfNullOrEmpty(parent);

/// <summary>
/// Gets the connection string expression for the Oracle Database.
Expand All @@ -25,5 +28,19 @@ public class OracleDatabaseResource(string name, string databaseName, OracleData
/// <summary>
/// Gets the database name.
/// </summary>
public string DatabaseName { get; } = databaseName;
public string DatabaseName { get; } = ThrowIfNullOrEmpty(databaseName);

private static T ThrowIfNullOrEmpty<T>([NotNull] T? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
ArgumentNullException.ThrowIfNull(argument, paramName);

if (argument is not string str)
{
return argument;
}

ArgumentException.ThrowIfNullOrEmpty(str, paramName);
return argument;

}
}
21 changes: 19 additions & 2 deletions src/Aspire.Hosting.Oracle/OracleDatabaseServerResource.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace Aspire.Hosting.ApplicationModel;

/// <summary>
Expand All @@ -15,9 +18,9 @@ public class OracleDatabaseServerResource : ContainerResource, IResourceWithConn
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="password">A parameter that contains the Oracle Database server password.</param>
public OracleDatabaseServerResource(string name, ParameterResource password) : base(name)
public OracleDatabaseServerResource(string name, ParameterResource password) : base(ThrowIfNullOrEmpty(name))
{
ArgumentNullException.ThrowIfNull(password);
ThrowIfNullOrEmpty(password);

PrimaryEndpoint = new(this, PrimaryEndpointName);
PasswordParameter = password;
Expand Down Expand Up @@ -51,4 +54,18 @@ internal void AddDatabase(string name, string databaseName)
{
_databases.TryAdd(name, databaseName);
}

private static T ThrowIfNullOrEmpty<T>([NotNull] T? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
ArgumentNullException.ThrowIfNull(argument, paramName);

if (argument is not string str)
{
return argument;
}

ArgumentException.ThrowIfNullOrEmpty(str, paramName);
return argument;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static partial class AspireEFMySqlExtensions
Action<DbContextOptionsBuilder>? configureDbContextOptions = null) where TContext : DbContext
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(connectionName);

builder.EnsureDbContextNotRegistered<TContext>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public static void AddQdrantClient(
string connectionName,
Action<QdrantClientSettings>? configureSettings = null)
{
ArgumentException.ThrowIfNullOrEmpty(connectionName);

AddQdrant(builder, configureSettings, connectionName, serviceKey: null);
}

Expand All @@ -47,6 +49,8 @@ public static void AddKeyedQdrantClient(
string name,
Action<QdrantClientSettings>? configureSettings = null)
{
ArgumentException.ThrowIfNullOrEmpty(name);

AddQdrant(builder, configureSettings, connectionName: name, serviceKey: name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Logging;
using Polly;
using Polly.Retry;
using RabbitMQ.Client;
Expand Down Expand Up @@ -40,7 +39,11 @@ public static void AddRabbitMQClient(
string connectionName,
Action<RabbitMQClientSettings>? configureSettings = null,
Action<ConnectionFactory>? configureConnectionFactory = null)
=> AddRabbitMQClient(builder, configureSettings, configureConnectionFactory, connectionName, serviceKey: null);
{
ArgumentException.ThrowIfNullOrEmpty(connectionName);

AddRabbitMQClient(builder, configureSettings, configureConnectionFactory, connectionName, serviceKey: null);
}

/// <summary>
/// Registers <see cref="IConnection"/> as a keyed singleton for the given <paramref name="name"/> in the services provided by the <paramref name="builder"/>.
Expand Down
7 changes: 5 additions & 2 deletions src/Components/Aspire.Seq/AspireSeqExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static void AddSeqEndpoint(
Action<SeqSettings>? configureSettings = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(connectionName);

var settings = new SeqSettings();
settings.Logs.Protocol = OtlpExportProtocol.HttpProtobuf;
Expand Down Expand Up @@ -63,13 +64,15 @@ public static void AddSeqEndpoint(
}

builder.Services.Configure<OpenTelemetryLoggerOptions>(logging => logging.AddProcessor(
_ => settings.Logs.ExportProcessorType switch {
_ => settings.Logs.ExportProcessorType switch
{
ExportProcessorType.Batch => new BatchLogRecordExportProcessor(new OtlpLogExporter(settings.Logs)),
_ => new SimpleLogRecordExportProcessor(new OtlpLogExporter(settings.Logs))
}));

builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddProcessor(
_ => settings.Traces.ExportProcessorType switch {
_ => settings.Traces.ExportProcessorType switch
{
ExportProcessorType.Batch => new BatchActivityExportProcessor(new OtlpTraceExporter(settings.Traces)),
_ => new SimpleActivityExportProcessor(new OtlpTraceExporter(settings.Traces))
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public static class AspireRedisDistributedCacheExtensions
/// </remarks>
public static void AddRedisDistributedCache(this IHostApplicationBuilder builder, string connectionName, Action<StackExchangeRedisSettings>? configureSettings = null, Action<ConfigurationOptions>? configureOptions = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(connectionName);

builder.AddRedisClient(connectionName, configureSettings, configureOptions);

builder.AddRedisDistributedCacheCore((RedisCacheOptions options, IServiceProvider sp) =>
Expand All @@ -52,6 +55,9 @@ public static void AddRedisDistributedCache(this IHostApplicationBuilder builder
/// </remarks>
public static void AddKeyedRedisDistributedCache(this IHostApplicationBuilder builder, string name, Action<StackExchangeRedisSettings>? configureSettings = null, Action<ConfigurationOptions>? configureOptions = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(name);

builder.AddKeyedRedisClient(name, configureSettings, configureOptions);

builder.AddRedisDistributedCacheCore((RedisCacheOptions options, IServiceProvider sp) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public static class AspireRedisOutputCacheExtensions
/// </remarks>
public static void AddRedisOutputCache(this IHostApplicationBuilder builder, string connectionName, Action<StackExchangeRedisSettings>? configureSettings = null, Action<ConfigurationOptions>? configureOptions = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(connectionName);

builder.AddRedisClient(connectionName, configureSettings, configureOptions);

builder.AddRedisOutputCacheCore((RedisOutputCacheOptions options, IServiceProvider sp) =>
Expand All @@ -51,6 +54,9 @@ public static void AddRedisOutputCache(this IHostApplicationBuilder builder, str
/// </remarks>
public static void AddKeyedRedisOutputCache(this IHostApplicationBuilder builder, string name, Action<StackExchangeRedisSettings>? configureSettings = null, Action<ConfigurationOptions>? configureOptions = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(name);

builder.AddKeyedRedisClient(name, configureSettings, configureOptions);

builder.AddRedisOutputCacheCore((RedisOutputCacheOptions options, IServiceProvider sp) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public static void AddRedisClient(
string connectionName,
Action<StackExchangeRedisSettings>? configureSettings = null,
Action<ConfigurationOptions>? configureOptions = null)
=> AddRedisClient(builder, configureSettings, configureOptions, connectionName, serviceKey: null);
{
ArgumentException.ThrowIfNullOrEmpty(connectionName);

AddRedisClient(builder, configureSettings, configureOptions, connectionName, serviceKey: null);
}

/// <summary>
/// Registers <see cref="IConnectionMultiplexer"/> as a keyed singleton for the given <paramref name="name"/> in the services provided by the <paramref name="builder"/>.
Expand Down
Loading