public void SaveSnapshotCountTest1() { var aggregateRootId = Guid.NewGuid(); var employee = new Employee(aggregateRootId); var localSnapshotProvider = new InMemorySnapshotProvider(); var localRepository = new EventSourcingDomainRepository(eventStore, eventPublisher, localSnapshotProvider); for (var i = 0; i < 31; i++) { employee.ChangeName($"daxnet_{i}"); } localRepository.Save <Guid, Employee>(employee); Assert.Equal(1, localSnapshotProvider.snapshots.Count); }
private IUnityContainer CreateContainer() { var container = new UnityContainer(); var config = this.domainRegistry.Config; container.RegisterInstance <IEventStoreRebuilderConfig>(config); container.RegisterInstance <ISystemTime>(config.SystemTime); var commandProcessor = new InMemoryCommandProcessor(this.tracer); var eventProcessor = new SynchronousEventDispatcher(this.tracer); container.RegisterInstance <ITextSerializer>(new JsonTextSerializer()); container.RegisterInstance <ITracer>(this.tracer); var snapshoter = new InMemorySnapshotProvider("Snapshotter", config.SystemTime); container.RegisterInstance <ISnapshotProvider>(snapshoter); container.RegisterInstance <IMetadataProvider>(new StandardMetadataProvider()); container.RegisterType <EventStoreDbContext>(new ContainerControlledLifetimeManager(), new InjectionConstructor(config.NewEventStoreConnectionString)); container.RegisterType(typeof(IEventStore <>), typeof(InMemoryEventStore <>), new ContainerControlledLifetimeManager()); container.RegisterInstance <IEventDispatcher>(eventProcessor); container.RegisterInstance <ICommandProcessor>(commandProcessor); container.RegisterInstance <ICommandHandlerRegistry>(commandProcessor); var bus = new InMemoryBus(); container.RegisterInstance <IInMemoryBus>(bus); var perfCounter = new EventStoreRebuilderPerfCounter(this.tracer, config.SystemTime); container.RegisterInstance <IRebuilderPerfCounter>(perfCounter); container.RegisterType(typeof(IEventStoreRebuilderEngine), typeof(EventStoreRebuilderEngine), new ContainerControlledLifetimeManager()); foreach (var registrationAction in this.domainRegistry.RegistrationList) { registrationAction(container, eventProcessor); } this.RegisterCommandHandlers(container); return(container); }
public void LoadFromSnapshotTest2() { var aggregateRootId = Guid.NewGuid(); var employee = new Employee(aggregateRootId); var localSnapshotProvider = new InMemorySnapshotProvider(); var localRepository = new EventSourcingDomainRepository(eventStore, eventPublisher, localSnapshotProvider); for (var i = 0; i < 31; i++) { employee.ChangeName($"daxnet_{i}"); } localRepository.Save <Guid, Employee>(employee); for (var i = 0; i < 4; i++) { employee.ChangeTitle($"Software Developer_{i}"); } localRepository.Save <Guid, Employee>(employee); var employee2 = localRepository.GetById <Guid, Employee>(aggregateRootId); Assert.Equal(employee.Name, employee2.Name); Assert.Equal(employee.Title, employee2.Title); }