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();
            }
        }
        public void Context()
        {
            HttpContext.Current = FakeHttpContextHelper.GetFakeHttpContext();

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

            DomainEvents.Initialize(domainEventHandlerFactory);

            _volatileResourceManager = new VolatileResourceManager();

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

            TransactionScopeUnitOfWorkHttpModule.Initialize(
                unitOfWorkFactory: unitOfWorkFactory,
                transactionScopeEnlistmentAction: transactionScope => _volatileResourceManager.EnlistIntoTransactionScope(transactionScope)
                );
            var transactionScopeUnitOfWorkHttpModule = new TransactionScopeUnitOfWorkHttpModule();
            var httpApplication = new FakeHttpApplication();

            transactionScopeUnitOfWorkHttpModule.Init(httpApplication);

            httpApplication.FireBeginRequest();

            _simulateApplicationTransaction();

            httpApplication.FireEndRequest();
        }
        public async Task Context()
        {
            var specification = new TTransactionScopeUnitOfWorkMiddlewareSpecification();

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

            DomainEvents.Initialize(domainEventHandlerFactory);

            _volatileResourceManager = new VolatileResourceManager();

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

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

                await _entityRepository.SaveAsync(_entity);

                _volatileResourceManager.SetMemberValue(23);

                throw new NotSupportedException("test exception");
            }

            try
            {
                await specification.CreateMiddlewareAndInvokeHandling(_requestDelegate, _volatileResourceManager);
            }
            catch (NotSupportedException) {}
        }
Exemplo n.º 4
0
        public async Task Context()
        {
            var domainEventHandlerFactory = new FakeDomainEventHandlerFactory(domainEvent => _raisedDomainEvent = domainEvent as IDomainEvent);

            DomainEvents.Initialize(domainEventHandlerFactory);

            _unitOfWork = new NhibernateUnitOfWork(new CoreDddSharedNhibernateConfigurator());
            _unitOfWork.BeginTransaction();

            var createNewShipCommand = new CreateNewShipCommand
            {
                ShipName  = "ship name",
                Tonnage   = 23.45678m,
                ImoNumber = "IMO 12345"
            };
            var createNewShipCommandHandler = new CreateNewShipCommandHandler(new NhibernateRepository <Ship>(_unitOfWork));

            createNewShipCommandHandler.CommandExecuted += args => _createdShipId = (int)args.Args;
            await createNewShipCommandHandler.ExecuteAsync(createNewShipCommand);

            _unitOfWork.Flush();
            _unitOfWork.Clear();

            _persistedShip = _unitOfWork.Get <Ship>(_createdShipId);
        }
        public void Context()
        {
            var domainEventHandlerFactory = new FakeDomainEventHandlerFactory(domainEvent => _raisedDomainEvent = (TestDomainEvent)domainEvent);

            DomainEvents.Initialize(domainEventHandlerFactory);

            _entity = new TestEntityWithDomainEvent();


            _entity.BehaviouralMethodWithRaisingDomainEvent();
        }
Exemplo 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();
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        public void Context()
        {
            var domainEventHandlerFactory = new FakeDomainEventHandlerFactory(domainEvent => _raisedDomainEvent = (EmailEnqueuedToBeSentDomainEvent)domainEvent);

            DomainEvents.Initialize(domainEventHandlerFactory);

            var template = EmailTemplateBuilder.New.Build();

            _email = new EmailBuilder()
                     .WithEmailTemplate(template)
                     .WithId(EmailId)
                     .Build();
            _recipientOne = new Recipient(ToAddressOne, NameOne);
            _recipientTwo = new Recipient(ToAddressTwo, NameTwo);
            _email.EnqueueEmailToBeSent(FromAddress,
                                        new HashSet <Recipient>
            {
                _recipientOne,
                _recipientTwo
            },
                                        Subject);
        }
        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) {}
        }