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

Added aloneguid/Storage backed blob event and snapshot store #93

Open
wants to merge 1 commit 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
33 changes: 25 additions & 8 deletions CQRSlite.sln
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.4
# Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Framework", "Framework", "{693A83BF-7B14-459E-B245-82B7B9AF810E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sample", "Sample", "{DC63AD03-D195-4E43-8120-0BD27AC86D46}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CQRSlite", "Framework\CQRSlite\CQRSlite.csproj", "{71DFCD1D-AC1E-4CAE-9998-C747662DBF0E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CQRSlite", "Framework\CQRSlite\CQRSlite.csproj", "{71DFCD1D-AC1E-4CAE-9998-C747662DBF0E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CQRSlite.Tests", "Framework\CQRSlite.Tests\CQRSlite.Tests.csproj", "{2694E1AD-335F-467B-9C0C-4979871830D3}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CQRSlite.Tests", "Framework\CQRSlite.Tests\CQRSlite.Tests.csproj", "{2694E1AD-335F-467B-9C0C-4979871830D3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CQRSlite.Tests.Extensions", "Framework\CQRSlite.Tests.Extensions\CQRSlite.Tests.Extensions.csproj", "{0A3F1993-C603-4CD9-BCB3-5791255B54AA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CQRSlite.Tests.Extensions", "Framework\CQRSlite.Tests.Extensions\CQRSlite.Tests.Extensions.csproj", "{0A3F1993-C603-4CD9-BCB3-5791255B54AA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CQRSCode", "Sample\CQRSCode\CQRSCode.csproj", "{94A8AD91-1300-471D-AAC0-F6F310A54927}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CQRSCode", "Sample\CQRSCode\CQRSCode.csproj", "{94A8AD91-1300-471D-AAC0-F6F310A54927}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CQRSWeb", "Sample\CQRSWeb\CQRSWeb.csproj", "{C1214159-C75F-4CAC-82BD-A5E4E3F7F0E2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CQRSWeb", "Sample\CQRSWeb\CQRSWeb.csproj", "{C1214159-C75F-4CAC-82BD-A5E4E3F7F0E2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CQRSTest", "Sample\CQRSTest\CQRSTest.csproj", "{DE6E654C-00A3-4829-AABF-42F534078D00}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CQRSTest", "Sample\CQRSTest\CQRSTest.csproj", "{DE6E654C-00A3-4829-AABF-42F534078D00}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D88E36CC-4CB2-436D-881B-5B6BB4174B42}"
ProjectSection(SolutionItems) = preProject
CQRSlite.nuspec = CQRSlite.nuspec
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CQRSlite.Storage", "Framework\CQRSlite.Storage\CQRSlite.Storage.csproj", "{0B20F4C1-94BE-41C6-BAA6-DC128A5D8ED3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CQRSlite.Storage.Tests", "Framework\CQRSlite.Storage.Tests\CQRSlite.Storage.Tests.csproj", "{329529E4-0834-417F-B527-F02E1B36EAF2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -54,6 +58,14 @@ Global
{DE6E654C-00A3-4829-AABF-42F534078D00}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE6E654C-00A3-4829-AABF-42F534078D00}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE6E654C-00A3-4829-AABF-42F534078D00}.Release|Any CPU.Build.0 = Release|Any CPU
{0B20F4C1-94BE-41C6-BAA6-DC128A5D8ED3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B20F4C1-94BE-41C6-BAA6-DC128A5D8ED3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B20F4C1-94BE-41C6-BAA6-DC128A5D8ED3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B20F4C1-94BE-41C6-BAA6-DC128A5D8ED3}.Release|Any CPU.Build.0 = Release|Any CPU
{329529E4-0834-417F-B527-F02E1B36EAF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{329529E4-0834-417F-B527-F02E1B36EAF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{329529E4-0834-417F-B527-F02E1B36EAF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{329529E4-0834-417F-B527-F02E1B36EAF2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -65,5 +77,10 @@ Global
{94A8AD91-1300-471D-AAC0-F6F310A54927} = {DC63AD03-D195-4E43-8120-0BD27AC86D46}
{C1214159-C75F-4CAC-82BD-A5E4E3F7F0E2} = {DC63AD03-D195-4E43-8120-0BD27AC86D46}
{DE6E654C-00A3-4829-AABF-42F534078D00} = {DC63AD03-D195-4E43-8120-0BD27AC86D46}
{0B20F4C1-94BE-41C6-BAA6-DC128A5D8ED3} = {693A83BF-7B14-459E-B245-82B7B9AF810E}
{329529E4-0834-417F-B527-F02E1B36EAF2} = {693A83BF-7B14-459E-B245-82B7B9AF810E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9F74664F-E6ED-4414-8D79-A70086E2A37D}
EndGlobalSection
EndGlobal
24 changes: 24 additions & 0 deletions Framework/CQRSlite.Storage.Tests/CQRSlite.Storage.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

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

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
<PackageReference Include="coverlet.collector" Version="1.0.1" />
<PackageReference Include="Scrutor" Version="3.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CQRSlite.Storage\CQRSlite.Storage.csproj" />
<ProjectReference Include="..\CQRSlite\CQRSlite.csproj" />
</ItemGroup>

</Project>
43 changes: 43 additions & 0 deletions Framework/CQRSlite.Storage.Tests/Events/ForumCommandHandlers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using CQRSlite.Commands;
using CQRSlite.Domain;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace CQRSlite.Storage.Tests.Events {
public class ForumCommandHandlers : ICancellableCommandHandler<TestCreateForum>,
ICancellableCommandHandler<TestAddPostToForum> {

private ISession _session;
public ForumCommandHandlers(ISession session) {
_session = session;

}


public async Task Handle(TestCreateForum message, CancellationToken token = default) {
var forum = new TestForum(message.Id,
message.Name,
message.Description,
message.ForumGroupId,
message.CanView,
message.CanPost,
message.CanModerate
);

await _session.Add(forum);
await _session.Commit();
}

public async Task Handle(TestAddPostToForum post, CancellationToken token = default) {
var forum = await _session.Get<TestForum>(post.ForumId, post.ExpectedVersion, token);


forum.AddPost(post.Id, post.Poster, post.PosterRoles, post.Markup, post.Posted, post.Tags);

await _session.Commit(token);
}
}
}
13 changes: 13 additions & 0 deletions Framework/CQRSlite.Storage.Tests/Events/ForumEventHandlers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using CQRSlite.Events;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace CQRSlite.Storage.Tests.Events {
public class ForumEventHandlers : IEventHandler<TestForumCreated> {
public Task Handle(TestForumCreated message) {
return Task.CompletedTask;
}
}
}
35 changes: 35 additions & 0 deletions Framework/CQRSlite.Storage.Tests/Events/TestAddPostToForum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using CQRSlite.Commands;
using System;
using System.Collections.Generic;
using System.Text;

namespace CQRSlite.Storage.Tests.Events {
public class TestAddPostToForum : ICommand {
public TestAddPostToForum(Guid id,
Guid forumId,
string poster,
string[] PosterRoles,
string Markup,
DateTimeOffset posted,
string[] tags,
int originalVersion) {
Id = id;
ForumId = forumId;
Poster = poster;
this.PosterRoles = PosterRoles;
this.Markup = Markup;
Posted = posted;
Tags = tags;
ExpectedVersion = originalVersion;
}

public Guid Id { get; set; }
public Guid ForumId { get; set; }
public string Poster { get; set; }
public string[] PosterRoles { get; set; }
public string Markup { get; set; }
public DateTimeOffset Posted { get; set; }
public string[] Tags { get; set; }
public int ExpectedVersion { get; set; }
}
}
29 changes: 29 additions & 0 deletions Framework/CQRSlite.Storage.Tests/Events/TestCreateForum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using CQRSlite.Commands;
using System;
using System.Collections.Generic;
using System.Text;

namespace CQRSlite.Storage.Tests.Events {
public class TestCreateForum : ICommand {


public TestCreateForum(Guid id, string name, string description, Guid forumGroupId, string[] CanView, string[] CanPost, string[] CanModerate) {

this.Id = id;
this.Name = name;
this.Description = description;
ForumGroupId = forumGroupId;
this.CanView = CanView;
this.CanPost = CanPost;
this.CanModerate = CanModerate;
}

public string Name { get; set; }
public string Description { get; set; }
public Guid ForumGroupId { get; set; }
public string[] CanView { get; set; }
public string[] CanPost { get; set; }
public string[] CanModerate { get; set; }
public Guid Id { get; set; }
}
}
127 changes: 127 additions & 0 deletions Framework/CQRSlite.Storage.Tests/Events/TestForum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
using CQRSlite.Domain;
using CQRSlite.Storage.Tests.Events;
using System;
using System.Collections.Generic;
using System.Text;

namespace CQRSlite.Storage.Tests {
[SnapshotStrategy(1)]
public class TestForum : Snapshotting.SnapshotAggregateRoot<TestForumSnapshot> {
public string Name { get; private set; }
public string Description { get; private set; }
public Guid ForumGroupId { get; private set; }
public string[] CanView { get; private set; }
public string[] CanPost { get; private set; }
public string[] CanModerate { get; private set; }

private TestForum() { }
public TestForum(Guid id,
string name,
string description,
Guid forumGroupId,
string[] canView,
string[] canPost,
string[] canModerate) {

if (string.IsNullOrEmpty(name)) {
throw new ArgumentException("message", nameof(name));
}

if (string.IsNullOrEmpty(description)) {
throw new ArgumentException("message", nameof(description));
}

if (canView is null) {
throw new ArgumentNullException(nameof(canView));
}

if (canPost is null) {
throw new ArgumentNullException(nameof(canPost));
}

if (canModerate is null) {
throw new ArgumentNullException(nameof(canModerate));
}

Id = id;

ApplyChange(new TestForumCreated(Id, name, description, forumGroupId, canView, canPost, canModerate));
}

private void Apply(TestForumCreated e) {
this.Name = e.Name;
this.Description = e.Description;
this.ForumGroupId = e.ForumGroupId;
this.CanView = e.CanView;
this.CanPost = e.CanPost;
this.CanModerate = e.CanModerate;
}


public void AddPost(Guid id,
string poster,
string[] PosterRoles,
string Markup,
DateTimeOffset posted,
string[] tags) {

// TODO: CanPost test

TestPostAdded post = new TestPostAdded(this.Id,
this.Id,
poster,
PosterRoles,
Markup,
posted,
tags);

ApplyChange(post);

}
public IList<TestPost> Posts { get; set; }
private void Apply(TestPostAdded e) {
if(this.Posts == null) {
this.Posts = new List<TestPost>();
}
Posts.Add(new TestPost() {
ForumId = this.Id,
Id = e.Id,
Markup = e.Markup,
Posted = e.Posted,
Poster = e.Poster,
PosterRoles = e.PosterRoles,
Tags = e.Tags,
Number = (this.Posts.Count + 1)
}) ;

}

protected override TestForumSnapshot CreateSnapshot() {
return new TestForumSnapshot() {
CanModerate = this.CanModerate,
CanPost = this.CanPost,
CanView = this.CanView,
Description = this.Description,
ForumGroupId = this.ForumGroupId,
Id = this.Id,
Name = this.Name,
Posts = this.Posts,
Version = this.Version


};
}

protected override void RestoreFromSnapshot(TestForumSnapshot snapshot) {
this.CanModerate = snapshot.CanModerate;
this.CanPost = snapshot.CanPost;
this.CanView = snapshot.CanView;
this.Description = snapshot.Description;
this.ForumGroupId = snapshot.ForumGroupId;
this.Id = snapshot.Id;
this.Name = snapshot.Name;
this.Posts = snapshot.Posts;
this.Version = snapshot.Version;
}
}
}
30 changes: 30 additions & 0 deletions Framework/CQRSlite.Storage.Tests/Events/TestForumCreated.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using CQRSlite.Events;
using System;
using System.Collections.Generic;
using System.Text;

namespace CQRSlite.Storage.Tests {
public class TestForumCreated : IEvent {

public TestForumCreated(Guid id, string name, string description, Guid forumGroupId, string[] CanView, string[] CanPost, string[] CanModerate) {

this.Id = id;
this.Name = name;
this.Description = description;
ForumGroupId = forumGroupId;
this.CanView = CanView;
this.CanPost = CanPost;
this.CanModerate = CanModerate;
}

public string Name { get; set; }
public string Description { get; set; }
public Guid ForumGroupId { get; set; }
public string[] CanView { get; set; }
public string[] CanPost { get; set; }
public string[] CanModerate { get; set; }
public Guid Id { get; set; }
public int Version { get; set; }
public DateTimeOffset TimeStamp { get; set ; }
}
}
15 changes: 15 additions & 0 deletions Framework/CQRSlite.Storage.Tests/Events/TestForumSnapshot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace CQRSlite.Storage.Tests.Events {
public class TestForumSnapshot : Snapshotting.Snapshot {
public string Name { get; set; }
public string Description { get; set; }
public Guid ForumGroupId { get; set; }
public string[] CanView { get; set; }
public string[] CanPost { get; set; }
public string[] CanModerate { get; set; }
public IList<TestPost> Posts { get; set; }
}
}
Loading