예제 #1
0
        public void GetRowKey_returns_prefixed_formatted_version()
        {
            int    version = new Fixture().Create <int>();
            string actual  = PendingEvent.GetRowKey(version);

            actual.Should().Be($"Pending-{version:D10}");
        }
        public async Task SaveEvents_does_not_insert_persistent_event_entities_if_fails_to_insert_pending_event_entities()
        {
            // Arrange
            var fixture = new Fixture();
            var user    = new FakeUser(Guid.NewGuid(), fixture.Create <string>());

            user.ChangeUsername(fixture.Create <string>());
            IList <IDomainEvent> domainEvents = user.FlushPendingEvents().ToList();

            IDomainEvent conflicting = domainEvents[new Random().Next(domainEvents.Count)];
            var          batch       = new TableBatchOperation();

            batch.Insert(new TableEntity
            {
                PartitionKey = AggregateEntity.GetPartitionKey(typeof(FakeUser), user.Id),
                RowKey       = PendingEvent.GetRowKey(conflicting.Version),
            });
            await s_eventTable.ExecuteBatchAsync(batch);

            // Act
            Func <Task> action = () => _sut.SaveEvents <FakeUser>(domainEvents);

            // Assert
            action.ShouldThrow <StorageException>();
            string filter = PersistentEvent.GetFilter(typeof(FakeUser), user.Id);
            var    query  = new TableQuery <PersistentEvent> {
                FilterString = filter
            };
            IEnumerable <PersistentEvent> actual = await s_eventTable.ExecuteQuerySegmentedAsync(query, default);

            actual.Should().BeEmpty();
        }
예제 #3
0
        public void Create_sets_RowKey_correctly()
        {
            IFixture        fixture     = new Fixture();
            SomeDomainEvent domainEvent = fixture.Create <SomeDomainEvent>();

            TestContext.WriteLine($"Version: {domainEvent.Version}");
            fixture.Inject <IDomainEvent>(domainEvent);

            var actual = PendingEvent.Create(
                fixture.Create <Type>(),
                fixture.Create <Envelope <IDomainEvent> >(),
                new JsonMessageSerializer());

            actual.RowKey.Should().Be(PendingEvent.GetRowKey(domainEvent.Version));
        }