Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/createrelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
run: |
echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}"
dotnet test "Shared.Tests\Shared.Tests.csproj"
dotnet test "Shared.EventStore.Tests\Shared.EventStore.Tests.csproj"

- name: Build Nuget Packages
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ jobs:
run: |
echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}"
dotnet test "Shared.Tests\Shared.Tests.csproj"
dotnet test "Shared.EventStore.Tests\Shared.EventStore.Tests.csproj"
105 changes: 105 additions & 0 deletions Shared.EventStore.Tests/PersistentSubscriptionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
namespace Shared.EventStore.Tests
{
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using EventHandling;
using General;
using Logger;
using Shouldly;
using SubscriptionWorker;
using Xunit;

public class PersistentSubscriptionTests
{
public PersistentSubscriptionTests()
{
Shared.Logger.Logger.Initialise(NullLogger.Instance);

TypeMap.AddType<EstateCreatedEvent>("EstateCreatedEvent");
}

[Fact]
public async Task PersistentSubscription_CanBeCreatedAndReceiveEventsSingleEventHandler()
{
PersistentSubscriptionDetails persistentSubscriptionDetails = new("$ce-test", "local-1");
List<IDomainEventHandler> eventHandlers = new();
TestDomainEventHandler eventHandler = new();
InMemoryPersistentSubscriptionsClient persistentSubscriptionsClient = new();
CancellationToken cancellationToken = CancellationToken.None;

eventHandlers.Add(eventHandler);

var persistentSubscription = PersistentSubscription.Create(persistentSubscriptionsClient, persistentSubscriptionDetails, eventHandlers);

await persistentSubscription.ConnectToSubscription(cancellationToken);

persistentSubscription.Connected.ShouldBeTrue();

String @event = "{\r\n \"estateId\": \"4fc2692f-067a-443e-8006-335bf2732248\",\r\n \"estateName\": \"Demo Estate\"\r\n}\t";

//Manually add events.
persistentSubscriptionsClient.WriteEvent(@event, "EstateCreatedEvent", cancellationToken);

//Crude - but a decent start point
eventHandler.DomainEvents.Count.ShouldBe(1);
}

[Fact]
public async Task PersistentSubscription_CanBeCreatedAndFilterOutSystemEvent()
{
PersistentSubscriptionDetails persistentSubscriptionDetails = new("$ce-test", "local-1");
List<IDomainEventHandler> eventHandlers = new();
TestDomainEventHandler eventHandler = new();
InMemoryPersistentSubscriptionsClient persistentSubscriptionsClient = new();
CancellationToken cancellationToken = CancellationToken.None;

eventHandlers.Add(eventHandler);

var persistentSubscription =
PersistentSubscription.Create(persistentSubscriptionsClient, persistentSubscriptionDetails, eventHandlers);

await persistentSubscription.ConnectToSubscription(cancellationToken);

persistentSubscription.Connected.ShouldBeTrue();

String @event = "";

//Manually add events.
persistentSubscriptionsClient.WriteEvent(@event, "$", cancellationToken);

//Crude - but a decent start point
eventHandler.DomainEvents.Count.ShouldBe(0);
}

[Fact]
public async Task PersistentSubscription_CanBeCreatedAndReceiveEventsMultipleEventHandler()
{
PersistentSubscriptionDetails persistentSubscriptionDetails = new("$ce-test", "local-1");
List<IDomainEventHandler> eventHandlers = new();
TestDomainEventHandler eventHandler1 = new();
TestDomainEventHandler eventHandler2 = new();
InMemoryPersistentSubscriptionsClient persistentSubscriptionsClient = new();
CancellationToken cancellationToken = CancellationToken.None;

eventHandlers.AddRange(new[] { eventHandler1, eventHandler2 });

var persistentSubscription =
PersistentSubscription.Create(persistentSubscriptionsClient, persistentSubscriptionDetails, eventHandlers);

await persistentSubscription.ConnectToSubscription(cancellationToken);

persistentSubscription.Connected.ShouldBeTrue();

String @event = "{\r\n \"estateId\": \"4fc2692f-067a-443e-8006-335bf2732248\",\r\n \"estateName\": \"Demo Estate\"\r\n}\t";

//Manually add events.
persistentSubscriptionsClient.WriteEvent(@event, "EstateCreatedEvent", cancellationToken);

//Crude - but a decent start point
eventHandler1.DomainEvents.Count.ShouldBe(1);
eventHandler2.DomainEvents.Count.ShouldBe(1);
}
}
}
28 changes: 28 additions & 0 deletions Shared.EventStore.Tests/Shared.EventStore.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="Moq" Version="4.16.0" />
<PackageReference Include="Shouldly" Version="4.0.3" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Shared.EventStore\Shared.EventStore.csproj" />
</ItemGroup>

</Project>
31 changes: 31 additions & 0 deletions Shared.EventStore.Tests/SubscriptionRepositoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace Shared.EventStore.Tests
{
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Shouldly;
using SubscriptionWorker;
using Xunit;

public class SubscriptionRepositoryTests
{
#region Methods

[Fact]
public async Task SubscriptionRepository_GetSubscriptions_ReturnsSubscriptions()
{
List<PersistentSubscriptionInfo> allSubscriptions = (TestData.GetPersistentSubscriptions_DemoEstate());

Func<CancellationToken, Task<List<PersistentSubscriptionInfo>>> GetAllSubscriptions = async token => allSubscriptions;

ISubscriptionRepository subscriptionRepository = SubscriptionRepository.Create(GetAllSubscriptions);

PersistentSubscriptions list = await subscriptionRepository.GetSubscriptions(true, CancellationToken.None);

list.PersistentSubscriptionInfo.Count.ShouldBe(allSubscriptions.Count);
}

#endregion
}
}
Loading