|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Utils;
using Xunit;
namespace Aspire.Hosting.Valkey.Tests;
public class ValkeyPublicApiTests
{
[Fact]
public void AddValkeyShouldThrowWhenBuilderIsNull()
{
IDistributedApplicationBuilder builder = null!;
const string name = "valkey";
var action = () => builder.AddValkey(name);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void AddValkeyShouldThrowWhenNameIsNullOrEmpty(bool isNull)
{
var builder = TestDistributedApplicationBuilder.Create();
var name = isNull ? null! : string.Empty;
var action = () => builder.AddValkey(name);
var exception = isNull
? Assert.Throws<ArgumentNullException>(action)
: Assert.Throws<ArgumentException>(action);
Assert.Equal(nameof(name), exception.ParamName);
}
[Fact]
public void WithDataVolumeShouldThrowWhenBuilderIsNull()
{
IResourceBuilder<ValkeyResource> builder = null!;
var action = () => builder.WithDataVolume();
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}
[Fact]
public void WithDataBindMountShouldThrowWhenBuilderIsNull()
{
IResourceBuilder<ValkeyResource> builder = null!;
const string source = "/data";
var action = () => builder.WithDataBindMount(source);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void WithDataBindMountShouldThrowWhenSourceIsNullOrEmpty(bool isNull)
{
var builder = TestDistributedApplicationBuilder.Create()
.AddValkey("valkey");
var source = isNull ? null! : string.Empty;
var action = () => builder.WithDataBindMount(source);
var exception = isNull
? Assert.Throws<ArgumentNullException>(action)
: Assert.Throws<ArgumentException>(action);
Assert.Equal(nameof(source), exception.ParamName);
}
[Fact]
public void WithPersistenceBindMountShouldThrowWhenBuilderIsNull()
{
IResourceBuilder<ValkeyResource> builder = null!;
var action = () => builder.WithPersistence();
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void CtorValkeyResourceShouldThrowWhenNameIsNullOrEmpty(bool isNull)
{
var name = isNull ? null! : string.Empty;
var action = () => new ValkeyResource(name);
var exception = isNull
? Assert.Throws<ArgumentNullException>(action)
: Assert.Throws<ArgumentException>(action);
Assert.Equal(nameof(name), exception.ParamName);
}
}
|