public void GetRowKey_returns_formatted_version() { int version = new Fixture().Create <int>(); string actual = PersistentEvent.GetRowKey(version); actual.Should().Be($"{version:D10}"); }
public async Task SaveEvents_does_not_insert_pending_event_entities_if_fails_to_insert_persistent_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 = PersistentEvent.GetRowKey(conflicting.Version), }); await s_eventTable.ExecuteBatchAsync(batch); // Act Func <Task> action = () => _sut.SaveEvents <FakeUser>(domainEvents); // Assert action.ShouldThrow <StorageException>(); string filter = PendingEvent.GetFilter(typeof(FakeUser), user.Id); var query = new TableQuery <PendingEvent> { FilterString = filter }; IEnumerable <PendingEvent> actual = await s_eventTable.ExecuteQuerySegmentedAsync(query, default); actual.Should().BeEmpty(); }
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 = PersistentEvent.Create( fixture.Create <Type>(), fixture.Create <Envelope <IDomainEvent> >(), new JsonMessageSerializer()); actual.RowKey.Should().Be(PersistentEvent.GetRowKey(domainEvent.Version)); }