Skip to content

Instantly share code, notes, and snippets.

View yreynhout's full-sized avatar
👔
ceci n'est pas une cravate

Yves Reynhout yreynhout

👔
ceci n'est pas une cravate
View GitHub Profile
@yreynhout
yreynhout / ProjectorSyntax.cs
Created March 8, 2014 19:58
Playground for flavors of declarative projections in C# ... seeking the DSL so to speak
// TState is an individual, immutable state entry in the projection state
// Flavor 1:
Projection<TState>.
When<TEvent>.ThenAdd<TKey, TEvent>(Func<TEvent, TKey> selector, Func<TEvent, TState> handler).
When<TEvent>.ThenUpdate<TKey, TEvent>(Func<TEvent, TKey> selector, Func<TState, TEvent, TState> handler).
When<TEvent>.ThenAddOrUpdate<TKey, TEvent>(Func<TEvent, TKey> selector, Func<TEvent, TState> addHandler, Func<TState, TEvent, TState> updateHandler)
When<TEvent>.ThenRemove<TKey, TEvent>(Func<TEvent, TKey> selector)
// TState is an individual, immutable state entry in the projection state
// Flavor 2: Add & Update melted into Set leaving the host to deal with Add or Update semantics
Task flushingTask = null;
public override Task FlushAsync(CancellationToken cancellationToken)
{
Interlocked.CompareExchange(
ref flushingTask,
Task.Delay(200, cancellationToken).ContinueWith(
async (t) =>
{
await write.FlushAsync(cancellationToken);
  1. General Background and Overview
@yreynhout
yreynhout / ProjacProjection.cs
Last active August 29, 2015 13:59
Declarative Projac Projection - Teaser
public static class DeclarativeTSqlProjection
{
public static void Sample()
{
var specification =
TSql.Projection().
When<StartedShopping>(@event =>
TSql.NonQuery(
"INSERT INTO [Cart] ([CartId], [Started], [Ended]) VALUES (@CartId, @Started, NULL)",
new
//FromAsync variant that can be used with APM across M<arshaling boundaries (you make your own TArgX overloads, please)
static class MarshalTask
{
public static Task<TResult> FromAsync<TArg1, TArg2, TResult>(Func<TArg1, TArg2, AsyncCallback, object, IAsyncResult> beginFunc, Func<IAsyncResult, TResult> endFunc, TArg1 arg1, TArg2 arg2)
{
var cp = new Completer<TResult>(endFunc);
var tcs = new TaskCompletionSource<TResult>();
cp.TaskCompletionSource = tcs;
using NUnit;
[TestFixture]
public class ShowCase
{
[Test]
public void EnrichesChangedOpeningHoursInTheExpectedWay()
{
new EventEnricherAssertion<BeautyFarmEventEnricher, ChangedOpeningHours>().
SetBeautyFarmName(123, "Spa Deluxe").
@yreynhout
yreynhout / ProjacTesting.cs
Last active August 29, 2015 14:00
Spiking Projac.Testing
[TestFixture]
public class SomeProjectionTests
{
[Test]
public void HandlesSomeEventAsExpected()
{
new TSqlProjectionScenario(TSqlProjection projection). //after renaming TSqlProjectionSpecification to TSqlProjection ;-)
Given(params object[] events).
Given(IEnumerable<object> events).
GivenNone().
using Projac;
using Projac.Testing;
using Projac.Testing.NUnit;
using NUnit.Framework;
[TestFixture]
public class PortfolioProjectionTests
{
[Test]
public void PhotoCountIsDecrementedWhenPhotoIsRemoved()
[Test]
public void EqualityMembersOverridden()
{
new EqualityMembersOverriddenAssertion(Func<object> sutFactory).
EqualsCase(object other).
EqualsCase(object other).
NotEqualsCase(object other).
NotEqualsCase(object other).
NotEqualsCase(object other).
Verify();
[TestFixture]
public class AuthorizationSpecifications
{
[Test]
public void WhoAreYouGonnaCall()
{
new AuthorizationScenario().
Given(events).
When(command).
InvokedBy(subject/identity).