public void CanLoadRootsDuringViewLocation() { _context.AddViewManager(_factory.GetViewManager <CountTheNodes>()); // arrange using (var uow = _context.BeginUnitOfWork()) { var node = uow.Load <Node>("rootnodeid"); var child1 = uow.Load <Node>("child1"); var child2 = uow.Load <Node>("child2"); child1.AttachTo(node); child2.AttachTo(node); var subChild1 = uow.Load <Node>("subchild1"); var subChild2 = uow.Load <Node>("subchild2"); var subChild3 = uow.Load <Node>("subchild3"); subChild1.AttachTo(child1); subChild2.AttachTo(child1); subChild3.AttachTo(child2); // act uow.Commit(); } _context.WaitForViewToCatchUp <CountTheNodes>(); // assert var view = _factory.Load <CountTheNodes>("rootnodeid"); Assert.That(view.Nodes, Is.EqualTo(5)); }
public void WorksWithInstancePerAggregateRootView() { _context.AddViewManager(_instancePerAggregateRootViewManager); _context.Save("id1", new ThisIsJustAnEvent()); _context.Save("id1", new ThisIsJustAnEvent()); _context.Save("id1", new ThisIsJustAnEvent()); _context.Save("id2", new ThisIsJustAnEvent()); _context.Save("id2", new ThisIsJustAnEvent()); _context.Save("id2", new ThisIsJustAnEvent()); _context.WaitForViewsToCatchUp(); var view = _factory.Load <InstancePerAggregateRootView>(InstancePerAggregateRootLocator.GetViewIdFromAggregateRootId("id1")); Assert.That(view.EventCounter, Is.EqualTo(3)); }
public void WorksWithSimpleScenario() { // arrange Console.WriteLine("Adding view manager for GeneratedIds"); var view = _factory.GetViewManager <GeneratedIds>(); _context.AddViewManager(view); // act Console.WriteLine("Processing 2 commands"); _context.ProcessCommand(new GenerateNewId(IdGenerator.InstanceId) { IdBase = "bim" }); _context.ProcessCommand(new GenerateNewId(IdGenerator.InstanceId) { IdBase = "bim" }); var last = _context.ProcessCommand(new GenerateNewId(IdGenerator.InstanceId) { IdBase = "bom" }); // assert Console.WriteLine("Waiting until dispatched: {0}", last.GetNewPosition()); view.WaitUntilProcessed(last, _defaultTimeout).Wait(); var idsView = _factory.Load <GeneratedIds>(InstancePerAggregateRootLocator.GetViewIdFromAggregateRootId(IdGenerator.InstanceId)); Assert.That(idsView, Is.Not.Null, "Could not find view!"); var storedIds = idsView.AllIds; Assert.That(storedIds.Count, Is.EqualTo(3)); Assert.That(storedIds, Contains.Item("bim/0")); Assert.That(storedIds, Contains.Item("bim/1")); Assert.That(storedIds, Contains.Item("bom/0")); }
protected override void DoSetUp() { CirqusLoggerFactory.Current = new ConsoleLoggerFactory(minLevel: Logger.Level.Warn); _factory = RegisterForDisposal(new TFactory()); _context = RegisterForDisposal( TestContext.With() .Options(x => x.Asynchronous()) .Create()); _viewManager = _factory.GetViewManager <PurgeTestView>(); _context.AddViewManager(_viewManager); }
public void CanRecoverAfterTransientErrors(int eventCount, double failIntervalSeconds, double failDurationSeconds) { // arrange var eventIds = Enumerable.Range(0, eventCount).ToList(); var failCount = 0; using (var failTimer = new Timer(TimeSpan.FromSeconds(failIntervalSeconds).TotalMilliseconds)) { failTimer.Elapsed += delegate { View.Fail = true; failCount++; ThreadPool.QueueUserWorkItem(_ => { Thread.Sleep(TimeSpan.FromSeconds(failDurationSeconds)); View.Fail = false; }); }; failTimer.Start(); var events = eventIds .Select(id => new Event { EventId = id }) .ToList(); events.ForEach(e => _context.Save("someid", e)); // act _context.AddViewManager(_viewManager); _context.WaitForViewsToCatchUp(300); } Console.WriteLine(@"==================================================== Processed {0} events Failed every {1} seconds (total fail count: {2}) ====================================================", eventCount, failIntervalSeconds, failCount); // assert var viewInstance = _viewManager.Load(GlobalInstanceLocator.GetViewInstanceId()); Assert.That(viewInstance.EventIds, Is.EqualTo(eventIds)); }
protected override void DoSetUp() { CirqusLoggerFactory.Current = new ConsoleLoggerFactory(minLevel: Logger.Level.Warn); _factory = RegisterForDisposal(new TFactory()); _context = RegisterForDisposal( TestContext.With() .Options(x => x.Asynchronous()) .Create()); _viewManager1 = _factory.GetViewManager <ViewThatSubscribesToEvents>(); _viewManager2 = _factory.GetViewManager <ViewThatSubscribesToAggregateRootEvent>(); _viewManager3 = _factory.GetViewManager <ViewThatSubscribesToAllEvents>(); _context .AddViewManager(_viewManager1) .AddViewManager(_viewManager2) .AddViewManager(_viewManager3); }