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

[DRAFT] Adding test coverage - validate arguments of public methods #7575

Draft
wants to merge 65 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
52233f3
update qdrant public api tests
Zombach Feb 12, 2025
9942980
Merge pull request #5 from Zombach/validate-arguments-of-public-metho…
Zombach Feb 12, 2025
a28abe5
update redis public api tests
Zombach Feb 12, 2025
80aaefa
Merge pull request #6 from Zombach/validate-arguments-of-public-metho…
Zombach Feb 12, 2025
e0dfaa0
update python public api tests
Zombach Feb 12, 2025
84ca198
Merge pull request #7 from Zombach/validate-arguments-of-public-metho…
Zombach Feb 12, 2025
f7b7841
update testing public api tests
Zombach Feb 12, 2025
8b7bc56
Merge pull request #8 from Zombach/validate-arguments-of-public-metho…
Zombach Feb 12, 2025
698bc2e
update sql server public api tests
Zombach Feb 12, 2025
0f3be62
Merge pull request #10 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 12, 2025
4df0e82
Merge branch 'dotnet:main' into validate-arguments-of-public-methods
Zombach Feb 13, 2025
2b3cc6b
update rabbitMQ public api tests
Zombach Feb 13, 2025
7200c79
Merge pull request #11 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 13, 2025
e2bfe71
Merge branch 'dotnet:main' into validate-arguments-of-public-methods
Zombach Feb 13, 2025
c57af56
Merge branch 'dotnet:main' into validate-arguments-of-public-methods
Zombach Feb 13, 2025
5a8166e
update postgre sql public api tests
Zombach Feb 13, 2025
3d8f9ed
Merge pull request #12 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 13, 2025
995c6ff
Merge branch 'dotnet:main' into validate-arguments-of-public-methods
Zombach Feb 13, 2025
ef51446
update nodeJs public api tests
Zombach Feb 13, 2025
f95aaea
Merge pull request #13 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 13, 2025
d5fa6cf
update nats public api tests
Zombach Feb 13, 2025
82973fe
Merge pull request #14 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 13, 2025
55ef55f
update my sql public api tests
Zombach Feb 13, 2025
dd96813
Merge pull request #15 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 13, 2025
0d22a1c
update mongo db public api tests
Zombach Feb 13, 2025
bf6e043
Merge pull request #16 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 13, 2025
2ef2db3
update milvus public api tests
Zombach Feb 14, 2025
6166ff3
Merge pull request #17 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 14, 2025
950f69a
Merge branch 'dotnet:main' into validate-arguments-of-public-methods
Zombach Feb 14, 2025
24f0ddb
Merge branch 'dotnet:main' into validate-arguments-of-public-methods
Zombach Feb 15, 2025
9568a23
update keycloak public api tests
Zombach Feb 15, 2025
030eee8
Merge pull request #18 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 15, 2025
31ef42f
update kafka public api tests
Zombach Feb 15, 2025
f80a4d0
Merge pull request #19 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 15, 2025
d5ed502
update garnet public api tests
Zombach Feb 15, 2025
b979f9a
Merge pull request #20 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 15, 2025
6063d3a
update elasticsearch public api tests
Zombach Feb 15, 2025
163f29d
Merge pull request #21 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 15, 2025
2682cde
add azure aI open aI public api tests
Zombach Feb 15, 2025
84bbdc7
Merge pull request #22 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 15, 2025
57f6a4d
Merge branch 'dotnet:main' into validate-arguments-of-public-methods
Zombach Feb 19, 2025
4bbbad9
up to actual main
Zombach Feb 20, 2025
1a5876d
update azure data tables public api tests
Zombach Feb 20, 2025
d4b588c
Merge pull request #23 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 20, 2025
7922940
update messaging event hub public api tests
Zombach Feb 20, 2025
713b520
Merge pull request #24 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 20, 2025
6751b13
update messaging service bus public api tests
Zombach Feb 20, 2025
baa1ed9
Merge pull request #25 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 20, 2025
221f695
update messaging web pub sub public api tests
Zombach Feb 20, 2025
d7ccb27
Merge pull request #26 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 20, 2025
1231b54
update search documents public api tests
Zombach Feb 20, 2025
aa7cfa9
Merge pull request #27 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 20, 2025
1c34c99
update security key vault public api tests
Zombach Feb 20, 2025
d49338a
update storage blobs public api tests
Zombach Feb 20, 2025
71f8599
update storage queues public api test
Zombach Feb 20, 2025
7dacbeb
Merge pull request #30 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 20, 2025
a302b4b
Merge pull request #28 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 20, 2025
44dd6b7
Merge pull request #29 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 20, 2025
d17b6af
update confluent kafka public api test
Zombach Feb 20, 2025
2bee03c
Merge pull request #31 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 20, 2025
d5da0da
update elastic clients elasticsearch public api test
Zombach Feb 20, 2025
f6a2de4
Merge pull request #32 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 20, 2025
aa19753
update keycloack authentication public api test
Zombach Feb 20, 2025
e3db78e
Merge pull request #33 from Zombach/validate-arguments-of-public-meth…
Zombach Feb 20, 2025
7daaf35
Merge branch 'dotnet:main' into validate-arguments-of-public-methods
Zombach Feb 20, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static IResourceBuilder<ElasticsearchResource> AddElasticsearch(
int? port = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(name);
ArgumentException.ThrowIfNullOrEmpty(name);

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

Expand Down Expand Up @@ -146,7 +146,7 @@ public static IResourceBuilder<ElasticsearchResource> WithDataVolume(this IResou
public static IResourceBuilder<ElasticsearchResource> WithDataBindMount(this IResourceBuilder<ElasticsearchResource> builder, string source)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(source);
ArgumentException.ThrowIfNullOrEmpty(source);

return builder.WithBindMount(source, "/usr/share/elasticsearch/data");
}
Expand Down
14 changes: 4 additions & 10 deletions src/Aspire.Hosting.Elasticsearch/ElasticsearchResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace Aspire.Hosting.ApplicationModel;
/// <summary>
/// A resource that represents a Elasticsearch
/// </summary>
public class ElasticsearchResource : ContainerResource, IResourceWithConnectionString
/// <param name="name">The name of the resource.</param>
/// <param name="password">A parameter that contains the Elasticsearch superuser password.</param>
public class ElasticsearchResource(string name, ParameterResource password) : ContainerResource(name), IResourceWithConnectionString
{
/// <summary>
/// Gets the Elasticsearch container superuser name.
Expand All @@ -22,14 +24,6 @@ public class ElasticsearchResource : ContainerResource, IResourceWithConnectionS
//For things like cluster updates, master elections, nodes joining/leaving, shard allocation
internal const string InternalEndpointName = "internal";

/// <param name="name">The name of the resource.</param>
/// <param name="password">A parameter that contains the Elasticsearch superuser password.</param>
public ElasticsearchResource(string name, ParameterResource password) : base(name)
{
ArgumentNullException.ThrowIfNull(password);
PasswordParameter = password;
}

private EndpointReference? _primaryEndpoint;
private EndpointReference? _internalEndpoint;

Expand All @@ -46,7 +40,7 @@ public ElasticsearchResource(string name, ParameterResource password) : base(nam
/// <summary>
/// Gets the parameter that contains the Elasticsearch superuser password.
/// </summary>
public ParameterResource PasswordParameter { get; }
public ParameterResource PasswordParameter { get; } = password ?? throw new ArgumentNullException(nameof(password));

/// <summary>
/// Gets the connection string expression for the Elasticsearch
Expand Down
4 changes: 2 additions & 2 deletions src/Aspire.Hosting.Garnet/GarnetBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static IResourceBuilder<GarnetResource> AddGarnet(this IDistributedApplic
int? port = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(name);
ArgumentException.ThrowIfNullOrEmpty(name);

var garnet = new GarnetResource(name);

Expand Down Expand Up @@ -140,7 +140,7 @@ public static IResourceBuilder<GarnetResource> WithDataBindMount(this IResourceB
string source, bool isReadOnly = false)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(source);
ArgumentException.ThrowIfNullOrEmpty(source);

builder.WithBindMount(source, GarnetContainerDataDirectory, isReadOnly);
if (!isReadOnly)
Expand Down
8 changes: 1 addition & 7 deletions src/Aspire.Hosting.Garnet/GarnetResource.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
// 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>
/// A resource that represents a Garnet resource independent of the hosting model.
/// </summary>
/// <param name="name">The name of the resource.</param>
public class GarnetResource(string name) : ContainerResource(ThrowIfNull(name)), IResourceWithConnectionString
public class GarnetResource(string name) : ContainerResource(name), IResourceWithConnectionString
{
internal const string PrimaryEndpointName = "tcp";

Expand All @@ -26,7 +23,4 @@ public class GarnetResource(string name) : ContainerResource(ThrowIfNull(name)),
/// </summary>
public ReferenceExpression ConnectionStringExpression =>
ReferenceExpression.Create($"{PrimaryEndpoint.Property(EndpointProperty.HostAndPort)}");

private static string ThrowIfNull([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
=> argument ?? throw new ArgumentNullException(paramName);
}
4 changes: 2 additions & 2 deletions src/Aspire.Hosting.Kafka/KafkaBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static class KafkaBuilderExtensions
public static IResourceBuilder<KafkaServerResource> AddKafka(this IDistributedApplicationBuilder builder, [ResourceName] string name, int? port = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(name);
ArgumentException.ThrowIfNullOrEmpty(name);

var kafka = new KafkaServerResource(name);

Expand Down Expand Up @@ -190,7 +190,7 @@ public static IResourceBuilder<KafkaServerResource> WithDataVolume(this IResourc
public static IResourceBuilder<KafkaServerResource> WithDataBindMount(this IResourceBuilder<KafkaServerResource> builder, string source, bool isReadOnly = false)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(source);
ArgumentException.ThrowIfNullOrEmpty(source);

return builder
.WithEnvironment(ConfigureLogDirs)
Expand Down
10 changes: 2 additions & 8 deletions src/Aspire.Hosting.Keycloak/KeycloakResource.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// 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 @@ -13,7 +10,7 @@ namespace Aspire.Hosting.ApplicationModel;
/// <param name="adminPassword">A parameter that contains the Keycloak admin password.</param>
/// </summary>
public sealed class KeycloakResource(string name, ParameterResource? admin, ParameterResource adminPassword)
: ContainerResource(ThrowIfNull(name)), IResourceWithServiceDiscovery
: ContainerResource(name), IResourceWithServiceDiscovery
{
private const string DefaultAdmin = "admin";
internal const string PrimaryEndpointName = "tcp";
Expand All @@ -31,8 +28,5 @@ AdminUserNameParameter is not null ?
/// <summary>
/// Gets the parameter that contains the Keycloak admin password.
/// </summary>
public ParameterResource AdminPasswordParameter { get; } = ThrowIfNull(adminPassword);

private static T ThrowIfNull<T>([NotNull] T? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
=> argument ?? throw new ArgumentNullException(paramName);
public ParameterResource AdminPasswordParameter { get; } = adminPassword ?? throw new ArgumentNullException(nameof(adminPassword));
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static IResourceBuilder<KeycloakResource> AddKeycloak(
IResourceBuilder<ParameterResource>? adminPassword = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(name);
ArgumentException.ThrowIfNullOrEmpty(name);

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

Expand Down Expand Up @@ -128,7 +128,7 @@ public static IResourceBuilder<KeycloakResource> WithDataVolume(this IResourceBu
public static IResourceBuilder<KeycloakResource> WithDataBindMount(this IResourceBuilder<KeycloakResource> builder, string source)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(source);
ArgumentException.ThrowIfNullOrEmpty(source);

return builder.WithBindMount(source, "/opt/keycloak/data", false);
}
Expand Down Expand Up @@ -156,7 +156,7 @@ public static IResourceBuilder<KeycloakResource> WithRealmImport(
bool isReadOnly = false)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(import);
ArgumentException.ThrowIfNullOrEmpty(import);

var importFullPath = Path.GetFullPath(import, builder.ApplicationBuilder.AppHostDirectory);

Expand Down
12 changes: 8 additions & 4 deletions src/Aspire.Hosting.Milvus/MilvusBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public static IResourceBuilder<MilvusServerResource> AddMilvus(this IDistributed
int? grpcPort = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(name);
ArgumentException.ThrowIfNullOrEmpty(name);

var apiKeyParameter = apiKey?.Resource ??
ParameterResourceBuilderExtensions.CreateDefaultPasswordParameter(builder, $"{name}-key");

Expand Down Expand Up @@ -94,7 +95,7 @@ public static IResourceBuilder<MilvusServerResource> AddMilvus(this IDistributed
public static IResourceBuilder<MilvusDatabaseResource> AddDatabase(this IResourceBuilder<MilvusServerResource> builder, [ResourceName] string name, string? databaseName = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(name);
ArgumentException.ThrowIfNullOrEmpty(name);

// Use the resource name as the database name if it's not provided
databaseName ??= name;
Expand Down Expand Up @@ -156,6 +157,7 @@ public static IResourceBuilder<T> WithAttu<T>(this IResourceBuilder<T> builder,
public static IResourceBuilder<MilvusServerResource> WithDataVolume(this IResourceBuilder<MilvusServerResource> builder, string? name = null, bool isReadOnly = false)
{
ArgumentNullException.ThrowIfNull(builder);

return builder.WithVolume(name ?? VolumeNameGenerator.Generate(builder, "data"), "/var/lib/milvus", isReadOnly);
}

Expand All @@ -169,7 +171,8 @@ public static IResourceBuilder<MilvusServerResource> WithDataVolume(this IResour
public static IResourceBuilder<MilvusServerResource> WithDataBindMount(this IResourceBuilder<MilvusServerResource> builder, string source, bool isReadOnly = false)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(source);
ArgumentException.ThrowIfNullOrEmpty(source);

return builder.WithBindMount(source, "/var/lib/milvus", isReadOnly);
}

Expand All @@ -182,7 +185,8 @@ public static IResourceBuilder<MilvusServerResource> WithDataBindMount(this IRes
public static IResourceBuilder<MilvusServerResource> WithConfigurationBindMount(this IResourceBuilder<MilvusServerResource> builder, string configurationFilePath)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(configurationFilePath);
ArgumentException.ThrowIfNullOrEmpty(configurationFilePath);

return builder.WithBindMount(configurationFilePath, "/milvus/configs/milvus.yaml");
}

Expand Down
12 changes: 10 additions & 2 deletions src/Aspire.Hosting.Milvus/MilvusDatabaseResource.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 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;
using Aspire.Hosting.Milvus;

namespace Aspire.Hosting.ApplicationModel;
Expand All @@ -16,7 +18,7 @@ public class MilvusDatabaseResource(string name, string databaseName, MilvusServ
/// <summary>
/// Gets the parent Milvus container resource.
/// </summary>
public MilvusServerResource Parent { get; } = parent;
public MilvusServerResource Parent { get; } = parent ?? throw new ArgumentNullException(nameof(parent));

/// <summary>
/// Gets the connection string expression for the Milvus database.
Expand All @@ -27,5 +29,11 @@ public class MilvusDatabaseResource(string name, string databaseName, MilvusServ
/// <summary>
/// Gets the database name.
/// </summary>
public string DatabaseName { get; } = databaseName;
public string DatabaseName { get; } = ThrowIfNullOrEmpty(databaseName);

private static string ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
ArgumentException.ThrowIfNullOrEmpty(argument, paramName);
return argument;
}
}
11 changes: 6 additions & 5 deletions src/Aspire.Hosting.MongoDB/MongoDBBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static IResourceBuilder<MongoDBServerResource> AddMongoDB(this IDistribut
IResourceBuilder<ParameterResource>? password = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(name);
ArgumentException.ThrowIfNullOrEmpty(name);

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

Expand Down Expand Up @@ -100,7 +100,7 @@ public static IResourceBuilder<MongoDBServerResource> AddMongoDB(this IDistribut
public static IResourceBuilder<MongoDBDatabaseResource> AddDatabase(this IResourceBuilder<MongoDBServerResource> builder, [ResourceName] string name, string? databaseName = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(name);
ArgumentException.ThrowIfNullOrEmpty(name);

// Use the resource name as the database name if it's not provided
databaseName ??= name;
Expand Down Expand Up @@ -144,7 +144,8 @@ public static IResourceBuilder<MongoDBDatabaseResource> AddDatabase(this IResour
/// <param name="configureContainer">Configuration callback for Mongo Express container resource.</param>
/// <param name="containerName">The name of the container (Optional).</param>
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<T> WithMongoExpress<T>(this IResourceBuilder<T> builder, Action<IResourceBuilder<MongoExpressContainerResource>>? configureContainer = null, string? containerName = null) where T : MongoDBServerResource
public static IResourceBuilder<T> WithMongoExpress<T>(this IResourceBuilder<T> builder, Action<IResourceBuilder<MongoExpressContainerResource>>? configureContainer = null, string? containerName = null)
where T : MongoDBServerResource
{
ArgumentNullException.ThrowIfNull(builder);

Expand Down Expand Up @@ -204,7 +205,7 @@ public static IResourceBuilder<MongoDBServerResource> WithDataVolume(this IResou
public static IResourceBuilder<MongoDBServerResource> WithDataBindMount(this IResourceBuilder<MongoDBServerResource> builder, string source, bool isReadOnly = false)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(source);
ArgumentException.ThrowIfNullOrEmpty(source);

return builder.WithBindMount(source, "/data/db", isReadOnly);
}
Expand All @@ -219,7 +220,7 @@ public static IResourceBuilder<MongoDBServerResource> WithDataBindMount(this IRe
public static IResourceBuilder<MongoDBServerResource> WithInitBindMount(this IResourceBuilder<MongoDBServerResource> builder, string source, bool isReadOnly = true)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(source);
ArgumentException.ThrowIfNullOrEmpty(source);

return builder.WithBindMount(source, "/docker-entrypoint-initdb.d", isReadOnly);
}
Expand Down
34 changes: 16 additions & 18 deletions src/Aspire.Hosting.MongoDB/MongoDBDatabaseResource.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
// 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>
/// A resource that represents a MongoDB database. This is a child resource of a <see cref="MongoDBServerResource"/>.
/// </summary>
public class MongoDBDatabaseResource : Resource, IResourceWithParent<MongoDBServerResource>, IResourceWithConnectionString
/// <param name="name">The name of the resource.</param>
/// <param name="databaseName">The database name.</param>
/// <param name="parent">The MongoDB server resource associated with this database.</param>
public class MongoDBDatabaseResource(string name, string databaseName, MongoDBServerResource parent)
: Resource(name), IResourceWithParent<MongoDBServerResource>, IResourceWithConnectionString
{
/// <summary>
/// A resource that represents a MongoDB database. This is a child resource of a <see cref="MongoDBServerResource"/>.
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="databaseName">The database name.</param>
/// <param name="parent">The MongoDB server resource associated with this database.</param>
public MongoDBDatabaseResource(string name, string databaseName, MongoDBServerResource parent) : base(name)
{
ArgumentNullException.ThrowIfNull(databaseName);
ArgumentNullException.ThrowIfNull(parent);

Parent = parent;
DatabaseName = databaseName;
}

/// <summary>
/// Gets the connection string expression for the MongoDB database.
/// </summary>
Expand All @@ -31,10 +23,16 @@ public MongoDBDatabaseResource(string name, string databaseName, MongoDBServerRe
/// <summary>
/// Gets the parent MongoDB container resource.
/// </summary>
public MongoDBServerResource Parent { get; }
public MongoDBServerResource Parent { get; } = parent ?? throw new ArgumentNullException(nameof(parent));

/// <summary>
/// Gets the database name.
/// </summary>
public string DatabaseName { get; }
public string DatabaseName { get; } = ThrowIfNullOrEmpty(databaseName);

private static string ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
ArgumentException.ThrowIfNullOrEmpty(argument, paramName);
return argument;
}
}
8 changes: 4 additions & 4 deletions src/Aspire.Hosting.MySql/MySqlBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static class MySqlBuilderExtensions
public static IResourceBuilder<MySqlServerResource> AddMySql(this IDistributedApplicationBuilder builder, [ResourceName] string name, IResourceBuilder<ParameterResource>? password = null, int? port = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(name);
ArgumentException.ThrowIfNullOrEmpty(name);

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

Expand Down Expand Up @@ -71,7 +71,7 @@ public static IResourceBuilder<MySqlServerResource> AddMySql(this IDistributedAp
public static IResourceBuilder<MySqlDatabaseResource> AddDatabase(this IResourceBuilder<MySqlServerResource> builder, [ResourceName] string name, string? databaseName = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(name);
ArgumentException.ThrowIfNullOrEmpty(name);

// Use the resource name as the database name if it's not provided
databaseName ??= name;
Expand Down Expand Up @@ -216,7 +216,7 @@ public static IResourceBuilder<MySqlServerResource> WithDataVolume(this IResourc
public static IResourceBuilder<MySqlServerResource> WithDataBindMount(this IResourceBuilder<MySqlServerResource> builder, string source, bool isReadOnly = false)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(source);
ArgumentException.ThrowIfNullOrEmpty(source);

return builder.WithBindMount(source, "/var/lib/mysql", isReadOnly);
}
Expand All @@ -231,7 +231,7 @@ public static IResourceBuilder<MySqlServerResource> WithDataBindMount(this IReso
public static IResourceBuilder<MySqlServerResource> WithInitBindMount(this IResourceBuilder<MySqlServerResource> builder, string source, bool isReadOnly = true)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(source);
ArgumentException.ThrowIfNullOrEmpty(source);

return builder.WithBindMount(source, "/docker-entrypoint-initdb.d", isReadOnly);
}
Expand Down
Loading
Loading