Skip to content

Commit

Permalink
Add missing transaction ID to DB specific projection contexts (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldkroon authored and dennisdoomen committed Feb 22, 2017
1 parent 18c3080 commit 8a83265
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 10 deletions.
1 change: 1 addition & 0 deletions Src/LiquidProjections.NHibernate/NHibernateProjector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ private async Task ProjectTransaction(Transaction transaction, ISession session)
{
var context = new NHibernateProjectionContext
{
TransactionId = transaction.Id,
Session = session,
StreamId = transaction.StreamId,
TimeStampUtc = transaction.TimeStampUtc,
Expand Down
1 change: 1 addition & 0 deletions Src/LiquidProjections.RavenDB/RavenProjector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ private async Task ProjectTransaction(Transaction transaction, IAsyncDocumentSes
{
var context = new RavenProjectionContext
{
TransactionId = transaction.Id,
Session = session,
StreamId = transaction.StreamId,
TimeStampUtc = transaction.TimeStampUtc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,8 @@ public void Then_it_should_remove_the_projection()
public class When_an_event_requires_a_custom_action :
Given_a_sqlite_projector_with_an_in_memory_event_source
{
private NHibernateProjectionContext context;

public When_an_event_requires_a_custom_action()
{
Given(() =>
Expand All @@ -767,16 +769,41 @@ public When_an_event_requires_a_custom_action()
context.Session.Delete(entry);
}

this.context = context;

return Task.FromResult(false);
});

StartProjecting();
});

When(() => The<MemoryEventSource>().Write(new CategoryDiscontinuedEvent
{
Category = "Hybrids",
}));
When(() => The<MemoryEventSource>().Write(
new Transaction
{
Checkpoint = 111,
Id = "MyTransactionId",
StreamId = "MyStreamId",
TimeStampUtc = 10.April(1979).At(13, 14, 15),
Headers = new Dictionary<string, object>
{
["My custom header"] = "My custom header value"
},
Events = new List<EventEnvelope>
{
new EventEnvelope
{
Body = new CategoryDiscontinuedEvent
{
Category = "Hybrids"
},
Headers = new Dictionary<string, object>
{
["Some event header"] = "Some event header value"
}
}
}
})
);
}

[Fact]
Expand All @@ -788,6 +815,26 @@ public void Then_it_should_have_executed_the_custom_action()
entry.Should().BeNull();
}
}

[Fact]
public void Then_it_should_have_created_the_context()
{
context.ShouldBeEquivalentTo(new NHibernateProjectionContext
{
Checkpoint = 111,
TransactionId = "MyTransactionId",
StreamId = "MyStreamId",
TimeStampUtc = 10.April(1979).At(13, 14, 15),
TransactionHeaders = new Dictionary<string, object>
{
["My custom header"] = "My custom header value"
},
EventHeaders = new Dictionary<string, object>
{
["Some event header"] = "Some event header value"
}
}, options => options.Excluding(c => c.Session));
}
}

public class When_an_event_is_not_mapped_at_all :
Expand Down
55 changes: 51 additions & 4 deletions Tests/LiquidProjections.RavenDB.Specs/RavenProjectorSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,8 @@ public async Task Then_it_should_remove_the_projection()

public class When_an_event_requires_a_custom_action : Given_a_raven_projector_with_an_in_memory_event_source
{
private RavenProjectionContext context;

public When_an_event_requires_a_custom_action()
{
Given(async () =>
Expand All @@ -893,15 +895,40 @@ await session.StoreAsync(new ProductCatalogEntry
{
ctx.Session.Delete(entry);
}

context = ctx;
});

StartProjecting();
});

When(() => The<MemoryEventSource>().Write(new CategoryDiscontinuedEvent
{
Category = "Hybrids",
}));
When(() => The<MemoryEventSource>().Write(
new Transaction
{
Checkpoint = 111,
Id = "MyTransactionId",
StreamId = "MyStreamId",
TimeStampUtc = 10.April(1979).At(13, 14, 15),
Headers = new Dictionary<string, object>
{
["My custom header"] = "My custom header value"
},
Events = new List<EventEnvelope>
{
new EventEnvelope
{
Body = new CategoryDiscontinuedEvent
{
Category = "Hybrids",
},
Headers = new Dictionary<string, object>
{
["Some event header"] = "Some event header value"
}
}
}
})
);
}

[Fact]
Expand All @@ -913,6 +940,26 @@ public async Task Then_it_should_have_executed_the_custom_action()
entry.Should().BeNull();
}
}

[Fact]
public void Then_it_should_have_created_the_context()
{
context.ShouldBeEquivalentTo(new RavenProjectionContext
{
Checkpoint = 111,
TransactionId = "MyTransactionId",
StreamId = "MyStreamId",
TimeStampUtc = 10.April(1979).At(13, 14, 15),
TransactionHeaders = new Dictionary<string, object>
{
["My custom header"] = "My custom header value"
},
EventHeaders = new Dictionary<string, object>
{
["Some event header"] = "Some event header value"
}
}, options => options.Excluding(c => c.Session));
}
}

public class When_an_event_requires_an_update_of_a_non_existing_projection :
Expand Down
4 changes: 2 additions & 2 deletions Tests/LiquidProjections.Specs/ProjectorSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ await The<MemoryEventSource>().Write(new Transaction
{
Checkpoint = 111,
Id = "MyTransactionId",
StreamId = "MySTreamId",
StreamId = "MyStreamId",
TimeStampUtc = 10.April(1979).At(13, 14, 15),
Headers = new Dictionary<string, object>
{
Expand Down Expand Up @@ -95,7 +95,7 @@ public void Then_it_should_have_created_the_context()
{
Checkpoint = 111,
TransactionId = "MyTransactionId",
StreamId = "MySTreamId",
StreamId = "MyStreamId",
TimeStampUtc = 10.April(1979).At(13, 14, 15),
TransactionHeaders = new Dictionary<string, object>
{
Expand Down

0 comments on commit 8a83265

Please sign in to comment.