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) {}
        }
        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();
        }
Exemple #3
0
        private static void TestNonScopedExcecution()
        {
            Console.WriteLine("Execution without transaction");

            VolatileResourceManager volatileResourceManager = new VolatileResourceManager();
            S3BucketResourceManager s3BucketResourceManager = new S3BucketResourceManager("upload-bucket");

            volatileResourceManager.SetProperty(3);
            s3BucketResourceManager.UploadImage("image.jpg");

            Console.WriteLine($"VolatileResourceManager Property Value: {volatileResourceManager.Property}");
        }
 private void PrivateInitialize(System.Workflow.ComponentModel.Activity rootActivity, Guid instanceId, IList <PropertyInfo> outputProperties, System.Workflow.ComponentModel.Activity workflowDefinition)
 {
     this.instanceId             = instanceId;
     this.rootActivity           = rootActivity;
     this.contextActivityMap     = new Dictionary <int, System.Workflow.ComponentModel.Activity>();
     this.scheduler              = new Scheduler(this);
     this.workflowQueuingService = new WorkflowQueuingService(this);
     this.outputProperties       = outputProperties;
     this.resourceManager        = new VolatileResourceManager();
     this.rootActivity.SetValue(System.Workflow.ComponentModel.Activity.WorkflowDefinitionProperty, workflowDefinition);
     this.rootActivity.SetValue(WorkflowExecutor.WorkflowExecutorProperty, this);
 }
Exemple #5
0
        private static void TestScopeAborted()
        {
            Console.WriteLine("Transaction scope aborting without Complete()");

            VolatileResourceManager volatileResourceManager = new VolatileResourceManager();
            S3BucketResourceManager s3BucketResourceManager = new S3BucketResourceManager("upload-bucket");

            using (TransactionScope transactionScope = new TransactionScope())
            {
                volatileResourceManager.SetProperty(3);
                s3BucketResourceManager.UploadImage("image.jpg");
            }

            Console.WriteLine($"VolatileResourceManager Property Value: {volatileResourceManager.Property}");
        }
        public async Task CreateMiddlewareAndInvokeHandling(
            RequestDelegate requestDelegate,
            VolatileResourceManager volatileResourceManager
            )
        {
            var transactionScopeUnitOfWorkMiddleware = new TransactionScopeUnitOfWorkDependencyInjectionMiddleware(
                requestDelegate,
                transactionScopeEnlistmentAction: volatileResourceManager.EnlistIntoTransactionScope
                );

            var httpContext = new DefaultHttpContext();
            var unitOfWork  = IoC.Resolve <IUnitOfWork>();

            await transactionScopeUnitOfWorkMiddleware.InvokeAsync(httpContext, unitOfWork);
        }
Exemple #7
0
 public void AddResourceManager(VolatileResourceManager resourceManager)
 {
     this.Activity.AddResourceManager(this.nativeActivityContext, resourceManager);
 }