-
-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
You can use generic types for Events because why not. Closes GH-1069
- Loading branch information
1 parent
b40bc61
commit 72170cc
Showing
9 changed files
with
191 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/Marten.Testing/Bugs/Bug_1069_using_generic_event_types_because_why_not.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.Linq; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace Marten.Testing.Bugs | ||
{ | ||
public class Bug_1069_using_generic_event_types_because_why_not : IntegratedFixture | ||
{ | ||
public class Envelope<T> | ||
{ | ||
public T Value { get; set; } | ||
public Guid ExecutingUserId { get; set; } | ||
} | ||
|
||
public class Created | ||
{ | ||
public Guid Id { get; set; } | ||
} | ||
|
||
public class Updated | ||
{ | ||
public String UpdateValue { get; set; } | ||
} | ||
|
||
[Fact] | ||
public void try_to_save_then_load_events() | ||
{ | ||
var streamId = Guid.NewGuid(); | ||
var event1 = new Envelope<Created>{Value = new Created{Id = Guid.NewGuid()}}; | ||
var event2 = new Envelope<Updated>{Value = new Updated{UpdateValue = "something"}}; | ||
|
||
using (var session = theStore.LightweightSession()) | ||
{ | ||
session.Events.StartStream(streamId, event1, event2); | ||
session.SaveChanges(); | ||
} | ||
|
||
using (var session = theStore.LightweightSession()) | ||
{ | ||
|
||
|
||
var events = session.Events.FetchStream(streamId); | ||
events.Select(x => x.Data.GetType()) | ||
.ShouldHaveTheSameElementsAs(typeof(Envelope<Created>), typeof(Envelope<Updated>)); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void try_to_save_then_load_events_across_stores() | ||
{ | ||
var streamId = Guid.NewGuid(); | ||
var event1 = new Envelope<Created>{Value = new Created{Id = Guid.NewGuid()}}; | ||
var event2 = new Envelope<Updated>{Value = new Updated{UpdateValue = "something"}}; | ||
|
||
using (var session = theStore.LightweightSession()) | ||
{ | ||
session.Events.StartStream(streamId, event1, event2); | ||
session.SaveChanges(); | ||
} | ||
|
||
var store2 = DocumentStore.For(_ => | ||
{ | ||
_.Connection(ConnectionSource.ConnectionString); | ||
_.AutoCreateSchemaObjects = AutoCreate.All; | ||
}); | ||
|
||
using (var session = store2.LightweightSession()) | ||
{ | ||
var events = session.Events.FetchStream(streamId); | ||
events.Select(x => x.Data.GetType()) | ||
.ShouldHaveTheSameElementsAs(typeof(Envelope<Created>), typeof(Envelope<Updated>)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.