public void can_get_repository_events() { var id = Guid.NewGuid(); var aggregate = new TestAggregate(id); _fixture.Repository.Save(aggregate); _fixture.RepositoryEvents.WaitFor <TestAggregateMessages.NewAggregate>(TimeSpan.FromMilliseconds(200)); _fixture .RepositoryEvents .AssertNext <TestAggregateMessages.NewAggregate>(e => e.AggregateId == id, "Aggregate Id Missmatch") .AssertEmpty(); }
public void throws_on_requesting_specific_version_higher_than_exists() { foreach (var repo in _repos) { var id = Guid.NewGuid(); var tAgg = new TestAggregate(id); tAgg.RaiseBy(1); tAgg.RaiseBy(1); tAgg.RaiseBy(1); tAgg.RaiseBy(1); //v4 repo.Save(tAgg); Assert.Throws <AggregateVersionException>(() => repo.GetById <TestAggregate>(id, 50)); } }
public void can_try_get_new_aggregate_at_version() { foreach (var repo in _repos) { var id = Guid.NewGuid(); Assert.False(repo.TryGetById(id, out TestAggregate tAgg, 1)); Assert.Null(tAgg); tAgg = new TestAggregate(id); repo.Save(tAgg); Assert.True(repo.TryGetById(id, out TestAggregate rAgg, 1)); Assert.NotNull(rAgg); Assert.Equal(tAgg.Id, rAgg.Id); } }
public void can_update_and_save_aggregate() { foreach (var repo in _repos) { var id = Guid.NewGuid(); var tAgg = new TestAggregate(id); repo.Save(tAgg); // Get v2 var v2Agg = repo.GetById <TestAggregate>(id); Assert.Equal((uint)0, v2Agg.CurrentAmount()); // update v2 v2Agg.RaiseBy(1); Assert.Equal((uint)1, v2Agg.CurrentAmount()); repo.Save(v2Agg); // get v3 var v3Agg = repo.GetById <TestAggregate>(id); Assert.Equal((uint)1, v3Agg.CurrentAmount()); } }
public void can_get_aggregate_at_version() { foreach (var repo in _repos) { var id = Guid.NewGuid(); Assert.Throws <InvalidOperationException>(() => repo.GetById <TestAggregate>(id, 0)); var tAgg = new TestAggregate(id); tAgg.RaiseBy(1); Assert.Equal((uint)1, tAgg.CurrentAmount()); tAgg.RaiseBy(2); Assert.Equal((uint)3, tAgg.CurrentAmount()); // get latest version (v3) repo.Save(tAgg); var v3Agg = repo.GetById <TestAggregate>(id); Assert.Equal((uint)3, v3Agg.CurrentAmount()); //get version v2 var v2Agg = repo.GetById <TestAggregate>(id, 2); Assert.Equal((uint)1, v2Agg.CurrentAmount()); } }
public void can_multiple_update_and_save_multiple_aggregates() { foreach (var repo in _repos) { var id1 = Guid.NewGuid(); var tAgg = new TestAggregate(id1); tAgg.RaiseBy(1); tAgg.RaiseBy(2); tAgg.RaiseBy(3); repo.Save(tAgg); var loadedAgg1 = repo.GetById <TestAggregate>(id1); Assert.True(tAgg.CurrentAmount() == loadedAgg1.CurrentAmount()); var id2 = Guid.NewGuid(); var tAgg2 = new TestAggregate(id2); tAgg2.RaiseBy(4); tAgg2.RaiseBy(5); tAgg2.RaiseBy(6); repo.Save(tAgg2); var loadedAgg2 = repo.GetById <TestAggregate>(id2); Assert.True(tAgg2.CurrentAmount() == loadedAgg2.CurrentAmount()); } }
public void will_throw_concurrency_exception() { foreach (var repo in _repos) { var id = Guid.NewGuid(); var tAgg = new TestAggregate(id); tAgg.RaiseBy(1); Assert.Equal((uint)1, tAgg.CurrentAmount()); tAgg.RaiseBy(2); Assert.Equal((uint)3, tAgg.CurrentAmount()); // get latest version (v3) then update & save repo.Save(tAgg); var v3Agg = repo.GetById <TestAggregate>(id); v3Agg.RaiseBy(2); repo.Save(v3Agg); //Update & save original copy tAgg.RaiseBy(6); var r = repo; //copy iteration varible for closure Assert.Throws <WrongExpectedVersionException>(() => r.Save(tAgg)); } }
public void can_clear_queues() { var evt = new TestEvent(); _fixture.Dispatcher.Publish(evt); var id = Guid.NewGuid(); var aggregate = new TestAggregate(id); _fixture.Repository.Save(aggregate); _fixture.RepositoryEvents.WaitFor <TestAggregateMessages.NewAggregate>(TimeSpan.FromMilliseconds(100)); _fixture .TestQueue .Messages .TryPeek(out var msg); Assert.IsType <TestEvent>(msg); Assert.Equal(evt.MsgId, msg.MsgId); _fixture .RepositoryEvents .Messages .TryPeek(out var repoEvt); Assert.IsType <TestAggregateMessages.NewAggregate>(repoEvt); Assert.Equal(id, ((TestAggregateMessages.NewAggregate)repoEvt).AggregateId); _fixture.ClearQueues(); _fixture .TestQueue .AssertEmpty(); _fixture .RepositoryEvents .AssertEmpty(); }