Skip to content

Commit

Permalink
WIP: Added Unit Testing projects
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmwebb-lv committed Nov 2, 2024
1 parent db6ce60 commit 3bfb8f8
Show file tree
Hide file tree
Showing 74 changed files with 1,048 additions and 549 deletions.
190 changes: 140 additions & 50 deletions Examples/Examples.sln

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Src\RCommon.ApplicationServices\RCommon.ApplicationServices.csproj" />
</ItemGroup>

</Project>
63 changes: 63 additions & 0 deletions Tests/RCommon.Caching.Tests/CacheKeyTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Moq;
using NUnit.Framework;
using RCommon.Caching;
using System;

namespace RCommon.Caching.Tests
{
[TestFixture]
public class CacheKeyTests
{
private MockRepository mockRepository;



[SetUp]
public void SetUp()
{
this.mockRepository = new MockRepository(MockBehavior.Strict);


}

private CacheKey CreateCacheKey()
{
return new CacheKey(
TODO);
}

[Test]
public void With_StateUnderTest_ExpectedBehavior()
{
// Arrange
var cacheKey = this.CreateCacheKey();
string[] keys = null;

// Act
var result = cacheKey.With(
keys);

// Assert
Assert.Fail();
this.mockRepository.VerifyAll();
}

[Test]
public void With_StateUnderTest_ExpectedBehavior1()
{
// Arrange
var cacheKey = this.CreateCacheKey();
Type ownerType = null;
string[] keys = null;

// Act
var result = cacheKey.With(
ownerType,
keys);

// Assert
Assert.Fail();
this.mockRepository.VerifyAll();
}
}
}
File renamed without changes.
32 changes: 32 additions & 0 deletions Tests/RCommon.Caching.Tests/RCommon.Caching.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Src\RCommon.Caching\RCommon.Caching.csproj" />
</ItemGroup>

</Project>
78 changes: 78 additions & 0 deletions Tests/RCommon.Core.Tests/EventHandling/InMemoryEventBusTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Microsoft.Extensions.DependencyInjection;
using Moq;
using NUnit.Framework;
using RCommon.EventHandling;
using System;
using System.Threading.Tasks;

namespace RCommon.Core.Tests.EventHandling
{
[TestFixture]
public class InMemoryEventBusTests
{
private MockRepository mockRepository;

private Mock<IServiceProvider> mockServiceProvider;
private Mock<IServiceCollection> mockServiceCollection;

[SetUp]
public void SetUp()
{
this.mockRepository = new MockRepository(MockBehavior.Strict);

this.mockServiceProvider = this.mockRepository.Create<IServiceProvider>();
this.mockServiceCollection = this.mockRepository.Create<IServiceCollection>();
}

private InMemoryEventBus CreateInMemoryEventBus()
{
return new InMemoryEventBus(
this.mockServiceProvider.Object,
this.mockServiceCollection.Object);
}

[Test]
public void Subscribe_StateUnderTest_ExpectedBehavior()
{
// Arrange
var inMemoryEventBus = this.CreateInMemoryEventBus();

// Act
var result = inMemoryEventBus.Subscribe();

// Assert
Assert.Fail();
this.mockRepository.VerifyAll();
}

[Test]
public void SubscribeAllHandledEvents_StateUnderTest_ExpectedBehavior()
{
// Arrange
var inMemoryEventBus = this.CreateInMemoryEventBus();

// Act
var result = inMemoryEventBus.SubscribeAllHandledEvents();

// Assert
Assert.Fail();
this.mockRepository.VerifyAll();
}

[Test]
public async Task PublishAsync_StateUnderTest_ExpectedBehavior()
{
// Arrange
var inMemoryEventBus = this.CreateInMemoryEventBus();
TEvent @event = default(TEvent);

// Act
await inMemoryEventBus.PublishAsync(
@event);

// Assert
Assert.Fail();
this.mockRepository.VerifyAll();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using RCommon.EventHandling.Producers;
using System;
using System.Threading.Tasks;

namespace RCommon.Core.Tests.EventHandling.Producers
{
[TestFixture]
public class InMemoryTransactionalEventRouterTests
{
private MockRepository mockRepository;

private Mock<IServiceProvider> mockServiceProvider;
private Mock<ILogger<InMemoryTransactionalEventRouter>> mockLogger;

[SetUp]
public void SetUp()
{
this.mockRepository = new MockRepository(MockBehavior.Strict);

this.mockServiceProvider = this.mockRepository.Create<IServiceProvider>();
this.mockLogger = this.mockRepository.Create<ILogger<InMemoryTransactionalEventRouter>>();
}

private InMemoryTransactionalEventRouter CreateInMemoryTransactionalEventRouter()
{
return new InMemoryTransactionalEventRouter(
this.mockServiceProvider.Object,
this.mockLogger.Object);
}

[Test]
public async Task RouteEventsAsync_StateUnderTest_ExpectedBehavior()
{
// Arrange
var inMemoryTransactionalEventRouter = this.CreateInMemoryTransactionalEventRouter();
IEnumerable transactionalEvents = null;

// Act
await inMemoryTransactionalEventRouter.RouteEventsAsync(
transactionalEvents);

// Assert
Assert.Fail();
this.mockRepository.VerifyAll();
}

[Test]
public async Task RouteEventsAsync_StateUnderTest_ExpectedBehavior1()
{
// Arrange
var inMemoryTransactionalEventRouter = this.CreateInMemoryTransactionalEventRouter();

// Act
await inMemoryTransactionalEventRouter.RouteEventsAsync();

// Assert
Assert.Fail();
this.mockRepository.VerifyAll();
}

[Test]
public void AddTransactionalEvent_StateUnderTest_ExpectedBehavior()
{
// Arrange
var inMemoryTransactionalEventRouter = this.CreateInMemoryTransactionalEventRouter();
ISerializableEvent serializableEvent = null;

// Act
inMemoryTransactionalEventRouter.AddTransactionalEvent(
serializableEvent);

// Assert
Assert.Fail();
this.mockRepository.VerifyAll();
}

[Test]
public void AddTransactionalEvents_StateUnderTest_ExpectedBehavior()
{
// Arrange
var inMemoryTransactionalEventRouter = this.CreateInMemoryTransactionalEventRouter();
IEnumerable serializableEvents = null;

// Act
inMemoryTransactionalEventRouter.AddTransactionalEvents(
serializableEvents);

// Assert
Assert.Fail();
this.mockRepository.VerifyAll();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using RCommon.EventHandling;
using RCommon.EventHandling.Producers;
using System;
using System.Threading.Tasks;

namespace RCommon.Core.Tests.EventHandling.Producers
{
[TestFixture]
public class PublishWithEventBusEventProducerTests
{
private MockRepository mockRepository;

private Mock<IEventBus> mockEventBus;
private Mock<ILogger<PublishWithEventBusEventProducer>> mockLogger;

[SetUp]
public void SetUp()
{
this.mockRepository = new MockRepository(MockBehavior.Strict);

this.mockEventBus = this.mockRepository.Create<IEventBus>();
this.mockLogger = this.mockRepository.Create<ILogger<PublishWithEventBusEventProducer>>();
}

private PublishWithEventBusEventProducer CreatePublishWithEventBusEventProducer()
{
return new PublishWithEventBusEventProducer(
this.mockEventBus.Object,
this.mockLogger.Object);
}

[Test]
public async Task ProduceEventAsync_StateUnderTest_ExpectedBehavior()
{
// Arrange
var publishWithEventBusEventProducer = this.CreatePublishWithEventBusEventProducer();
T @event = default(T);
CancellationToken cancellationToken = default(global::System.Threading.CancellationToken);

// Act
await publishWithEventBusEventProducer.ProduceEventAsync(
@event,
cancellationToken);

// Assert
Assert.Fail();
this.mockRepository.VerifyAll();
}
}
}
File renamed without changes.
Loading

0 comments on commit 3bfb8f8

Please sign in to comment.