|
// 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.Kafka.Tests;
public class KafkaPublicApiTests
{
[Fact]
public void AddKafkaContainerShouldThrowWhenBuilderIsNull()
{
IDistributedApplicationBuilder builder = null!;
const string name = "Kafka";
var action = () => builder.AddKafka(name);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}
[Fact]
public void AddKafkaContainerShouldThrowWhenNameIsNull()
{
var builder = DistributedApplication.CreateBuilder([]);
string name = null!;
var action = () => builder.AddKafka(name);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(name), exception.ParamName);
}
[Fact]
public void WithDataVolumeShouldThrowWhenBuilderIsNull()
{
IResourceBuilder<KafkaServerResource> builder = null!;
var action = () => builder.WithDataVolume();
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}
[Fact]
public void WithDataBindMountShouldThrowWhenBuilderIsNull()
{
IResourceBuilder<KafkaServerResource> builder = null!;
const string source = "/Kafka/data";
var action = () => builder.WithDataBindMount(source);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}
[Fact]
public void WithDataBindMountShouldThrowWhenSourceIsNull()
{
var builderResource = TestDistributedApplicationBuilder.Create();
var Kafka = builderResource.AddKafka("Kafka");
string source = null!;
var action = () => Kafka.WithDataBindMount(source);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(source), exception.ParamName);
}
[Fact]
public void WithKafkaUIShouldThrowWhenBuilderIsNull()
{
IResourceBuilder<KafkaServerResource> builder = null!;
var action = () => builder.WithKafkaUI();
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}
[Fact]
public void WithHostPortShouldThrowWhenBuilderIsNull()
{
IResourceBuilder<KafkaUIContainerResource> builder = null!;
var action = () => builder.WithHostPort(9936);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}
[Fact]
public void CtorKafkaServerResourceShouldThrowWhenNameIsNull()
{
string name = null!;
var action = () => new KafkaServerResource(name);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(name), exception.ParamName);
}
[Fact]
public void CtorKafkaUIContainerResourceShouldThrowWhenNameIsNull()
{
string name = null!;
var action = () => new KafkaUIContainerResource(name);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(name), exception.ParamName);
}
}
|