Beispiel #1
0
        public static void BootUp()
        {
            // initialize the config system
            Config.Config.LoadFromXml(Config.Config.DefaultPath);

            NcqrsEnvironment.SetDefault <ReadModel.IReadModelStore>(InitializeReadModelStore());
        }
Beispiel #2
0
        protected override void InitializeEnvironment()
        {
            var store = new MsSqlServerEventStore(GetConnectionString());

            NcqrsEnvironment.SetDefault <ISnapshotStore>(store);
            NcqrsEnvironment.SetDefault <IEventStore>(store);
            NcqrsEnvironment.SetDefault <IUnitOfWorkFactory>(new UnitOfWorkFactory());
        }
Beispiel #3
0
 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));
 }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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());
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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());
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
        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));
        }
Beispiel #13
0
        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);
        }
Beispiel #14
0
        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);
        }
Beispiel #15
0
        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);
        }
Beispiel #16
0
        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();
        }
Beispiel #17
0
        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();
        }
Beispiel #18
0
        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);
        }
Beispiel #19
0
        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>>(
        }
Beispiel #20
0
        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");
            }
        }
Beispiel #21
0
        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();
        }
Beispiel #22
0
 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());
 }