// IHttpAsyncHandler members
            public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback asyncCallback, object extraData)
            {
                IAsyncResult result = null;
                // Get the controller type
                string controllerName = _requestContext.RouteData.GetRequiredString("controller");

                // Obtain an instance of the controller
                _factory = ControllerBuilder.Current.GetControllerFactory();
                var controller = _factory.CreateController(_requestContext, controllerName) as ControllerBase;
                if (controller == null)
                  throw new InvalidOperationException("Can't locate the controller " + controllerName);

                try
                {
                  _asyncController = controller as AsyncController;
                  if (_asyncController == null)
                throw new InvalidOperationException("Controller isn't an AsyncController.");

                  // Set up asynchronous processing
                  _httpContext = HttpContext.Current; // Save this for later

                  result = _asyncController.Execute(_requestContext, asyncCallback);
                }
                finally
                {
                  if (result == null || result.CompletedSynchronously)
                  {
                this._factory.ReleaseController(controller);
                  }
                }

                return result;
            }
Example #2
0
        public void ExecuteCallsInitialize()
        {
            // Arrange
            RequestContext  requestContext = new RequestContext(new Mock <HttpContextBase>().Object, new RouteData());
            MockAsyncResult asyncResult    = new MockAsyncResult();

            Mock <AsyncController> mockController = new Mock <AsyncController>()
            {
                CallBase = true
            };

            mockController.Expect(c => c.BeginExecuteCore(It.IsAny <AsyncCallback>(), It.IsAny <object>())).Returns(asyncResult).Verifiable();
            mockController.Expect(c => c.EndExecuteCore(asyncResult)).Verifiable();

            AsyncController  controller  = mockController.Object;
            IAsyncController iController = controller;

            // Act
            IAsyncResult returnedAsyncResult = iController.BeginExecute(requestContext, null, null);

            iController.EndExecute(returnedAsyncResult);

            // Assert
            Assert.AreEqual(requestContext, controller.ControllerContext.RequestContext);
            mockController.Verify();
        }
Example #3
0
 public CrystalResportViewPDF(string reportName, string usuario, string password, AsyncController controller)
 {
     _controller = controller;
     Reporte     = new ReportDocument();
     Reporte.SetDatabaseLogon(usuario, password);
     if (reportName != null)
     {
         ruta = GetRutaReporteByName(reportName);
         Reporte.Load(ruta);
     }
 }
Example #4
0
 public CrystalResportViewPDF(string reportName, AsyncController controller)
 {
     _controller = controller;
     Reporte     = new ReportDocument();
     if (reportName != null)
     {
         ruta = GetRutaReporteByName(reportName);
         Reporte.Load(ruta);
         Reporte.SetDatabaseLogon(WebConfigurationManager.AppSettings["UsuarioReporte"].ToString(), WebConfigurationManager.AppSettings["ClaveUsuarioReporte"].ToString());
     }
 }
Example #5
0
        /// <summary>
        /// Extension metod that helps in unit testing async controllers.
        /// When asynchronous operation is called it blocks current thread until
        /// asynchronous operation is finished with processing.
        /// </summary>
        /// <param name="actionAsync">Asynchronous action</param>
        /// <param name="actionCompleted">Action that should be executed after asynchronous action finishes processing</param>
        public static void ExecuteAsync(this AsyncController asyncController, Action actionAsync, Action actionCompleted)
        {
            var trigger = new AutoResetEvent(false);

            asyncController.AsyncManager.Finished += (sender, ev) =>
            {
                actionCompleted();
                trigger.Set();
            };
            actionAsync();
            trigger.WaitOne();
        }
 public SimpleDefaultMainAction(AbstractController controller, AsyncController.AsyncDelegate main)
     : base(controller)
 {
     _background = main;
 }
 public SimpleWindowMainAction(AsyncController.AsyncDelegate main, WindowController c)
     : base(c)
 {
     _main = main;
 }
Example #8
0
 public void Setup()
 {
     _controller = new AsyncController();
 }
Example #9
0
        public void ShouldSetActionInvoker()
        {
            var controller = new AsyncController();

            Assert.IsInstanceOf <AsyncActionInvoker>(controller.ActionInvoker);
        }