public void Context()
        {
            HttpContext.Current = FakeHttpContextHelper.GetFakeHttpContext();

            var domainEventHandlerFactory = new FakeDomainEventHandlerFactory(domainEvent => _raisedDomainEvent = (TestDomainEvent)domainEvent);

            DomainEvents.Initialize(domainEventHandlerFactory, isDelayedDomainEventHandlingEnabled: true);
            DomainEvents.ResetDelayedEventsStorage();

            var unitOfWorkFactory = IoC.Resolve <IUnitOfWorkFactory>();

            UnitOfWorkHttpModule.Initialize(unitOfWorkFactory);
            var unitOfWorkHttpModule = new UnitOfWorkHttpModule();
            var httpApplication      = new FakeHttpApplication();

            unitOfWorkHttpModule.Init(httpApplication);

            httpApplication.FireBeginRequest();

            try
            {
                _simulateApplicationTransactionWhichThrowsAnException();
            }
            catch
            {
                httpApplication.FireError();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Invokes the middleware operation.
        /// </summary>
        /// <param name="context">HTTP context</param>
        /// <param name="next">Request delegate</param>
        /// <param name="unitOfWork">An instance of unit of work</param>
        /// <returns></returns>
        protected async Task InvokeAsync(HttpContext context, RequestDelegate next, IUnitOfWork unitOfWork)
        {
            if (_getOrHeadRequestPathsWithoutTransaction != null &&
                (context.Request.Method == WebRequestMethods.Http.Get || context.Request.Method == WebRequestMethods.Http.Head) &&
                _getOrHeadRequestPathsWithoutTransaction.Any(x => x.IsMatch(context.Request.Path.Value)))
            {
                await next.Invoke(context).ConfigureAwait(false);

                return;
            }

            unitOfWork.BeginTransaction(_isolationLevel);

            DomainEvents.ResetDelayedEventsStorage();

            try
            {
                await next.Invoke(context).ConfigureAwait(false);

                await unitOfWork.CommitAsync().ConfigureAwait(false);
            }
            catch
            {
                await unitOfWork.RollbackAsync().ConfigureAwait(false);

                throw;
            }

            DomainEvents.RaiseDelayedEvents();
        }
        public void Context()
        {
            var domainEventHandlerFactory = IoC.Resolve <IDomainEventHandlerFactory>();

            DomainEvents.Initialize(domainEventHandlerFactory, isDelayedDomainEventHandlingEnabled: true);

            DomainEvents.ResetDelayedEventsStorage();
        }
Esempio n. 4
0
        private void Application_BeginRequest(Object source, EventArgs e)
        {
            _CheckWasInitialized();

            UnitOfWork = _unitOfWorkFactory.Create();
            UnitOfWork.BeginTransaction(_isolationLevel);

            DomainEvents.ResetDelayedEventsStorage();
        }
Esempio n. 5
0
        private void _InitializeDomainEvents(WindsorContainer ioCContainer, bool isDelayedDomainEventHandlingEnabled)
        {
            var domainEventHandlerFactory = ioCContainer.Resolve <IDomainEventHandlerFactory>();

            DomainEvents.Initialize(domainEventHandlerFactory, isDelayedDomainEventHandlingEnabled: isDelayedDomainEventHandlingEnabled);

            if (isDelayedDomainEventHandlingEnabled)
            {
                DomainEvents.ResetDelayedEventsStorage();
            }
        }
Esempio n. 6
0
        public void Context()
        {
            _raisedDomainEvent = null;

            var domainEventHandlerFactory = new FakeDomainEventHandlerFactory(domainEvent => _raisedDomainEvent = (TestDomainEvent)domainEvent);

            DomainEvents.Initialize(domainEventHandlerFactory, isDelayedDomainEventHandlingEnabled: true);
            DomainEvents.ResetDelayedEventsStorage();

            _entity = new TestEntityWithDomainEvent();


            _entity.BehaviouralMethodWithRaisingDomainEvent();
        }
        public void raising_delayed_domain_event_throws_not_initialized()
        {
            _simulateDomainEventsNotInitialized();
            DomainEvents.ResetDelayedEventsStorage();

            var ex = Should.Throw <InvalidOperationException>(() => new TestEntityWithDomainEvent().BehaviouralMethodWithRaisingDomainEvent());

            ex.Message.ToLower().ShouldContain("DomainEvents.Initialize");


            void _simulateDomainEventsNotInitialized()
            {
                DomainEvents.Initialize(domainEventHandlerFactory: null, isDelayedDomainEventHandlingEnabled: true);
            }
        }
Esempio n. 8
0
        public async Task Context()
        {
            var specification = new TUnitOfWorkMiddlewareSpecification();

            var domainEventHandlerFactory = new FakeDomainEventHandlerFactory(domainEvent => _raisedDomainEvent = (TestDomainEvent)domainEvent);

            DomainEvents.Initialize(domainEventHandlerFactory, isDelayedDomainEventHandlingEnabled: true);
            DomainEvents.ResetDelayedEventsStorage();

            async Task _requestDelegate(HttpContext context)
            {
                _entityRepository = IoC.Resolve <IRepository <TestEntityWithDomainEvent> >();

                _entity = new TestEntityWithDomainEvent();
                _entity.BehaviouralMethodWithRaisingDomainEvent();

                await _entityRepository.SaveAsync(_entity);
            }

            await specification.CreateMiddlewareAndInvokeHandling(_requestDelegate);
        }
        /// <summary>
        /// Invokes the middleware operation.
        /// </summary>
        /// <param name="context">HTTP context</param>
        /// <param name="next">Request delegate</param>
        /// <param name="unitOfWork">An instance of unit of work</param>
        /// <returns></returns>
        protected async Task InvokeAsync(HttpContext context, RequestDelegate next, IUnitOfWork unitOfWork)
        {
            unitOfWork.BeginTransaction(_isolationLevel);

            DomainEvents.ResetDelayedEventsStorage();

            try
            {
                await next.Invoke(context).ConfigureAwait(false);

                await unitOfWork.CommitAsync().ConfigureAwait(false);
            }
            catch
            {
                await unitOfWork.RollbackAsync().ConfigureAwait(false);

                throw;
            }

            DomainEvents.RaiseDelayedEvents();
        }
Esempio n. 10
0
        public void Context()
        {
            var domainEventHandlerFactory = new FakeDomainEventHandlerFactory(domainEvent => _raisedDomainEvent = (TestDomainEvent)domainEvent);

            DomainEvents.Initialize(domainEventHandlerFactory);
            DomainEvents.ResetDelayedEventsStorage();

            var unitOfWorkFactory = IoC.Resolve <IUnitOfWorkFactory>();

            RebusUnitOfWork.Initialize(
                unitOfWorkFactory: unitOfWorkFactory,
                isolationLevel: IsolationLevel.ReadCommitted
                );
            _fakeMessageContext = new FakeMessageContext();
            _unitOfWork         = RebusUnitOfWork.Create(_fakeMessageContext);

            _simulateApplicationTransaction();

            RebusUnitOfWork.Commit(_fakeMessageContext, _unitOfWork);
            RebusUnitOfWork.Cleanup(_fakeMessageContext, _unitOfWork);
        }
        public async Task Context()
        {
            var specification = new TUnitOfWorkMiddlewareSpecification();

            var domainEventHandlerFactory = new FakeDomainEventHandlerFactory(domainEvent => _raisedDomainEvent = (TestDomainEvent)domainEvent);

            DomainEvents.Initialize(domainEventHandlerFactory, isDelayedDomainEventHandlingEnabled: true);
            DomainEvents.ResetDelayedEventsStorage();

            async Task _requestDelegate(HttpContext context)
            {
                _entityRepository = IoC.Resolve <IRepository <TestEntityWithDomainEvent> >();
                _entity           = new TestEntityWithDomainEvent();
                await _entityRepository.SaveAsync(_entity);

                throw new NotSupportedException("test exception");
            }

            try
            {
                await specification.CreateMiddlewareAndInvokeHandling(_requestDelegate);
            }
            catch (NotSupportedException) {}
        }