Exemple #1
0
        public dynamic Workflow()
        {
            var workflowId  = Request.Form["WorkflowId"];
            var connId      = Request.Form["ConnectionId"];
            var currentUser = _userStore.GetUser(this.Context.CurrentUser.UserName);

            // get the connection and load the workflow store
            ConnectionModel connection = _userStore.GetConnection(connId);
            IWorkflowStore  store      = _workflowStoreFactory.GetWorkflowStore(connection);

            // extract the data we need to display the workflow
            string json = store.GetWorkflowAsJson(workflowId);

            if (json == null)
            {
                return(this.Response.AsJson(new { Message = "No workflow found matching the supplied workflow and connection (the workflow may have completed)." }, HttpStatusCode.NotFound));
            }
            UIWorkflow wf = _workflowInfoService.GetWorkflowInfoFromJson(json, connection.WorkflowStoreType);

            WorkflowViewModel viewModel = new WorkflowViewModel();

            viewModel.WorkflowJson = json;
            viewModel.IsSuspended  = wf.IsSuspended;
            return(this.Response.AsJson(viewModel));
        }
Exemple #2
0
        public void Workflow_WorkflowFound_SetsModelAndReturnsView()
        {
            // setup
            var currentUser = new UserIdentity()
            {
                Id = Guid.NewGuid(), UserName = "******"
            };
            var        browser      = CreateBrowser(currentUser);
            var        workflowId   = Guid.NewGuid();
            var        connectionId = Guid.NewGuid();
            UIWorkflow uiWorkflow   = new UIWorkflow();

            uiWorkflow.IsSuspended = DateTime.Now.Second > 30;

            ConnectionModel connection = new ConnectionModel()
            {
                Id   = connectionId,
                Host = "myserver",
                WorkflowStoreType = WorkflowStoreType.MongoDb
            };

            _userStore.GetConnection(connectionId).Returns(connection);

            string json = JsonConvert.SerializeObject(uiWorkflow);

            IWorkflowStore workflowStore = Substitute.For <IWorkflowStore>();

            _workflowStoreFactory.GetWorkflowStore(connection).Returns(workflowStore);
            workflowStore.GetWorkflowAsJson(workflowId).Returns(json);

            _workflowInfoService.GetWorkflowInfoFromJson(json, WorkflowStoreType.MongoDb).Returns(uiWorkflow);

            // execute
            var response = browser.Post(Actions.Store.Workflow, (with) =>
            {
                with.HttpRequest();
                with.FormsAuth(currentUser.Id, new Nancy.Authentication.Forms.FormsAuthenticationConfiguration());
                with.FormValue("WorkflowId", workflowId.ToString());
                with.FormValue("ConnectionId", connectionId.ToString());
            });

            // assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual("application/json; charset=utf-8", response.ContentType);

            WorkflowViewModel wvm = JsonConvert.DeserializeObject <WorkflowViewModel>(response.Body.AsString());

            Assert.IsNotNull(wvm);
            Assert.AreEqual(json, wvm.WorkflowJson);
            Assert.AreEqual(uiWorkflow.IsSuspended, wvm.IsSuspended);
        }