Skip to content

Commit

Permalink
SBT-9722 Upgrade Aggregate Repository Event Store to use ES GRPC Clie…
Browse files Browse the repository at this point in the history
…nt (#10)
  • Loading branch information
SamBucaMatthews authored Nov 3, 2022
1 parent 4630a25 commit bbcaa07
Show file tree
Hide file tree
Showing 15 changed files with 242 additions and 381 deletions.
3 changes: 0 additions & 3 deletions build.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ if [ -n "$2" ]; then tag="$2"
fi
tag=${tag/tags\//}

curl -o nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
.\\nuget.exe restore .\\src\\AggregateRepository.EventStore.Tests\\AggregateRepository.EventStore.Tests.csproj -PackagesDirectory .\\src\\packages -Verbosity detailed

dotnet test .\\src\\AggregateRepository.EventStore.Tests\\AggregateRepository.EventStore.Tests.csproj
if %errorlevel% neq 0 exit /b %errorlevel%

Expand Down
Original file line number Diff line number Diff line change
@@ -1,145 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.NET.Test.Sdk.15.7.2\build\net45\Microsoft.Net.Test.Sdk.props" Condition="Exists('..\packages\Microsoft.NET.Test.Sdk.15.7.2\build\net45\Microsoft.Net.Test.Sdk.props')" />
<Import Project="..\packages\Microsoft.CodeCoverage.15.8.0-preview-20180610-02\build\netstandard1.0\Microsoft.CodeCoverage.props" Condition="Exists('..\packages\Microsoft.CodeCoverage.15.8.0-preview-20180610-02\build\netstandard1.0\Microsoft.CodeCoverage.props')" />
<Import Project="..\packages\NUnit3TestAdapter.3.10.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.10.0\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\packages\NUnit.3.10.1\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.10.1\build\NUnit.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6972CC70-3F3B-4CBF-8829-CF61A3EE47E5}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CorshamScience.AggregateRepository.EventStore.Tests</RootNamespace>
<AssemblyName>CorshamScience.AggregateRepository.EventStore.Tests</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>
</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="CorshamScience.AggregateRepository.Core, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CorshamScience.AggregateRepository.Core.2.0.0\lib\netstandard2.0\CorshamScience.AggregateRepository.Core.dll</HintPath>
</Reference>
<Reference Include="EventStore.BufferManagement, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EventStore.Client.Embedded.5.0.0\lib\net471\EventStore.BufferManagement.dll</HintPath>
</Reference>
<Reference Include="EventStore.ClientAPI, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EventStore.Client.Embedded.5.0.0\lib\net471\EventStore.ClientAPI.dll</HintPath>
</Reference>
<Reference Include="EventStore.ClientAPI.Embedded, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EventStore.Client.Embedded.5.0.0\lib\net471\EventStore.ClientAPI.Embedded.dll</HintPath>
</Reference>
<Reference Include="EventStore.Common, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EventStore.Client.Embedded.5.0.0\lib\net471\EventStore.Common.dll</HintPath>
</Reference>
<Reference Include="EventStore.Common.Utils, Version=5.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EventStore.Client.Embedded.5.0.0\lib\net471\EventStore.Common.Utils.dll</HintPath>
</Reference>
<Reference Include="EventStore.Core, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EventStore.Client.Embedded.5.0.0\lib\net471\EventStore.Core.dll</HintPath>
</Reference>
<Reference Include="EventStore.Native, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EventStore.Client.Embedded.5.0.0\lib\net471\EventStore.Native.dll</HintPath>
</Reference>
<Reference Include="EventStore.Projections.Core, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EventStore.Client.Embedded.5.0.0\lib\net471\EventStore.Projections.Core.dll</HintPath>
</Reference>
<Reference Include="EventStore.Rags, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EventStore.Client.Embedded.5.0.0\lib\net471\EventStore.Rags.dll</HintPath>
</Reference>
<Reference Include="EventStore.Transport.Http, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EventStore.Client.Embedded.5.0.0\lib\net471\EventStore.Transport.Http.dll</HintPath>
</Reference>
<Reference Include="EventStore.Transport.Tcp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EventStore.Client.Embedded.5.0.0\lib\net471\EventStore.Transport.Tcp.dll</HintPath>
</Reference>
<Reference Include="HdrHistogram, Version=2.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\HdrHistogram.2.5.0\lib\net45\HdrHistogram.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.CodeCoverage.Shim, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.CodeCoverage.15.8.0-preview-20180610-02\lib\net45\Microsoft.VisualStudio.CodeCoverage.Shim.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.5.10\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=3.10.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.10.1\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="protobuf-net, Version=2.4.0.0, Culture=neutral, PublicKeyToken=257b51d87d2e4d67, processorArchitecture=MSIL">
<HintPath>..\packages\protobuf-net.2.4.0\lib\net40\protobuf-net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Transactions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="YamlDotNet, Version=5.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\YamlDotNet.5.2.1\lib\net45\YamlDotNet.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AggregateRepositoryTestFixture.cs" />
<Compile Include="EmbeddedEventStore.cs" />
<Compile Include="EventStoreAggregateRepositoryTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestAggregate.cs" />
<Compile Include="TestAggregateCreated.cs" />
<Compile Include="TestEvent.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AggregateRepository.EventStore\AggregateRepository.EventStore.csproj">
<Project>{f3dad4ac-69f2-439f-b66c-96c717695fd0}</Project>
<Name>AggregateRepository.EventStore</Name>
</ProjectReference>
<PackageReference Include="CorshamScience.AggregateRepository.Core" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="TeamCity.VSTest.TestAdapter" Version="1.0.36" />
<PackageReference Include="Testcontainers" Version="2.1.0" />
</ItemGroup>

<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
<ProjectReference Include="..\AggregateRepository.EventStore\AggregateRepository.EventStore.csproj" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit.3.10.1\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.10.1\build\NUnit.props'))" />
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.10.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.10.0\build\net35\NUnit3TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeCoverage.15.8.0-preview-20180610-02\build\netstandard1.0\Microsoft.CodeCoverage.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeCoverage.15.8.0-preview-20180610-02\build\netstandard1.0\Microsoft.CodeCoverage.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.NET.Test.Sdk.15.7.2\build\net45\Microsoft.Net.Test.Sdk.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NET.Test.Sdk.15.7.2\build\net45\Microsoft.Net.Test.Sdk.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.NET.Test.Sdk.15.7.2\build\net45\Microsoft.Net.Test.Sdk.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NET.Test.Sdk.15.7.2\build\net45\Microsoft.Net.Test.Sdk.targets'))" />
<Error Condition="!Exists('..\packages\EventStore.Client.Embedded.5.0.0\build\EventStore.Client.Embedded.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EventStore.Client.Embedded.5.0.0\build\EventStore.Client.Embedded.targets'))" />
</Target>
<Import Project="..\packages\Microsoft.NET.Test.Sdk.15.7.2\build\net45\Microsoft.Net.Test.Sdk.targets" Condition="Exists('..\packages\Microsoft.NET.Test.Sdk.15.7.2\build\net45\Microsoft.Net.Test.Sdk.targets')" />
<Import Project="..\packages\EventStore.Client.Embedded.5.0.0\build\EventStore.Client.Embedded.targets" Condition="Exists('..\packages\EventStore.Client.Embedded.5.0.0\build\EventStore.Client.Embedded.targets')" />
</Project>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,29 @@

namespace CorshamScience.AggregateRepository.EventStore.Tests
{
using System;
using System.Collections.Generic;
using CorshamScience.AggregateRepository.Core;
using CorshamScience.AggregateRepository.Core.Exceptions;
using NUnit.Framework;

[TestFixture]
public abstract class AggregateRepositoryTestFixture
internal abstract class AggregateRepositoryTestFixture
{
private List<Guid> _storedEvents = new List<Guid>();
private TestAggregate _retrievedAggregate;
private string _aggregateIdUnderTest;
private List<Guid> _storedEvents = new();
private TestAggregate _retrievedAggregate = null!;
private string _aggregateIdUnderTest = null!;

protected IAggregateRepository RepoUnderTest { get; set; }
protected IAggregateRepository RepoUnderTest { get; set; } = null!;

[OneTimeSetUp]
public async Task OneTimeSetUp() => await InitRepositoryAsync();

[SetUp]
public void SetUp()
{
InitRepository();
_aggregateIdUnderTest = Guid.NewGuid().ToString();
_storedEvents = new List<Guid>();
}

[TearDown]
public void TearDown() => CleanUpRepository();
[OneTimeTearDown]
public async Task OneTimeTearDown() => await CleanUpRepositoryAsync();

[Test]
public void Retreiving_an_aggregate_from_an_empty_eventstore_should_throw_an_exception() => Assert.Throws<AggregateNotFoundException>(() => RepoUnderTest.GetAggregateFromRepository<TestAggregate>(_aggregateIdUnderTest));
Expand All @@ -55,8 +53,12 @@ public void Retrieving_a_newly_created_aggregate_reconstructs_the_entity_correct
RepoUnderTest.Save(aggregate);

_retrievedAggregate = RepoUnderTest.GetAggregateFromRepository<TestAggregate>(_aggregateIdUnderTest);
Assert.AreEqual(_aggregateIdUnderTest, _retrievedAggregate.Id);
Assert.AreEqual(0, _retrievedAggregate.EventsApplied.Count);

Assert.Multiple(() =>
{
Assert.That(_retrievedAggregate.Id, Is.EqualTo(_aggregateIdUnderTest));
Assert.That(_retrievedAggregate.EventsApplied.Count, Is.EqualTo(0));
});
}

[Test]
Expand All @@ -73,11 +75,15 @@ public void Retrieving_an_aggregate_with_events_reconstructs_the_entity_correctl
RepoUnderTest.Save(aggregate);
_retrievedAggregate = RepoUnderTest.GetAggregateFromRepository<TestAggregate>(_aggregateIdUnderTest);

Assert.AreEqual(_aggregateIdUnderTest, _retrievedAggregate.Id);
Assert.AreEqual(_storedEvents.Count, _retrievedAggregate.EventsApplied.Count);
Assert.Multiple(() =>
{
Assert.That(_retrievedAggregate.Id, Is.EqualTo(_aggregateIdUnderTest));
Assert.That(_retrievedAggregate.EventsApplied.Count, Is.EqualTo(_storedEvents.Count));
});

foreach (var id in _storedEvents)
{
Assert.Contains(id, _retrievedAggregate.EventsApplied);
Assert.That(_retrievedAggregate.EventsApplied, Does.Contain(id));
}
}

Expand All @@ -95,12 +101,32 @@ public void Retrieving_an_aggregate_with_events_when_specifying_a_version_recons
RepoUnderTest.Save(aggregate);
_retrievedAggregate = RepoUnderTest.GetAggregateFromRepository<TestAggregate>(_aggregateIdUnderTest, 6);

Assert.AreEqual(_aggregateIdUnderTest, _retrievedAggregate.Id);
Assert.AreEqual(_storedEvents.Count, _retrievedAggregate.EventsApplied.Count);
Assert.Multiple(() =>
{
Assert.That(_retrievedAggregate.Id, Is.EqualTo(_aggregateIdUnderTest));
Assert.That(_retrievedAggregate.EventsApplied.Count, Is.EqualTo(_storedEvents.Count));
});

foreach (var id in _storedEvents)
{
Assert.Contains(id, _retrievedAggregate.EventsApplied);
Assert.That(_retrievedAggregate.EventsApplied, Does.Contain(id));
}
}

[Test]
public void Retrieving_an_aggregate_with_events_when_specifying_an_incorrect_version_throws_aggregate_not_found_exception()
{
var aggregate = new TestAggregate(_aggregateIdUnderTest);
for (var i = 0; i < 5; i++)
{
var eventId = Guid.NewGuid();
_storedEvents.Add(eventId);
aggregate.GenerateEvent(eventId);
}

RepoUnderTest.Save(aggregate);

Assert.Throws<AggregateVersionException>(() => RepoUnderTest.GetAggregateFromRepository<TestAggregate>(_aggregateIdUnderTest, 10));
}

[Test]
Expand All @@ -125,11 +151,15 @@ public void Retrieving_an_aggregate_with_events_reconstructs_the_entity_correctl
RepoUnderTest.Save(secondAggregate);
_retrievedAggregate = RepoUnderTest.GetAggregateFromRepository<TestAggregate>(_aggregateIdUnderTest);

Assert.AreEqual(_aggregateIdUnderTest, _retrievedAggregate.Id);
Assert.AreEqual(_storedEvents.Count, _retrievedAggregate.EventsApplied.Count);
Assert.Multiple(() =>
{
Assert.That(_retrievedAggregate.Id, Is.EqualTo(_aggregateIdUnderTest));
Assert.That(_retrievedAggregate.EventsApplied.Count, Is.EqualTo(_storedEvents.Count));
});

foreach (var id in _storedEvents)
{
Assert.Contains(id, _retrievedAggregate.EventsApplied);
Assert.That(_retrievedAggregate.EventsApplied, Does.Contain(id));
}
}

Expand All @@ -145,11 +175,16 @@ public void Saving_new_events_to_an_existing_aggregate_should_correctly_persist_
_retrievedAggregate.GenerateEvent(eventId);

RepoUnderTest.Save(_retrievedAggregate);

var actualAggregate = RepoUnderTest.GetAggregateFromRepository<TestAggregate>(_aggregateIdUnderTest);

Assert.AreEqual(1, actualAggregate.EventsApplied.Count);
Assert.AreEqual(_aggregateIdUnderTest, actualAggregate.Id);
Assert.AreEqual(eventId, actualAggregate.EventsApplied[0]);
Assert.Multiple(() =>
{
Assert.That(actualAggregate.EventsApplied.Count, Is.EqualTo(1));
Assert.That(actualAggregate.Id, Is.EqualTo(_aggregateIdUnderTest));
Assert.That(actualAggregate.EventsApplied[0], Is.EqualTo(eventId));
Assert.That(actualAggregate.Version, Is.EqualTo(2));
});
}

[Test]
Expand Down Expand Up @@ -192,8 +227,8 @@ public void Retrieving_an_aggregate_with_expected_version_greater_than_the_actua
Assert.Throws<AggregateVersionException>(() => RepoUnderTest.GetAggregateFromRepository<TestAggregate>(_aggregateIdUnderTest, 10));
}

protected abstract void InitRepository();
protected abstract Task InitRepositoryAsync();

protected abstract void CleanUpRepository();
protected abstract Task CleanUpRepositoryAsync();
}
}
Loading

0 comments on commit bbcaa07

Please sign in to comment.