public Task <int> Handle(CreateCartCommand request, CancellationToken cancellationToken) { using (TransactionScope scope = new TransactionScope()) { log.Debug("start handling command ..."); log.Debug("start dispatch event..."); IDomainEvent domainEvent = new CartCreatedDomainEvent() { DomainEventId = Guid.NewGuid().ToString(), DomainEventName = "CartCreated", DomainEventRoutingKey = RoutingKeyConstants.ToCartCreatedDomainEventSubscribers, DomainEventType = 0, CartId = "test-cart-id" }; _mediator.Publish(domainEvent); Transaction.Current.TransactionCompleted += new TransactionCompletedEventHandler((sender, e) => { _dispatchIntegrationEventWhenTransactionCompletedEvent.Handler(sender, e, _rmqSender, domainEvent); }); scope.Complete(); } return(Task.FromResult(1)); }
public void Mapper_StoredEventToDomainEvent_Test() { var config = new MapperConfiguration(cfg => { cfg.AddProfile <MapDomainEventToStoredEventProfile>(); cfg.AddProfile <MapStoredEventToDomainEventProfile>(); cfg.AddProfile <CartCreatedDomainEventProfile>(); }); IMapper mapper = config.CreateMapper(); IDomainEvent cartCreatedDomainEvent = new CartCreatedDomainEvent("test-id"); StoredEvent storedEvent = new StoredEvent() { Id = Guid.NewGuid(), Name = "CartCreatedDomainEvent", DomainEventType = cartCreatedDomainEvent.DomainEventType, OccurredOn = cartCreatedDomainEvent.OccurredOn, Payload = JsonConvert.SerializeObject(cartCreatedDomainEvent, Formatting.None, new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver() }) }; _output.WriteLine(JsonConvert.SerializeObject(storedEvent, Formatting.Indented)); var target = Convert.ChangeType(mapper.Map(storedEvent, storedEvent.GetType(), Type.GetType(storedEvent.Name)), Type.GetType(storedEvent.Name)); _output.WriteLine(JsonConvert.SerializeObject(target, Formatting.Indented)); //Assert.True(target.DomainEventName == "test"); Assert.Equal(typeof(CartCreatedDomainEvent), target.GetType()); }
public void Mapper_IDomainEventToStoredEvent_Test() { var config = new MapperConfiguration(cfg => { cfg.AddProfile <MapDomainEventToStoredEventProfile>(); cfg.AddProfile <MapStoredEventToDomainEventProfile>(); cfg.AddProfile <CartCreatedDomainEventProfile>(); }); IMapper mapper = config.CreateMapper(); CartCreatedDomainEvent cartCreatedDomainEvent = new CartCreatedDomainEvent("test-id"); var target = mapper.Map <StoredEvent>(cartCreatedDomainEvent); _output.WriteLine(JsonConvert.SerializeObject(target, Formatting.Indented)); Assert.True(false); }
public ActionResult <string> Msg() { var nhConfig = new Configuration().Configure(); var sessionFactory = nhConfig.BuildSessionFactory(); string result = ""; using (var session = sessionFactory.OpenSession()) using (var tx = session.BeginTransaction()) { new SchemaExport(nhConfig).Execute(true, true, false, session.Connection, null); IDomainEvent domainEvent = new CartCreatedDomainEvent() { DomainEventId = Guid.NewGuid().ToString(), DomainEventType = (int)DomainEventTypeConstants.CartCreatedDomainEvent, DomainEventName = "CartCreated", OccurredOn = DateTime.Now, CartId = "test-cart-id" }; RmqPublishMessage msg = new RmqPublishMessage() { MessageId = Guid.NewGuid(), DomainEventType = 0, Sender = "test", OccurredOn = DateTime.Now, Content = JObject.FromObject(domainEvent), DeliveryTag = 1, Status = MessageStatusConstants.Failed }; session.Save(msg); session.Flush(); session.Clear(); RmqPublishMessage found = session.Get <RmqPublishMessage>(msg.MessageId); result = JsonConvert.SerializeObject(found, Formatting.Indented); tx.Commit(); } return(result); }
public ActionResult <IEnumerable <string> > Event() { var nhConfig = new Configuration().Configure(); var sessionFactory = nhConfig.BuildSessionFactory(); using (var session = sessionFactory.OpenSession()) using (var tx = session.BeginTransaction()) { new SchemaExport(nhConfig).Execute(true, true, false, session.Connection, null); IDomainEvent domainEvent = new CartCreatedDomainEvent() { DomainEventId = Guid.NewGuid().ToString(), DomainEventType = (int)DomainEventTypeConstants.CartCreatedDomainEvent, DomainEventName = "CartCreated", OccurredOn = DateTime.Now, CartId = "test-cart-id" }; session.Save(_storedEventTranslator.TranslateToStoredEvent(domainEvent)); tx.Commit(); } return(new string[] { "value1", "value2" }); }