Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jviau committed Jan 24, 2025
1 parent d885f10 commit f9d5fc0
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
{
Expand Down

0 comments on commit f9d5fc0

Please sign in to comment.