public static string ConfigureSwitchExpression(ConfigureSwitchExpressionMessage args) { OldSwitchValue = string.Empty; var expression = ConfigureActivity <DsfFlowSwitchActivity>(args.ModelItem, GlobalConstants.SwitchExpressionPropertyText, args.IsNew); if (expression == null) { return(null); } var expressionText = expression.Properties[GlobalConstants.SwitchExpressionTextPropertyText]; var modelProperty = args.ModelItem.Properties[GlobalConstants.DisplayNamePropertyText]; if (modelProperty?.Value != null) { _callBackHandler = StartSwitchDropWizard(expression, modelProperty.Value.ToString()); } if (_callBackHandler != null) { try { var modelData = _callBackHandler.ModelData; var resultSwitch = JsonConvert.DeserializeObject <Dev2Switch>(modelData); var expr = ActivityHelper.InjectExpression(resultSwitch, expressionText); ActivityHelper.SetDisplayName(args.ModelItem, resultSwitch); // MUST use args.ModelItem otherwise it won't be visible! return(expr); } catch { PopupController.Show(GlobalConstants.SwitchWizardErrorString, GlobalConstants.SwitchWizardErrorHeading, MessageBoxButton.OK, MessageBoxImage.Error, null, false, true, false, false, false, false); } } return(null); }
public void ConfigureSwitchExpression(ConfigureSwitchExpressionMessage args) { var expression = ConfigureActivity <DsfFlowSwitchActivity>(args.ModelItem, GlobalConstants.SwitchExpressionPropertyText, args.IsNew); if (expression == null) { return; } var expressionText = expression.Properties[GlobalConstants.SwitchExpressionTextPropertyText]; Dev2Switch ds; if (expressionText != null && expressionText.Value != null) { ds = new Dev2Switch(); var val = ActivityHelper.ExtractData(expressionText.Value.ToString()); if (!string.IsNullOrEmpty(val)) { ds.SwitchVariable = val; } } else { ds = DataListConstants.DefaultSwitch; } var displayName = args.ModelItem.Properties[GlobalConstants.DisplayNamePropertyText]; if (displayName != null && displayName.Value != null) { ds.DisplayText = displayName.Value.ToString(); } var webModel = JsonConvert.SerializeObject(ds); // now invoke the wizard ;) _callBackHandler = StartSwitchDropWizard(args.EnvironmentModel, webModel); // Wizard finished... // Now Fetch from DL and push the model data into the workflow try { var resultSwitch = JsonConvert.DeserializeObject <Dev2Switch>(_callBackHandler.ModelData); ActivityHelper.InjectExpression(resultSwitch, expressionText); // PBI 9220 - 2013.04.29 - TWR ActivityHelper.SetDisplayName(args.ModelItem, resultSwitch); // MUST use args.ModelItem otherwise it won't be visible! } catch { _popupController.Show(GlobalConstants.SwitchWizardErrorString, GlobalConstants.SwitchWizardErrorHeading, MessageBoxButton.OK, MessageBoxImage.Error, null); } }
public void Handle(ConfigureSwitchExpressionMessage message) { ConfigureSwitchExpression(message); }
public void FlowController_ConfigureSwitch_Handle_Switch() { //------------Setup for test-------------------------- var popupController = new Mock <IPopupController>(); CustomContainer.Register(popupController.Object); var env = EnviromentRepositoryTest.CreateMockEnvironment(); var properties = new Dictionary <string, Mock <ModelProperty> >(); var propertyCollection = new Mock <ModelPropertyCollection>(); var testAct = new DsfFlowSwitchActivity { ExpressionText = "" }; var prop = new Mock <ModelProperty>(); prop.Setup(p => p.ComputedValue).Returns(testAct); properties.Add("Expression", prop); propertyCollection.Protected().Setup <ModelProperty>("Find", "Expression", true).Returns(prop.Object); var source = new Mock <ModelItem>(); source.Setup(s => s.Properties).Returns(propertyCollection.Object); #region setup decision Mock ModelItem var crmSwitch = new Mock <IContextualResourceModel>(); crmSwitch.Setup(r => r.Environment).Returns(env.Object); crmSwitch.Setup(r => r.ResourceName).Returns("Test"); crmSwitch.Setup(res => res.WorkflowXaml).Returns(new StringBuilder(StringResourcesTest.xmlServiceDefinition)); var switchProperties = new Dictionary <string, Mock <ModelProperty> >(); var switchPropertyCollection = new Mock <ModelPropertyCollection>(); var switchProp = new Mock <ModelProperty>(); switchProp.Setup(p => p.ComputedValue).Returns(string.Empty); switchProperties.Add("Expression", switchProp); switchPropertyCollection.Protected().Setup <ModelProperty>("Find", "Expression", true).Returns(switchProp.Object); var switchModelItem = new Mock <ModelItem>(); switchModelItem.Setup(s => s.Properties).Returns(switchPropertyCollection.Object); switchModelItem.Setup(s => s.ItemType).Returns(typeof(FlowSwitch <string>)); prop.Setup(p => p.Value).Returns(switchModelItem.Object); #endregion #region setup Environment Model env.Setup(c => c.Connection).Returns(new Mock <IEnvironmentConnection>().Object); #endregion var flowController = new FlowController(); var message = new ConfigureSwitchExpressionMessage { ModelItem = source.Object, Server = env.Object, IsNew = true }; //------------Execute Test--------------------------- flowController.Handle(message); //------------Assert Results------------------------- }