コード例 #1
0
        public async Task RemoveAsync_ExistingEntity_EntityDeleted()
        {
            var eventStore = new PersonEventStore {
                PersonId = 12
            };

            eventStore.Events.Add(new PersonEventStore.PersonEvent
            {
                SerializedEvent = "{" +
                                  "\"$type\": \"Silverback.Tests.EventSourcing.TestTypes.Person+NameChangedEvent, Silverback.EventSourcing.Tests\"," +
                                  "\"NewName\": \"Silverback\"" +
                                  "}"
            });

            var repo = new PersonEventStoreRepository(eventStore);

            var entity = repo.GetById(12);

            entity.Should().NotBeNull();

            await repo.RemoveAsync(entity);

            repo.EventStores.Count.Should().Be(0);
            repo.EventStores.SelectMany(s => s.Events).Count().Should().Be(0);
        }
コード例 #2
0
        public async Task RemoveAsync_ExistingEntity_EntityDeleted()
        {
            var eventStore = _dbContext.Persons.Add(new PersonEventStore {
                Id = 12
            }).Entity;

            eventStore.Events.Add(new PersonEvent
            {
                SerializedEvent = "{" +
                                  "\"$type\": \"Silverback.Tests.EventSourcing.EntityFrameworkCore.TestTypes.Person+NameChangedEvent, Silverback.EventSourcing.EntityFrameworkCore.Tests\"," +
                                  "\"NewName\": \"Silverback\"" +
                                  "}"
            });
            _dbContext.SaveChanges();

            var repo = new PersonEventStoreRepository(_dbContext);

            var entity = await repo.GetAsync(p => p.Id == 12);

            entity.Should().NotBeNull();

            await repo.RemoveAsync(entity);

            await _dbContext.SaveChangesAsync();

            _dbContext.Persons.Count().Should().Be(0);
            _dbContext.Persons.SelectMany(s => s.Events).Count().Should().Be(0);
        }
コード例 #3
0
        public async Task RemoveAsync_NonExistingEntity_ReturnsNull()
        {
            var repo = new PersonEventStoreRepository();

            var entity = new Person(123);

            var result = await repo.RemoveAsync(entity);

            result.Should().BeNull();
        }