| File: MessagingWebPubSubPublicApiTests.cs | Web Access |
| Project: src\tests\Aspire.Azure.Messaging.WebPubSub.Tests\Aspire.Azure.Messaging.WebPubSub.Tests.csproj (Aspire.Azure.Messaging.WebPubSub.Tests) |
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.Extensions.Hosting; using Xunit; namespace Aspire.Azure.Messaging.WebPubSub.Tests; public class MessagingWebPubSubPublicApiTests { [Fact] public void AddAzureWebPubSubServiceClientShouldThrowWhenBuilderIsNull() { IHostApplicationBuilder builder = null!; const string connectionName = "wps"; var action = () => builder.AddAzureWebPubSubServiceClient(connectionName); var exception = Assert.Throws<ArgumentNullException>(action); Assert.Equal(nameof(builder), exception.ParamName); } [Theory] [InlineData(true)] [InlineData(false)] public void AddAzureWebPubSubServiceClientShouldThrowWhenConnectionNameIsNullOrEmpty(bool isNull) { var builder = Host.CreateEmptyApplicationBuilder(null); var connectionName = isNull ? null! : string.Empty; var action = () => builder.AddAzureWebPubSubServiceClient(connectionName); var exception = isNull ? Assert.Throws<ArgumentNullException>(action) : Assert.Throws<ArgumentException>(action); Assert.Equal(nameof(connectionName), exception.ParamName); } [Fact] public void AddKeyedAzureWebPubSubServiceClientShouldThrowWhenBuilderIsNull() { IHostApplicationBuilder builder = null!; const string connectionName = "wps"; const string serviceKey = "wps"; var action = () => builder.AddKeyedAzureWebPubSubServiceClient(connectionName, serviceKey); var exception = Assert.Throws<ArgumentNullException>(action); Assert.Equal(nameof(builder), exception.ParamName); } [Theory] [InlineData(true)] [InlineData(false)] public void AddKeyedAzureWebPubSubServiceClientShouldThrowWhenConnectionNameIsNullOrEmpty(bool isNull) { var builder = Host.CreateEmptyApplicationBuilder(null); var connectionName = isNull ? null! : string.Empty; const string serviceKey = "wps"; var action = () => builder.AddKeyedAzureWebPubSubServiceClient(connectionName, serviceKey); var exception = isNull ? Assert.Throws<ArgumentNullException>(action) : Assert.Throws<ArgumentException>(action); Assert.Equal(nameof(connectionName), exception.ParamName); } [Theory] [InlineData(true)] [InlineData(false)] public void AddKeyedAzureWebPubSubServiceClientShouldThrowWhenServiceKeyIsNullOrEmpty(bool isNull) { var builder = Host.CreateEmptyApplicationBuilder(null); const string connectionName = "wps"; var serviceKey = isNull ? null! : string.Empty; var action = () => builder.AddKeyedAzureWebPubSubServiceClient(connectionName, serviceKey); var exception = isNull ? Assert.Throws<ArgumentNullException>(action) : Assert.Throws<ArgumentException>(action); Assert.Equal(nameof(serviceKey), exception.ParamName); } }