コード例 #1
0
        /// <inheritdoc />
        protected override async Task SaveAsync(VersionableEvent versionableEvent, IDictionary <string, object> headers)
        {
            var eventDescriptor = new SqlEventDescriptor(this.AggregateType, this.AggregateId, versionableEvent, headers);

            using (var connection = await this.factory.CreateAsync(this.connectionStringName).ConfigureAwait(false))
                using (var command = new SqlCommand(SqlCommands.InsertEvent, connection))
                {
                    command.AddParameter("@AggregateType", eventDescriptor.AggregateType);
                    command.AddParameter("@AggregateId", eventDescriptor.AggregateId);
                    command.AddParameter("@Version", eventDescriptor.Version);
                    command.AddParameter("@Timestamp", eventDescriptor.Timestamp);
                    command.AddParameter("@EventType", eventDescriptor.EventType);
                    command.AddParameter("@EventData", eventDescriptor.SerializedEvent);
                    command.AddParameter("@Headers", eventDescriptor.SerializedHeaders);

                    await command.ExecuteNonQueryAsync().ConfigureAwait(false);
                }
        }
コード例 #2
0
        public void CanCreateInstanceWithParameters()
        {
            var aggregateType    = typeof(MyDynamicEventSourcedAggregateRoot).FullName;
            var aggregateId      = Guid.NewGuid();
            var versionableEvent = new VersionableEvent(new ValueEvent(11)).With(1);
            var headers          = new Dictionary <string, object> {
                { "UserName", "Patrick" }, { "MagicNumber", 42 }
            };

            var testee = new SqlEventDescriptor(aggregateType, aggregateId, versionableEvent, headers);

            testee.AggregateType.Should().Be(aggregateType);
            testee.AggregateId.Should().Be(aggregateId);
            testee.Version.Should().Be(1);
            testee.Timestamp.Should().BeCloseTo(DateTime.Now, 1000);
            testee.EventType.Should().Be("SimpleDomain.TestDoubles.ValueEvent");
            testee.Event.Should().BeSameAs(versionableEvent.InnerEvent);
            testee.SerializedEvent.Should().Be("{\"Value\":11}");
            testee.Headers.Should().Contain("UserName", "Patrick").And.Contain("MagicNumber", 42);
            testee.SerializedHeaders.Should().Be("{\"UserName\":\"Patrick\",\"MagicNumber\":42}");
        }
コード例 #3
0
        public void CanCreateParameterlessInstance()
        {
            var testee = new SqlEventDescriptor();

            testee.Should().NotBeNull();
        }