-
-
Notifications
You must be signed in to change notification settings - Fork 525
/
Copy pathOneToOneEventTransformations.cs
128 lines (128 loc) · 4.84 KB
/
OneToOneEventTransformations.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// using System;
// using System.Linq;
// using Marten.Events;
// using Marten.Events.Projections;
// using Marten.Integration.Tests.TestsInfrasructure;
// using SharpTestsEx;
// using Xunit;
//
// namespace Marten.Integration.Tests.EventStore.Transformations
// {
// public class OneToOneEventTransformations: MartenTest
// {
// public interface IIssueEvent
// {
// Guid IssueId { get; set; }
// }
//
// public class IssueCreated: IIssueEvent
// {
// public Guid IssueId { get; set; }
// public string Description { get; set; }
// }
//
// public class IssueUpdated: IIssueEvent
// {
// public Guid IssueId { get; set; }
// public string Description { get; set; }
// }
//
// public enum ChangeType
// {
// Creation,
// Modification
// }
//
// public class IssueChangesLog
// {
// public Guid Id { get; set; }
// public Guid IssueId { get; set; }
// public ChangeType ChangeType { get; set; }
// public DateTime Timestamp { get; set; }
// }
//
// public class IssuesList { }
//
// public class IssueChangeLogTransform: ITransform<IssueCreated, IssueChangesLog>,
// ITransform<IssueUpdated, IssueChangesLog>
// {
// public IssueChangesLog Transform(EventStream stream, Event<IssueCreated> input)
// {
// return new IssueChangesLog
// {
// IssueId = input.Data.IssueId,
// Timestamp = input.Timestamp.DateTime,
// ChangeType = ChangeType.Creation
// };
// }
//
// public IssueChangesLog Transform(EventStream stream, Event<IssueUpdated> input)
// {
// return new IssueChangesLog
// {
// IssueId = input.Data.IssueId,
// Timestamp = input.Timestamp.DateTime,
// ChangeType = ChangeType.Modification
// };
// }
// }
//
// protected override IDocumentSession CreateSession(Action<StoreOptions> setStoreOptions)
// {
// var store = DocumentStore.For(options =>
// {
// options.Connection(Settings.ConnectionString);
// options.AutoCreateSchemaObjects = AutoCreate.All;
// options.DatabaseSchemaName = SchemaName;
// options.Events.DatabaseSchemaName = SchemaName;
//
// //It's needed to manualy set that transformations should be applied
// options.Events.InlineProjections.TransformEvents<IssueCreated, IssueChangesLog>(new IssueChangeLogTransform());
// options.Events.InlineProjections.TransformEvents<IssueUpdated, IssueChangesLog>(new IssueChangeLogTransform());
// });
//
// return store.OpenSession();
// }
//
// [Fact]
// public void GivenEvents_WhenInlineTransformationIsApplied_ThenReturnsSameNumberOfTransformedItems()
// {
// var issue1Id = Guid.NewGuid();
// var issue2Id = Guid.NewGuid();
//
// var events = new IIssueEvent[]
// {
// new IssueCreated {IssueId = issue1Id, Description = "Description 1"},
// new IssueUpdated {IssueId = issue1Id, Description = "Description 1 New"},
// new IssueCreated {IssueId = issue2Id, Description = "Description 2"},
// new IssueUpdated {IssueId = issue1Id, Description = "Description 1 Super New"},
// new IssueUpdated {IssueId = issue2Id, Description = "Description 2 New"},
// };
//
// //1. Create events
// EventStore.StartStream<IssuesList>(events);
//
// await Session.SaveChangesAsync();
//
// //2. Get transformed events
// var changeLogs = Session.Query<IssueChangesLog>().ToList();
//
// changeLogs.Should().HaveCount(events.Length);
//
// changeLogs.Select(ev => ev.IssueId)
// .Should().Have.SameValuesAs(events.Select(ev => ev.IssueId));
//
// changeLogs.Count(ev => ev.ChangeType == ChangeType.Creation)
// .Should().Be(events.OfType<IssueCreated>().Count());
//
// changeLogs.Count(ev => ev.ChangeType == ChangeType.Modification)
// .Should().Be(events.OfType<IssueUpdated>().Count());
//
// changeLogs.Count(ev => ev.IssueId == issue1Id)
// .Should().Be(events.Count(ev => ev.IssueId == issue1Id));
//
// changeLogs.Count(ev => ev.IssueId == issue2Id)
// .Should().Be(events.Count(ev => ev.IssueId == issue2Id));
// }
// }
// }