Skip to content

Commit

Permalink
Merge pull request #28 from NerosoftDev/refactoring/service-bus
Browse files Browse the repository at this point in the history
Refactor unit test.
  • Loading branch information
Codespilot authored Nov 29, 2023
2 parents 9234d1a + 5ada141 commit 1b8b375
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 50 deletions.
40 changes: 40 additions & 0 deletions Tests/Euonia.Bus.InMemory.Tests/ServiceBusTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Microsoft.Extensions.Configuration;
using Nerosoft.Euonia.Bus.Tests.Commands;

namespace Nerosoft.Euonia.Bus.Tests;

public partial class ServiceBusTests
{
private readonly IBus _bus;
private readonly bool _dontRunTests;

public ServiceBusTests(IBus bus, IConfiguration configuration)
{
_bus = bus;
_dontRunTests = configuration.GetValue<bool>("DontRunTests");
}

public partial async Task TestSendCommand_HasReponse()
{
var result = await _bus.SendAsync<UserCreateCommand, int>(new UserCreateCommand());
Assert.Equal(1, result);
}

public partial async Task TestSendCommand_NoReponse()
{
await _bus.SendAsync(new UserCreateCommand());
Assert.True(true);
}

public partial async Task TestSendCommand_HasReponse_UseSubscribeAttribute()
{
var result = await _bus.SendAsync<FooCreateCommand, int>(new FooCreateCommand(), new SendOptions { Channel = "foo.create" });
Assert.Equal(1, result);
}

public partial async Task TestSendCommand_HasReponse_MessageHasResultInherites()
{
var result = await _bus.SendAsync<int>(new FooCreateCommand(), new SendOptions { Channel = "foo.create" });
Assert.Equal(1, result);
}
}
82 changes: 82 additions & 0 deletions Tests/Euonia.Bus.RabbitMq.Tests/ServiceBusTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using Microsoft.Extensions.Configuration;
using Nerosoft.Euonia.Bus.Tests.Commands;

namespace Nerosoft.Euonia.Bus.Tests;

#if DEBUG
public partial class ServiceBusTests
{
private readonly IBus _bus;
private readonly bool _dontRunTests;

public ServiceBusTests(IBus bus, IConfiguration configuration)
{
_bus = bus;
_dontRunTests = configuration.GetValue<bool>("DontRunTests");
}


public partial async Task TestSendCommand_HasReponse()
{
if (_dontRunTests)
{
return;
}
var result = await _bus.SendAsync<UserCreateCommand, int>(new UserCreateCommand());
Assert.Equal(1, result);
}

public partial async Task TestSendCommand_NoReponse()
{
if (_dontRunTests)
{
return;
}
await _bus.SendAsync(new UserCreateCommand());
Assert.True(true);
}

public partial async Task TestSendCommand_HasReponse_UseSubscribeAttribute()
{
if (_dontRunTests)
{
return;
}
var result = await _bus.SendAsync<FooCreateCommand, int>(new FooCreateCommand(), new SendOptions { Channel = "foo.create" });
Assert.Equal(1, result);
}

public partial async Task TestSendCommand_HasReponse_MessageHasResultInherites()
{
if (_dontRunTests)
{
return;
}
var result = await _bus.SendAsync<int>(new FooCreateCommand(), new SendOptions { Channel = "foo.create" });
Assert.Equal(1, result);
}
}
#else
public partial class ServiceBusTests
{
public partial async Task TestSendCommand_HasReponse()

Check warning on line 62 in Tests/Euonia.Bus.RabbitMq.Tests/ServiceBusTests.cs

View workflow job for this annotation

GitHub Actions / build (7.0.x, Release)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
Assert.True(true);
}

public partial async Task TestSendCommand_NoReponse()
{
Assert.True(true);
}

public partial async Task TestSendCommand_HasReponse_UseSubscribeAttribute()
{
Assert.True(true);
}

public partial async Task TestSendCommand_HasReponse_MessageHasResultInherites()
{
Assert.True(true);
}
}
#endif
56 changes: 6 additions & 50 deletions Tests/Euonia.Bus.Tests.Shared/ServiceBusTests.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,16 @@
using Microsoft.Extensions.Configuration;
using Nerosoft.Euonia.Bus.Tests.Commands;
namespace Nerosoft.Euonia.Bus.Tests;

namespace Nerosoft.Euonia.Bus.Tests;

public class ServiceBusTests
public partial class ServiceBusTests
{
private readonly IBus _bus;
private readonly bool _dontRunTests;

public ServiceBusTests(IBus bus, IConfiguration configuration)
{
_bus = bus;
_dontRunTests = configuration.GetValue<bool>("DontRunTests");
}

[Fact]
public async Task TestSendCommand_HasReponse()
{
if (_dontRunTests)
{
return;
}
var result = await _bus.SendAsync<UserCreateCommand, int>(new UserCreateCommand());
Assert.Equal(1, result);
}
public partial Task TestSendCommand_HasReponse();

[Fact]
public async Task TestSendCommand_NoReponse()
{
if (_dontRunTests)
{
return;
}
await _bus.SendAsync(new UserCreateCommand());
Assert.True(true);
}
public partial Task TestSendCommand_NoReponse();

[Fact]
public async Task TestSendCommand_HasReponse_UseSubscribeAttribute()
{
if (_dontRunTests)
{
return;
}
var result = await _bus.SendAsync<FooCreateCommand, int>(new FooCreateCommand(), new SendOptions { Channel = "foo.create" });
Assert.Equal(1, result);
}
public partial Task TestSendCommand_HasReponse_UseSubscribeAttribute();

[Fact]
public async Task TestSendCommand_HasReponse_MessageHasResultInherites()
{
if (_dontRunTests)
{
return;
}
var result = await _bus.SendAsync<int>(new FooCreateCommand(), new SendOptions { Channel = "foo.create" });
Assert.Equal(1, result);
}
public partial Task TestSendCommand_HasReponse_MessageHasResultInherites();
}

0 comments on commit 1b8b375

Please sign in to comment.