public void SetUp() { BootStrapper.BootUp(this, null); _service = NcqrsEnvironment.Get <ICommandService>(); _service.Execute(new CreateNewNote()); _rand = new Random(DateTime.Now.Millisecond); }
public static void BootUp() { // initialize the config system Config.Config.LoadFromXml(Config.Config.DefaultPath); NcqrsEnvironment.SetDefault <ReadModel.IReadModelStore>(InitializeReadModelStore()); }
public void LoadItUp() { IList <Guid> ids = new List <Guid>(); for (int i = 0; i < 5; i++) { Guid id = Guid.NewGuid(); ids.Add(id); NcqrsEnvironment.Get <ICommandService>().Execute(new Env.CreateNoteCommand() { NoteId = id, NoteText = "Hello world " + i }); } foreach (Guid id in ids) { NcqrsEnvironment.Get <ICommandService>().Execute(new Env.ChangeNoteCommand() { NoteId = id, NewNoteText = "Hello solar system" }); } foreach (Guid id in ids) { NcqrsEnvironment.Get <ICommandService>().Execute(new Env.ChangeNoteCommand() { NoteId = id, NewNoteText = "Hello galaxy" }); } }
protected override void When() { ExecutedCommand = WhenExecuting(); var cmdService = NcqrsEnvironment.Get <ICommandService>(); cmdService.Execute(ExecutedCommand); }
public void Map(MapsToAggregateRootMethodAttribute attribute, ICommand command, IMappedCommandExecutor executor) { var commandType = command.GetType(); ValidateCommandType(commandType); var match = GetMatchingMethod(attribute, commandType, attribute.MethodName); Action <AggregateRoot, ICommand> action = (agg, cmd) => { var parameter = match.Item2.Select(p => p.GetValue(cmd, null)); match.Item1.Invoke(agg, parameter.ToArray()); }; Action executorAction = () => executor.ExecuteActionOnExistingInstance(GetAggregateRootId, GetAggregateRootType, action); if (commandType.IsDefined(typeof(TransactionalAttribute), false)) { var transactionService = NcqrsEnvironment.Get <ITransactionService>(); transactionService.ExecuteInTransaction(executorAction); } else { executorAction(); } }
private void RecordGivenEvents() { var store = NcqrsEnvironment.Get <IEventStore>(); var givenEventStream = ConvertGivenEvents(); store.Store(givenEventStream); }
protected override void SetupDependencies() { base.SetupDependencies(); GenerateEventSourceId(); RecordGivenEvents(); CommandService = NcqrsEnvironment.Get <ICommandService>(); }
public void Map(MapsToAggregateRootConstructorAttribute attribute, ICommand command, IMappedCommandExecutor executor) { var commandType = command.GetType(); ValidateCommandType(commandType); var match = GetMatchingConstructor(attribute, commandType); Func <ICommand, AggregateRoot> create = (c) => { var parameter = match.Item2.Select(p => p.GetValue(c, null)); return((AggregateRoot)match.Item1.Invoke(parameter.ToArray())); }; Action executorAction = () => executor.ExecuteActionCreatingNewInstance(create); if (commandType.IsDefined(typeof(TransactionalAttribute), false)) { var transactionService = NcqrsEnvironment.Get <ITransactionService>(); transactionService.ExecuteInTransaction(executorAction); } else { executorAction(); } }
public void Send(object payload) { _message.Payload = payload; _message.SenderId = _senderId; _message.SenderType = GetType(); _message.MessageId = NcqrsEnvironment.Get <IUniqueIdentifierGenerator>().GenerateNewId(); _sendAction(_message); }
protected override void InitializeEnvironment() { var store = new MsSqlServerEventStore(GetConnectionString()); NcqrsEnvironment.SetDefault <ISnapshotStore>(store); NcqrsEnvironment.SetDefault <IEventStore>(store); NcqrsEnvironment.SetDefault <IUnitOfWorkFactory>(new UnitOfWorkFactory()); }
/// <summary> /// Initializes a new instance of the <see cref="EventSource"/> class. /// </summary> protected EventSource() { InitialVersion = 0; var idGenerator = NcqrsEnvironment.Get <IUniqueIdentifierGenerator>(); EventSourceId = idGenerator.GenerateNewId(); }
/// <summary> /// Initializes a new instance of the <see cref="Event"/> class. /// </summary> public Event() { var idGenerator = NcqrsEnvironment.Get <IUniqueIdentifierGenerator>(); var clock = NcqrsEnvironment.Get <IClock>(); EventIdentifier = idGenerator.GenerateNewId(); EventTimeStamp = clock.UtcNow(); EventVersion = DefaultVersion; }
public void Public_event_handlers_should_be_mapped() { using (var work = NcqrsEnvironment.Get <IUnitOfWorkFactory>().CreateUnitOfWork(Guid.NewGuid())) { var target = new TheAggregateRoot(); target.ApplyEvent(new EventForPublicMethod()); target.OnEventForPublicMethodInvokedCount.Should().Be(1); } }
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)); }
/// <summary> /// Initializes a new instance of the <see cref="JsonEventFormatter"/> class /// with a given type resolver. /// </summary> /// <param name="typeResolver">The <see cref="IEventTypeResolver"/> to use /// when resolving event types/names.</param> /// <exception cref="ArgumentNullException"><paramref name="typeResolver"/> is <value>null</value>.</exception> public JsonEventFormatter(IEventTypeResolver typeResolver) { Contract.Requires <ArgumentNullException>(typeResolver != null, "typeResolver"); _typeResolver = typeResolver; _serializer = new JsonSerializer { ContractResolver = NcqrsEnvironment.Get <IContractResolver>() }; }
/// <summary> /// Used by WCF to enumerate all types inheriting from <see cref="CommandBase"/>, /// so that instances of them can be sent to a service operation that expects a command. /// </summary> /// <returns>An enumeration of all classes in the current AppDomain inheriting from <see cref="CommandBase" /></returns> public static IEnumerable <Type> GetKnownTypes() { var knownCommandsEnumerator = NcqrsEnvironment.Get <IKnownCommandsEnumerator>(); if (knownCommandsEnumerator == null) { throw new InvalidOperationException("No Ncqrs.Commanding.IKnownCommandsEnumerator implementation registered with the NcqrsEnvironment."); } return(knownCommandsEnumerator.GetAllCommandTypes()); }
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 Process(object message) { using (var work = NcqrsEnvironment.Get <IUnitOfWorkFactory>().CreateUnitOfWork()) { var incomingMessage = ReceiveMessage(message); var targetAggregateRoot = GetReceiver(work, incomingMessage); targetAggregateRoot.ProcessMessage(incomingMessage); work.Accept(); } }
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 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 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); }
protected override void ExecuteInContext(IUnitOfWorkContext context, AddInvoiceItem command) { ITaxRepository taxRepo = NcqrsEnvironment.Get <ITaxRepository>(); Tax tax = taxRepo.FindByCode(command.TaxCode, command.OwnerId); Invoice invoice = context.GetById <Invoice>(command.InvoiceId, command.KnownVersion); invoice.AddInvoiceItem(command.ItemId, command.Description, command.Quantity, command.Price, command.DiscountInPercent, tax, command.OwnerId, command.UserName); context.Accept(); }
public static void Configure() { if (NcqrsEnvironment.IsConfigured) { return; } var cfg = new Configuration(); NcqrsEnvironment.Configure(cfg); }
public Note(Guid id, string text) : base(id) { var clock = NcqrsEnvironment.Get <IClock>(); this.ApplyEvent(new NoteAdded { Id = id, Text = text, CreationDate = clock.UtcNow() }); }
public void Methods_marked_as_no_event_handler_should_not_be_mapped() { using (var work = NcqrsEnvironment.Get <IUnitOfWorkFactory>().CreateUnitOfWork(Guid.NewGuid())) { var target = new TheAggregateRoot(); Action act = () => target.ApplyEvent(new EventForNoEventHandlerMethod()); act.ShouldThrow <EventNotHandledException>(); } }
public void Method_with_a_wrong_method_name_should_not_be_mapped() { using (var work = NcqrsEnvironment.Get <IUnitOfWorkFactory>().CreateUnitOfWork(Guid.NewGuid())) { var target = new TheAggregateRoot(); Action act = () => target.ApplyEvent(new EventForMethodWithWrongMethodName()); act.ShouldThrow <EventNotHandledException>(); } }
public static void BootUp() { var config = new StructureMapConfiguration(c => { c.For <ICommandService>().Use(BuildCommandService); c.For <IEventStore>().Use(BuildEventStore); c.For <IEventBus>().Use(BuildEventBus); }); NcqrsEnvironment.Configure(config); }
public static void BootUp() { var config = new StructureMapConfiguration(cfg => { cfg.For <ICommandService>().Use(InitializeCommandService); cfg.For <IEventBus>().Use(InitializeEventBus); cfg.For <IEventStore>().Use(InitializeEventStore); }); NcqrsEnvironment.Configure(config); }
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 Note(Guid noteId, String text) : base(noteId) { var clock = NcqrsEnvironment.Get <IClock>(); ApplyEvent(new NewNoteAddedEvent { NoteId = noteId, Text = text, CreationDate = clock.UtcNow() }); }