public async Task GetOptionalAsyncReturnsEmpty() { using (var fixture = new MsSqlStreamStoreFixture("dbo")) { using (var store = await fixture.GetStreamStore()) { var sut = new RepositoryScenarioBuilder(store) .BuildForAsyncRepository(); var result = await sut.GetOptionalAsync(_model.UnknownIdentifier); Assert.Equal(result, Optional <AggregateRootEntityStub> .Empty); } } }
public async Task GetOptionalAsyncReturnsRootForKnownId() { using (var fixture = new MsSqlStreamStoreFixture("dbo")) { using (var store = await fixture.GetStreamStore()) { var sut = new RepositoryScenarioBuilder(store) .ScheduleAttachToUnitOfWork(new Aggregate(_model.KnownIdentifier, 0, _root)) .BuildForAsyncRepository(); var result = await sut.GetOptionalAsync(_model.KnownIdentifier); Assert.Equal(result, new Optional <AggregateRootEntityStub>(_root)); } } }
public async Task GetReturnsRootOfKnownId() { using (var fixture = new MsSqlStreamStoreFixture("dbo")) { using (var store = await fixture.GetMsSqlStreamStore()) { var sut = new RepositoryScenarioBuilder(store) .ScheduleAppendToStream(_model.KnownIdentifier, new EventStub(1)) .BuildForAsyncRepository(); var result = await sut.GetAsync(_model.KnownIdentifier); result.RecordedEvents.ShouldBeEquivalentTo(new[] { new EventStub(1) }); } } }
public async Task AddAttachesToUnitOfWork() { using (var fixture = new MsSqlStreamStoreFixture("dbo")) { using (var store = await fixture.GetStreamStore()) { var sut = new RepositoryScenarioBuilder(store) .BuildForAsyncRepository(); sut.Add(_model.KnownIdentifier, _root); Aggregate aggregate; var result = sut.UnitOfWork.TryGet(_model.KnownIdentifier, out aggregate); Assert.True(result); Assert.Equal(aggregate.Identifier, _model.KnownIdentifier); Assert.Equal(aggregate.Root, _root); } } }
public async Task GetAsyncThrows() { using (var fixture = new MsSqlStreamStoreFixture("dbo")) { using (var store = await fixture.GetStreamStore()) { var sut = new RepositoryScenarioBuilder(store) .BuildForAsyncRepository(); var exception = await Assert.ThrowsAsync <AggregateNotFoundException>(async() => { var _ = await sut.GetAsync(_model.UnknownIdentifier); }); Assert.Equal(exception.Identifier, _model.UnknownIdentifier); Assert.Equal(exception.ClrType, typeof(AggregateRootEntityStub)); } } }