diff --git a/test/Client/Core.Tests/DependencyInjection/ServiceCollectionExtensionsTests.cs b/test/Client/Core.Tests/DependencyInjection/ServiceCollectionExtensionsTests.cs index 7347d61f..a9386a73 100644 --- a/test/Client/Core.Tests/DependencyInjection/ServiceCollectionExtensionsTests.cs +++ b/test/Client/Core.Tests/DependencyInjection/ServiceCollectionExtensionsTests.cs @@ -8,8 +8,22 @@ namespace Microsoft.DurableTask.Client.Tests; public class ServiceCollectionExtensionsTests { + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData("MyBuilder")] + public void AddDurableTaskClient_SameInstance(string? name) + { + ServiceCollection services = new(); + IDurableTaskClientBuilder actual1 = services.AddDurableTaskClient(name); + IDurableTaskClientBuilder actual2 = services.AddDurableTaskClient(name); + + actual1.Should().NotBeNull(); + actual1.Should().BeSameAs(actual2); + } + [Fact] - public void AddDurableTaskClient_SameInstance() + public void AddDurableTaskClient_SameInstance2() { ServiceCollection services = new(); IDurableTaskClientBuilder? actual1 = null; @@ -21,6 +35,73 @@ public void AddDurableTaskClient_SameInstance() actual1.Should().BeSameAs(actual2); } + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData("MyBuilder")] + public void AddDurableTaskClient_SameInstance3(string name) + { + ServiceCollection services = new(); + IDurableTaskClientBuilder? actual1 = null; + IDurableTaskClientBuilder? actual2 = null; + services.AddDurableTaskClient(name, builder => actual1 = builder); + services.AddDurableTaskClient(name, builder => actual2 = builder); + + actual1.Should().NotBeNull(); + actual1.Should().BeSameAs(actual2); + } + + [Fact] + public void AddDurableTaskClient_SameInstance4() + { + ServiceCollection services = new(); + IDurableTaskClientBuilder actual1 = services.AddDurableTaskClient(); + IDurableTaskClientBuilder? actual2 = null; + services.AddDurableTaskClient(builder => actual2 = builder); + + actual1.Should().NotBeNull(); + actual1.Should().BeSameAs(actual2); + } + + [Fact] + public void AddDurableTaskClient_DifferentNames_NotSame() + { + ServiceCollection services = new(); + IDurableTaskClientBuilder actual1 = services.AddDurableTaskClient(); + IDurableTaskClientBuilder actual2 = services.AddDurableTaskClient("MyBuilder"); + + actual1.Should().NotBeNull(); + actual2.Should().NotBeNull(); + actual1.Should().NotBeSameAs(actual2); + } + + [Fact] + public void AddDurableTaskClient_DifferentNames_NotSame2() + { + ServiceCollection services = new(); + IDurableTaskClientBuilder? actual1 = null; + IDurableTaskClientBuilder? actual2 = null; + services.AddDurableTaskClient(builder => actual1 = builder); + services.AddDurableTaskClient("MyBuilder", builder => actual2 = builder); + + actual1.Should().NotBeNull(); + actual2.Should().NotBeNull(); + actual1.Should().NotBeSameAs(actual2); + } + + [Fact] + public void AddDurableTaskClient_DifferentNames_NotSame3() + { + ServiceCollection services = new(); + IDurableTaskClientBuilder actual1 = services.AddDurableTaskClient(); + IDurableTaskClientBuilder? actual2 = null; + services.AddDurableTaskClient("MyBuilder", builder => actual2 = builder); + + actual1.Should().NotBeNull(); + actual2.Should().NotBeNull(); + actual1.Should().NotBeSameAs(actual2); + } + [Fact] public void AddDurableTaskClient_HostedServiceAdded() { diff --git a/test/Worker/Core.Tests/DependencyInjection/ServiceCollectionExtensionsTests.cs b/test/Worker/Core.Tests/DependencyInjection/ServiceCollectionExtensionsTests.cs index 672d6eee..e584da9c 100644 --- a/test/Worker/Core.Tests/DependencyInjection/ServiceCollectionExtensionsTests.cs +++ b/test/Worker/Core.Tests/DependencyInjection/ServiceCollectionExtensionsTests.cs @@ -9,8 +9,22 @@ namespace Microsoft.DurableTask.Worker.Tests; public class ServiceCollectionExtensionsTests { + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData("MyBuilder")] + public void AddDurableTaskWorker_SameInstance(string? name) + { + ServiceCollection services = new(); + IDurableTaskWorkerBuilder actual1 = services.AddDurableTaskWorker(name); + IDurableTaskWorkerBuilder actual2 = services.AddDurableTaskWorker(name); + + actual1.Should().NotBeNull(); + actual1.Should().BeSameAs(actual2); + } + [Fact] - public void AddDurableTaskWorker_SameInstance() + public void AddDurableTaskWorker_SameInstance2() { ServiceCollection services = new(); IDurableTaskWorkerBuilder? actual1 = null; @@ -22,6 +36,73 @@ public void AddDurableTaskWorker_SameInstance() actual1.Should().BeSameAs(actual2); } + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData("MyBuilder")] + public void AddDurableTaskWorker_SameInstance3(string name) + { + ServiceCollection services = new(); + IDurableTaskWorkerBuilder? actual1 = null; + IDurableTaskWorkerBuilder? actual2 = null; + services.AddDurableTaskWorker(name, builder => actual1 = builder); + services.AddDurableTaskWorker(name, builder => actual2 = builder); + + actual1.Should().NotBeNull(); + actual1.Should().BeSameAs(actual2); + } + + [Fact] + public void AddDurableTaskWorker_SameInstance4() + { + ServiceCollection services = new(); + IDurableTaskWorkerBuilder actual1 = services.AddDurableTaskWorker(); + IDurableTaskWorkerBuilder? actual2 = null; + services.AddDurableTaskWorker(builder => actual2 = builder); + + actual1.Should().NotBeNull(); + actual1.Should().BeSameAs(actual2); + } + + [Fact] + public void AddDurableTaskWorker_DifferentNames_NotSame() + { + ServiceCollection services = new(); + IDurableTaskWorkerBuilder actual1 = services.AddDurableTaskWorker(); + IDurableTaskWorkerBuilder actual2 = services.AddDurableTaskWorker("MyBuilder"); + + actual1.Should().NotBeNull(); + actual2.Should().NotBeNull(); + actual1.Should().NotBeSameAs(actual2); + } + + [Fact] + public void AddDurableTaskWorker_DifferentNames_NotSame2() + { + ServiceCollection services = new(); + IDurableTaskWorkerBuilder? actual1 = null; + IDurableTaskWorkerBuilder? actual2 = null; + services.AddDurableTaskWorker(builder => actual1 = builder); + services.AddDurableTaskWorker("MyBuilder", builder => actual2 = builder); + + actual1.Should().NotBeNull(); + actual2.Should().NotBeNull(); + actual1.Should().NotBeSameAs(actual2); + } + + [Fact] + public void AddDurableTaskWorker_DifferentNames_NotSame3() + { + ServiceCollection services = new(); + IDurableTaskWorkerBuilder actual1 = services.AddDurableTaskWorker(); + IDurableTaskWorkerBuilder? actual2 = null; + services.AddDurableTaskWorker("MyBuilder", builder => actual2 = builder); + + actual1.Should().NotBeNull(); + actual2.Should().NotBeNull(); + actual1.Should().NotBeSameAs(actual2); + } + [Fact] public void AddDurableTaskWorker_HostedServiceAdded() {