public async Task CanMeasureTimeSpentInViewManagers() { var waitHandle = new ViewManagerWaitHandle(); var myProfiler = new MyProfiler(); var view1 = new InMemoryViewManager <SlowView>(); var view2 = new InMemoryViewManager <QuickView>(); var commandProcessor = CommandProcessor.With() .Logging(l => l.UseConsole(minLevel: Logger.Level.Debug)) .EventStore(e => e.UseInMemoryEventStore()) .EventDispatcher(e => { e.UseViewManagerEventDispatcher(view1, view2) .WithWaitHandle(waitHandle) .WithProfiler(myProfiler); }) .Create(); using (commandProcessor) { var lastResult = Enumerable.Range(0, 10) .Select(i => commandProcessor.ProcessCommand(new Commando("someId"))) .Last(); await waitHandle.WaitForAll(lastResult, TimeSpan.FromMinutes(1)); } var accumulatedTimes = myProfiler.GetAccumulatedTimes(); Assert.That(accumulatedTimes.ContainsKey(view1), "Could not find {0} among the keys!", view1); Assert.That(accumulatedTimes.ContainsKey(view2), "Could not find {0} among the keys!", view2); Assert.That(accumulatedTimes[view1], Is.GreaterThan(TimeSpan.FromSeconds(1))); Assert.That(accumulatedTimes[view2], Is.GreaterThan(TimeSpan.FromSeconds(.1)).And.LessThan(TimeSpan.FromSeconds(0.15))); }
public async Task ItShallNotBeSo() { var waitHandle = new ViewManagerWaitHandle(); var viewManager = new InMemoryViewManager <Wview>(); var commandProcessor = CommandProcessor.With() .EventStore(e => e.UseInMemoryEventStore()) .EventDispatcher(e => { e.UseViewManagerEventDispatcher(viewManager) .WithWaitHandle(waitHandle); }) .Options(o => o.SetMaxRetries(0)) .Create(); const string oneWootId = "oneWoot"; const string anotherWootId = "anotherWoot"; using (commandProcessor) { commandProcessor.ProcessCommand(new MakeAnotherWootDoItsThing(anotherWootId)); commandProcessor.ProcessCommand(new MakeOneWootReadAnotherWoot(oneWootId, anotherWootId)); commandProcessor.ProcessCommand(new MakeAnotherWootDoItsThing(anotherWootId)); var lastResult = commandProcessor.ProcessCommand(new MakeOneWootReadAnotherWoot(oneWootId, anotherWootId)); await waitHandle.WaitFor <Wview>(lastResult, TimeSpan.FromSeconds(10)); var instance = viewManager.Load(GlobalInstanceLocator.GetViewInstanceId()); instance.ToString(); } }
private static void RegisterSimpleViewInstance <TView>() where TView : class, IViewInstance, ISubscribeTo, new() { var viewInstance = new InMemoryViewManager <TView>(); Views.Add(viewInstance); _container.RegisterSingle <IViewManager <TView> >(viewInstance); }
public void ExceptionsInViewsBubblesToSurface() { var view = new InMemoryViewManager <ThrowingView>(); Configure(x => x.EventDispatcher(d => d.UseSynchronousViewManangerEventDispatcher(view))); Should.Throw <ApplicationException>(() => Emit(NewId <RootA>(), new EventA1())) .InnerException.ShouldBeOfType <InvalidOperationException>() .Message.ShouldBe("hej"); }
[OneTimeSetUp] public void StartDomain() { _view = new InMemoryViewManager <BenefitEstimateViewModel>(); _eventstore = new InMemoryEventStore(); _processor = CommandProcessor.With() .EventStore(c => c.RegisterInstance(_eventstore)) .EventDispatcher(e => e.UseViewManagerEventDispatcher(new IViewManager[] { _view })) .Create(); }
protected override void DoSetUp() { _viewManager = new InMemoryViewManager <RootView>(); _commandProcessor = CommandProcessor.With() .EventStore(e => e.InMemoryEventStore()) .EventDispatcher(e => e.UseViewManagerEventDispatcher(_viewManager)) .Create(); RegisterForDisposal(_commandProcessor); }
protected override void DoSetUp() { var factory = new TEventStoreFactory(); _viewManager = new InMemoryViewManager <LeView>(); _commandProcessor = CreateCommandProcessor(config => config .EventStore(e => e.Register(c => factory.GetEventStore())) .EventDispatcher(e => e.UseViewManagerEventDispatcher(_viewManager)) .Options(o => o.UseCustomDomainEventSerializer(new BinaryDomainEventSerializer()))); RegisterForDisposal(_commandProcessor); }
protected override void DoSetUp() { _viewManager = new InMemoryViewManager <RootView>(); var services = new ServiceCollection(); services.AddCirqus(c => c.EventStore(e => e.UseInMemoryEventStore()) .EventDispatcher(e => e.UseViewManagerEventDispatcher(_viewManager))); var provider = services.BuildServiceProvider(); _commandProcessor = provider.GetService <ICommandProcessor>(); RegisterForDisposal(_commandProcessor); }
public void CanUpdateViewSynchronously() { var view = new InMemoryViewManager <ViewA>(); Configure(x => x.EventDispatcher(d => d .UseSynchronousViewManangerEventDispatcher(view) .WithViewContext(new Dictionary <string, object> { { "Tag", new Tag() } }))); Emit(NewId <RootA>(), new EventA1()); Emit(NewId <RootA>(), new EventA1()); view.GetPosition().Result.ShouldBe(1); // position starts at -1 }
public void CanUpdateMultipleViewsSynchronously() { var a = new InMemoryViewManager <ViewA>(); var b = new InMemoryViewManager <ViewB>(); Configure(x => x.EventDispatcher(d => d .UseSynchronousViewManangerEventDispatcher(a, b) .WithViewContext(new Dictionary <string, object> { { "Tag", new Tag() } }))); Emit(NewId <RootA>(), new EventA1()); b.Load(GlobalInstanceLocator.GetViewInstanceId()) .Tag.ShouldBe("Greetings from ViewA;Greetings from ViewB"); }
private void SetupCommandProcessor() { var estimateViewModels = new InMemoryViewManager <BenefitEstimateViewModel>(); estimateViewModels.Updated += x => Broadcast(x); var viewManagers = new List <IViewManager> { estimateViewModels }; var eventstore = new NtfsEventStore(this.GetDataFolder()); var processor = CommandProcessor.With() .EventStore(c => c.RegisterInstance(eventstore)) .EventDispatcher(e => e.UseViewManagerEventDispatcher(viewManagers.ToArray())) .Create(); TinyIoC.TinyIoCContainer.Current.Register <InMemoryViewManager <BenefitEstimateViewModel> >(estimateViewModels); TinyIoC.TinyIoCContainer.Current.Register <ICommandProcessor>(processor); TinyIoC.TinyIoCContainer.Current.Register <IEventStore>(eventstore); TinyIoC.TinyIoCContainer.Current.Register <List <IViewManager> >(viewManagers); }
public void CanTestWithDependentViewManagerEventDispatcher() { var a = new InMemoryViewManager <ViewA>(); var b = new InMemoryViewManager <ViewB>(); Configure(x => { x.EventDispatcher(d => { var context = new Dictionary <string, object> { { "Tag", new Tag() } }; d.UseViewManagerEventDispatcher(a).WithViewContext(context); d.UseDependentViewManagerEventDispatcher(b).DependentOn(a).WithViewContext(context); }); }); Emit(NewId <RootA>(), new EventA1()); b.Load(GlobalInstanceLocator.GetViewInstanceId()) .Tag.ShouldBe("Greetings from ViewA;Greetings from ViewB"); }
protected override void DoSetUp() { _viewManager1 = new InMemoryViewManager <MyViewInstance>(); _viewManager2 = new InMemoryViewManager <MyViewInstanceImplicit>(); _viewManager3 = new InMemoryViewManager <MyViewInstanceEmitting>(); _viewManager4 = new InMemoryViewManager <MyViewInstanceLoadingNonexistentRoot>(); _cirqus = CreateCommandProcessor(config => config .EventStore(e => e.UseInMemoryEventStore()) .EventDispatcher(e => e.Register <IEventDispatcher>(c => { var repository = c.GetService <IAggregateRootRepository>(); var store = c.GetService <IEventStore>(); var serializer = c.GetService <IDomainEventSerializer>(); var typeMapper = c.GetService <IDomainTypeNameMapper>(); _eventDispatcher = new ViewManagerEventDispatcher(repository, store, serializer, typeMapper); return(_eventDispatcher); }))); RegisterForDisposal(_cirqus); }
public void CanGetViewTypeFromViewManager() { IViewManager viewManager = new InMemoryViewManager <SomeView>(); Assert.That(viewManager.GetViewType(), Is.EqualTo(typeof(SomeView))); }