public static void BootUp() { // initialize the config system Config.Config.LoadFromXml(Config.Config.DefaultPath); NcqrsEnvironment.SetDefault <ReadModel.IReadModelStore>(InitializeReadModelStore()); }
protected override void InitializeEnvironment() { var store = new MsSqlServerEventStore(GetConnectionString()); NcqrsEnvironment.SetDefault <ISnapshotStore>(store); NcqrsEnvironment.SetDefault <IEventStore>(store); NcqrsEnvironment.SetDefault <IUnitOfWorkFactory>(new UnitOfWorkFactory()); }
public void SetUp() { _aggregateRootId = Guid.NewGuid(); _eventStore = MockRepository.GenerateMock <IEventStore>(); NcqrsEnvironment.SetDefault(_eventStore); _receivingStrategy = MockRepository.GenerateMock <IReceivingStrategy>(); _sut = new MessageService(); _sut.UseReceivingStrategy(new ConditionalReceivingStrategy(x => true, _receivingStrategy)); }
public void Setting_a_default_should_multiple_times_should_not_throw_an_exception() { var defaultFoo = MockRepository.GenerateMock <IFoo>(); var newDefaultFoo = MockRepository.GenerateMock <IFoo>(); NcqrsEnvironment.SetDefault <IFoo>(defaultFoo); NcqrsEnvironment.SetDefault <IFoo>(newDefaultFoo); NcqrsEnvironment.SetDefault <IFoo>(defaultFoo); NcqrsEnvironment.SetDefault <IFoo>(newDefaultFoo); }
public void It_should_initialize_with_a_new_id_given_by_the_generator_from_the_environment() { var generator = MockRepository.GenerateMock <IUniqueIdentifierGenerator>(); NcqrsEnvironment.SetDefault <IUniqueIdentifierGenerator>(generator); var theAggregate = new MyAggregateRoot(); generator.AssertWasCalled(g => g.GenerateNewId()); }
public void When_get_is_called_when_the_environmemt_is_not_configured_defaults_should_still_be_returned() { NcqrsEnvironment.Deconfigure(); var defaultClock = new DateTimeBasedClock(); NcqrsEnvironment.SetDefault <IClock>(defaultClock); NcqrsEnvironment.Get <IClock>().Should().Be(defaultClock); }
public void Constructing_a_new_event_base_it_should_call_the_GenerateNewId_method_from_the_generator_that_has_been_set_in_the_environment() { var generator = MockRepository.GenerateMock <IUniqueIdentifierGenerator>(); NcqrsEnvironment.SetDefault <IUniqueIdentifierGenerator>(generator); var mock = MockRepository.GenerateStub <Event>(); generator.AssertWasCalled(g => g.GenerateNewId()); }
public void Configure(Configure config) { Builder = config.Builder; Configurer = config.Configurer; NcqrsEnvironment.Configure(new NsbEnvironmentConfiguration(Builder)); _inProcessEventBus = new InProcessEventBus(false); NcqrsEnvironment.SetDefault <IEventBus>(_inProcessEventBus); _commandService = new NsbCommandService(); config.Configurer.RegisterSingleton(typeof(ICommandService), _commandService); }
public static void Start() { NcqrsEnvironment.SetDefault <IEventStore>(new TableOnlyStore("MainTest")); //NcqrsEnvironment.SetDefault<IEventStore>(new MsSqlServerEventStore(@"Server=.\SQLExpress;Initial Catalog=MyNotesEventStore;Integrated Security=SSPI")); CommandService c = new CommandService(); c.RegisterExecutorsInAssembly(typeof(CreateNoteCommand).Assembly); NcqrsEnvironment.SetDefault <ICommandService>(c); }
public void Setting_a_default_should_override_the_exiting_default() { var defaultFoo = MockRepository.GenerateMock <IFoo>(); var newDefaultFoo = MockRepository.GenerateMock <IFoo>(); NcqrsEnvironment.SetDefault <IFoo>(defaultFoo); NcqrsEnvironment.SetDefault <IFoo>(newDefaultFoo); var result = NcqrsEnvironment.Get <IFoo>(); result.Should().BeSameAs(newDefaultFoo); }
static void Main(string[] args) { NcqrsEnvironment.SetDefault(InitializeEventStore()); NcqrsEnvironment.SetDefault(InitializeCommandService()); var commandService = NcqrsEnvironment.Get <ICommandService>(); var id = new Guid("AE6920ED-381A-467D-8DB2-EE91E851F431"); commandService.Execute(new ChangeNameCommand(id, "Jane Smith Doe")); Console.WriteLine("If you see this message and no exception occurred, it had probably worked. You are all clear now!"); Console.ReadKey(true); }
static CommandService() { var service = new InProcessCommandService(); service.RegisterExecutor(new CommandExecutorCreateJunk()); NcqrsEnvironment.SetDefault <ICommandService>(service); var store = new InMemoryEventStore(); NcqrsEnvironment.SetDefault <IEventStore>(store); // TODO: remove this is for testing only Execute(new CommandCreateJunk("junk", new Vector3D(1, 2, 3), Quaternion.Identity)); }
public void Constructing_a_new_event_base_it_should_set_the_event_time_stap_to_the_time_given_by_the_IClock_from_the_NcqrsEnvironment() { var theTimeStamp = new DateTime(2000, 1, 1, 1, 1, 1, 1, DateTimeKind.Utc); var clock = MockRepository.GenerateStrictMock <IClock>(); clock.Stub(c => c.UtcNow()).Return(theTimeStamp); NcqrsEnvironment.SetDefault <IClock>(clock); var eventBase = MockRepository.GenerateStub <Event>(); eventBase.EventTimeStamp.Should().Be(theTimeStamp); }
public void Constructing_a_new_event_base_it_should_set_the_event_identifier_to_identifier_that_has_been_given_from_the_IUniqueIdentifierGenerator_from_the_NcqrsEnvironment() { var identiefier = Guid.NewGuid(); var generator = MockRepository.GenerateStrictMock <IUniqueIdentifierGenerator>(); generator.Stub(g => g.GenerateNewId()).Return(identiefier); NcqrsEnvironment.SetDefault <IUniqueIdentifierGenerator>(generator); var mock = MockRepository.GenerateStub <Event>(); mock.EventIdentifier.Should().Be(identiefier); }
protected override void InitializeEnvironment() { var factory = new AbsoluteOrderingSqlPersistenceFactory("SqlCeEventStore", new BinarySerializer(), false); var streamPersister = factory.Build(); streamPersister.Initialize(); var store = new OptimisticEventStore(streamPersister, new NullDispatcher()); var snapshotStore = new JoesSnapshotStoreAdapter(streamPersister); NcqrsEnvironment.SetDefault <ISnapshotStore>(snapshotStore); var uowFactory = new JoesUnitOfWorkFactory(store); NcqrsEnvironment.SetDefault <IUnitOfWorkFactory>(uowFactory); }
static void Main(string[] args) { NcqrsEnvironment.SetDefault(InitializeEventStore()); NcqrsEnvironment.SetDefault(InitializeCommandService()); var commandService = NcqrsEnvironment.Get <ICommandService>(); var id = new Guid("AE6920ED-381A-467D-8DB2-EE91E851F431"); commandService.Execute(new ChangeNameCommand(id, "Jane", "Doe")); Console.WriteLine("If you see this message and no exception occurred, it had probably worked. Now you can run AppV3."); Console.WriteLine("Press any key to continue"); Console.ReadLine(); }
public void Constructing_without_any_parameters_should_use_IUniqueIdentifierGenerator_to_generate_id() { var generatedId = Guid.NewGuid(); var generator = MockRepository.GenerateMock <IUniqueIdentifierGenerator>(); generator.Stub(t => t.GenerateNewId()).Return(generatedId); NcqrsEnvironment.SetDefault <IUniqueIdentifierGenerator>(generator); var command = new FooCommand(); generator.VerifyAllExpectations(); command.CommandIdentifier.Should().Be(generatedId); NcqrsEnvironment.Deconfigure(); }
public void Configure(Configure config) { Builder = config.Builder; Configurer = config.Configurer; NcqrsEnvironment.Configure(new NsbEnvironmentConfiguration(Builder)); var compositeBus = new CompositeEventBus(); _inProcessEventBus = new InProcessEventBus(false); compositeBus.AddBus(new NsbEventBus()); compositeBus.AddBus(_inProcessEventBus); _sendingEventHandler = new MessageSendingEventHandler(); _inProcessEventBus.RegisterHandler(_sendingEventHandler); NcqrsEnvironment.SetDefault(compositeBus); _messageService = new MessageService(); config.Configurer.RegisterSingleton(typeof(IMessageService), _messageService); }
public void InstallMongoDBEventStore() { MongoServerSettings settings = new MongoServerSettings(); settings.ConnectionMode = ConnectionMode.ReplicaSet; settings.ReplicaSetName = "dokukuSet"; settings.DefaultCredentials = new MongoCredentials("admin", "S31panas", true); settings.SlaveOk = true; settings.Servers = new List <MongoServerAddress> { new MongoServerAddress("tcloud2.bonastoco.com", 27021), new MongoServerAddress("tcloud2.bonastoco.com", 27022) }; MongoServer mongo = MongoServer.Create(settings); NcqrsEnvironment.SetDefault <IEventStore>(new MongoDBEventStore(mongo, SafeMode.True, "Invoice")); // NcqrsEnvironment.Get<CommandService>().RegisterExecutor<Ncqrs.Commanding.CommandExecution.ICommandExecutor<CreateInvoice>>( }
public void Snapshotting_should_persist_state() { InitializeEnvironment(); var commandService = new CommandService(); commandService.RegisterExecutorsInAssembly(typeof(FetureTests).Assembly); NcqrsEnvironment.SetDefault <ISnapshottingPolicy>(new SimpleSnapshottingPolicy(2)); var noteId = Guid.NewGuid(); var createNewCommand = new CreateNewNoteCommand { NoteId = noteId, Text = "Note One" }; commandService.Execute(createNewCommand); var updateCommand = new ChangeNoteTextCommand() { NoteId = noteId, NewText = "Note One Modified" }; commandService.Execute(updateCommand); updateCommand = new ChangeNoteTextCommand() { NoteId = noteId, NewText = "Note One Modified Once Again" }; commandService.Execute(updateCommand); updateCommand = new ChangeNoteTextCommand() { NoteId = noteId, NewText = "Note One Modified And Again" }; commandService.Execute(updateCommand); var uowFactory = NcqrsEnvironment.Get <IUnitOfWorkFactory>(); using (var uow = uowFactory.CreateUnitOfWork(Guid.NewGuid())) { var note = (Note)uow.GetById(typeof(Note), noteId, null); note.Text.Should().Be("Note One Modified And Again"); } }
public void Configured_instance_should_over_rule_default() { var defaultClock = new DateTimeBasedClock(); var configuredClock = MockRepository.GenerateMock <IClock>(); IClock ingore; var configuration = MockRepository.GenerateMock <IEnvironmentConfiguration>(); configuration.Stub((m) => m.TryGet(out ingore)).IgnoreArguments().OutRef(configuredClock).Return(true); NcqrsEnvironment.SetDefault <IClock>(defaultClock); NcqrsEnvironment.Configure(configuration); var result = NcqrsEnvironment.Get <IClock>(); Assert.AreSame(configuredClock, result); Assert.AreNotSame(defaultClock, result); NcqrsEnvironment.Deconfigure(); }
public static void Boot() { NcqrsEnvironment.SetDefault <ICommandService>(CreateCommandService()); NcqrsEnvironment.SetDefault <IEventStore>(CreateEventStore()); NcqrsEnvironment.SetDefault <IEventBus>(CreateEventBus()); }
public void Aggregates_should_be_persisted_in_one_transaction() { var factory = new AbsoluteOrderingSqlPersistenceFactory("SqlJoesEventStore", new BinarySerializer(), true); var streamPersister = factory.Build(); streamPersister.Initialize(); var store = new OptimisticEventStore(streamPersister, new NullDispatcher()); var uowFactory = new JoesUnitOfWorkFactory(store); NcqrsEnvironment.SetDefault <IUnitOfWorkFactory>(uowFactory); var note1Id = Guid.NewGuid(); var note2Id = Guid.NewGuid(); //Create using (var uow = uowFactory.CreateUnitOfWork(Guid.NewGuid())) { var note1 = new Note(note1Id, "Text 1"); var note2 = new Note(note2Id, "Text 2"); uow.Accept(); } try { using (var tx = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = IsolationLevel.ReadCommitted })) { using (var uow = uowFactory.CreateUnitOfWork(Guid.NewGuid())) { var note1 = (Note)uow.GetById(typeof(Note), note1Id, null); note1.ChangeText("Text 1 Modified"); var note2 = (Note)uow.GetById(typeof(Note), note2Id, null); note2.ChangeText("Text 2 Modified"); var t = new Thread(() => { using (var nestedUow = uowFactory.CreateUnitOfWork(Guid.NewGuid())) { note2 = (Note)nestedUow.GetById(typeof(Note), note2Id, null); note2.ChangeText("Text 2 Modified from mested UoW"); nestedUow.Accept(); } }); t.Start(); t.Join(); uow.Accept(); //Throws } tx.Complete(); } } catch (Exception) { //Swallow } //Nothing should be modified using (var uow = uowFactory.CreateUnitOfWork(Guid.NewGuid())) { var note1 = (Note)uow.GetById(typeof(Note), note1Id, null); note1.Text.Should().Be("Text 1"); var note2 = (Note)uow.GetById(typeof(Note), note2Id, null); note2.Text.Should().Be("Text 2 Modified from mested UoW"); } }
public static void BootUp() { NcqrsEnvironment.SetDefault <ICommandService>(InitializeCommandService()); NcqrsEnvironment.SetDefault <IEventStore>(InitializeEventStore()); NcqrsEnvironment.SetDefault <IEventBus>(InitializeEventBus()); }