Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SqlStreamStore implementation #25

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/Core/AggregateSource/AggregateSource.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -22,7 +22,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\net45\AggregateSource.xml</DocumentationFile>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Core/AggregateSource/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/Recipes/EventStoreShopping/EventStoreShopping/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup>
</configuration>
</configuration>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -9,8 +9,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EventStoreShopping</RootNamespace>
<AssemblyName>EventStoreShopping</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down
4 changes: 2 additions & 2 deletions src/SampleSource/SampleSource.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -23,7 +23,7 @@
<DefineConstants>DEBUG;TRACE;NET45</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
4 changes: 4 additions & 0 deletions src/SqlStreamStore/.nuget/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit.Runners" version="2.6.3" />
</packages>
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7E6BACB9-7804-429A-A71E-78B12D0AB786}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AggregateSource.SqlStreamStore</RootNamespace>
<AssemblyName>AggregateSource.SqlStreamStore.Tests</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\net45</OutputPath>
<DefineConstants>DEBUG;TRACE;NET45</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\net45</OutputPath>
<DefineConstants>TRACE;NET45</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.5.0\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SqlStreamStore, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SqlStreamStore.1.0.2\lib\net461\SqlStreamStore.dll</HintPath>
</Reference>
<Reference Include="SqlStreamStore.MsSql, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\SqlStreamStore.MsSql.1.0.2\lib\net461\SqlStreamStore.MsSql.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\Core\AggregateSource.Content.ExplicitRouting\AggregateRootEntity.cs">
<Link>Framework\AggregateRootEntity.cs</Link>
</Compile>
<Compile Include="..\..\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="..\..\SharedVersionInfo.cs">
<Link>Properties\SharedVersionInfo.cs</Link>
</Compile>
<Compile Include="Framework\AggregateRootEntityStub.cs" />
<Compile Include="Framework\EventStub.cs" />
<Compile Include="Framework\RepositoryScenarioBuilder.cs" />
<Compile Include="Model.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RepositoryTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\AggregateSource\AggregateSource.csproj">
<Project>{cc3fcc99-9e18-45de-9b39-76031d45624d}</Project>
<Name>AggregateSource</Name>
</ProjectReference>
<ProjectReference Include="..\AggregateSource.SqlStreamStore\AggregateSource.SqlStreamStore.csproj">
<Project>{06aa30d7-8cd5-4ec4-99f2-50129dee0d57}</Project>
<Name>AggregateSource.SqlStreamStore</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using AggregateSource;

namespace SSS.Framework
{
public class AggregateRootEntityStub : AggregateRootEntity
{
public static readonly Func<AggregateRootEntityStub> Factory = () => new AggregateRootEntityStub();

readonly List<object> _recordedEvents;

public AggregateRootEntityStub()
{
_recordedEvents = new List<object>();

Register<EventStub>(_ => _recordedEvents.Add(_));
}

public IList<object> RecordedEvents
{
get { return new ReadOnlyCollection<object>(_recordedEvents); }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace SSS.Framework
{
public class EventStub
{
public int Value { get; set; }

public EventStub() {}

public EventStub(int value)
{
Value = value;
}

public override bool Equals(object obj)
{
return Equals(obj as EventStub);
}

bool Equals(EventStub @event)
{
return !ReferenceEquals(@event, null) && Value.Equals(@event.Value);
}

public override int GetHashCode()
{
unchecked
{
return Value.GetHashCode()*10 + 2;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using AggregateSource;
using SqlStreamStore;
using SqlStreamStore.Streams;
using StreamStoreStore.Json;

namespace SSS.Framework
{
public class RepositoryScenarioBuilder
{
readonly IStreamStore _eventStore;
readonly List<Action<IStreamStore>> _eventStoreSchedule;
readonly List<Action<UnitOfWork>> _unitOfWorkSchedule;
UnitOfWork _unitOfWork;

public RepositoryScenarioBuilder()
{
_eventStore = new InMemoryStreamStore(() => DateTime.UtcNow);
_unitOfWork = new UnitOfWork();
_eventStoreSchedule = new List<Action<IStreamStore>>();
_unitOfWorkSchedule = new List<Action<UnitOfWork>>();
}

public RepositoryScenarioBuilder WithUnitOfWork(UnitOfWork value)
{
_unitOfWork = value;
return this;
}

public RepositoryScenarioBuilder ScheduleAppendToStream(string stream, params object[] events)
{
if (stream == null) throw new ArgumentNullException("stream");
if (events == null) throw new ArgumentNullException("events");
_eventStoreSchedule.Add(
store =>
{
var messages = events
.Select(o =>
new NewStreamMessage(
messageId: Guid.NewGuid(),
type: o.GetType().AssemblyQualifiedName, // Uses AssemblyQualifiedName for simplicity, use a map instead.
jsonData: SimpleJson.SerializeObject(o)))
.ToList();

store.AppendToStream(new StreamId(stream), ExpectedVersion.Any, messages.ToArray(), CancellationToken.None).GetAwaiter().GetResult();
});
return this;
}

public RepositoryScenarioBuilder ScheduleDeleteStream(string stream)
{
if (stream == null) throw new ArgumentNullException("stream");
_eventStoreSchedule.Add(store => store.DeleteStream(stream).GetAwaiter().GetResult());
return this;
}

public RepositoryScenarioBuilder ScheduleAttachToUnitOfWork(Aggregate aggregate)
{
if (aggregate == null) throw new ArgumentNullException("aggregate");
_unitOfWorkSchedule.Add(uow => uow.Attach(aggregate));
return this;
}

public Repository<AggregateRootEntityStub> BuildForRepository()
{
ExecuteScheduledActions();
return new Repository<AggregateRootEntityStub>(
AggregateRootEntityStub.Factory,
_unitOfWork,
_eventStore);
}

void ExecuteScheduledActions()
{
foreach (var action in _eventStoreSchedule)
{
action(_eventStore);
}
foreach (var action in _unitOfWorkSchedule)
{
action(_unitOfWork);
}
}
}
}
16 changes: 16 additions & 0 deletions src/SqlStreamStore/AggregateSource.SqlStreamStore.Tests/Model.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace SSS
{
public class Model
{
public Model()
{
KnownIdentifier = "aggregate/" + Guid.NewGuid();
UnknownIdentifier = "aggregate/" + Guid.NewGuid();
}

public string KnownIdentifier { get; private set; }
public string UnknownIdentifier { get; private set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using System.Reflection;

[assembly: AssemblyTitle("AggregateSource.SqlStreamStore.Tests")]
[assembly: AssemblyDescription("AggregateSource integration with SqlStreamStore. Unit tests.")]
Loading