private DestinationNode ToExpressionNode(DestinationFieldList destination)
        {
            var destinationNode = new DestinationNode();

            foreach (var field in destination.Fields)
            {

                if (field.ConnectorIn.Connection == null)
                    continue;

                if (field.ConnectorIn.Connection.Source == null)
                    continue;

                var resultNode = new ResultNode
                                     {
                                         FieldName = field.Name,
                                         Expression =
                                             ToExpressionNode(
                                                 field.ConnectorIn.Connection.Source.Connection.Source.Owner,
                                                 field.ConnectorIn.Connection.Source.Connection
                                             )
                                     };

                destinationNode.ResultNodes.Add(resultNode);
            }

            return destinationNode;
        }
        public void CreateDestinationNodeShouldReturnDestinationNode()
        {
            var obj = new ExpressionNodeFactory();

            var destination = new DestinationFieldList { UniqueName = "Destination" };
            destination.Fields.Add(new DestinationField(destination));
            var source = new ConstantExpression();
            var connection = new Connection { Source = source.ConnectorOut, Sink = destination.Fields[0].ConnectorIn };

            var objects = new List<IExpressionObjectBase>
                              {   
                                  source,
                                  destination,
                                  connection
                              };

            Assert.IsNotNull(obj.CreateDestinationNode(objects, "Destination"));
        }
        public void AddDestinationVersionFieldsTest()
        {
            // Arrange.
            var vm = new ExpressionDesignerWindowViewModelBase();
            var accessor = new PrivateAccessor(vm);

            var processInfo = Mock.Create<PublishedProcessInfo>();
            Mock.Arrange(() => processInfo.ProcessOption).Returns(ProcessOption.VersionEnabled);

            var destination = new DestinationFieldList();

            // Act.
            accessor.CallMethod("AddVersionFields", processInfo, destination);

            // Assert.
            Assert.AreEqual(3, destination.Fields.Count);

            var versionNumber = destination.Fields.FirstOrDefault(f => f.SystemName == Constants.VersionNumber);
            var versionDate = destination.Fields.FirstOrDefault(f => f.SystemName == Constants.VersionDate);
            var versionMasterId = destination.Fields.FirstOrDefault(f => f.SystemName == Constants.VersionMasterId);

            Assert.IsNotNull(versionNumber);
            Debug.Assert(versionNumber != null, "versionNumber != null");
            Assert.AreEqual(NodeDataType.String, versionNumber.DataType);
            Assert.AreEqual(Constants.VersionNumberName, versionNumber.Name);
            Assert.AreEqual(Constants.VersionNumber, versionNumber.InnerName);
            Assert.AreEqual(Constants.VersionNumber, versionNumber.SystemName);

            Assert.IsNotNull(versionDate);
            Debug.Assert(versionDate != null, "versionDate != null");
            Assert.AreEqual(NodeDataType.DateTime, versionDate.DataType);
            Assert.AreEqual("Version Date", versionDate.Name);
            Assert.AreEqual(Constants.VersionDate, versionDate.InnerName);
            Assert.AreEqual(Constants.VersionDate, versionDate.SystemName);

            Assert.IsNotNull(versionMasterId);
            Debug.Assert(versionMasterId != null, "versionMasterId != null");
            Assert.AreEqual(NodeDataType.Int, versionMasterId.DataType);
            Assert.AreEqual("Version Master Id", versionMasterId.Name);
            Assert.AreEqual(Constants.VersionMasterId, versionMasterId.InnerName);
            Assert.AreEqual(Constants.VersionMasterId, versionMasterId.SystemName);
        }
        /// <summary>
        /// Converts to source.
        /// </summary>
        /// <param name="sourceType">Type of the source.</param>
        /// <returns>DestinationFieldList.</returns>
        public static DestinationFieldList ConvertToSource(Type sourceType)
        {
            var result = new DestinationFieldList {ExpressionName = sourceType.Name};

            var properties = sourceType.GetProperties();

            foreach (var property in properties)
            {
                var dn = new DestinationField(result)
                             {
                                 Name = property.Name,
                                 DataType = GetDataType(property.PropertyType),
                                 ConnectorIn = {DataType = GetDataType(property.PropertyType), Name = property.Name}
                             };
                dn.Id = dn.ConnectorIn.Id;
                result.Fields.Add(dn);
            }

            return result;
        }
        public void ToExpressionNode_SetChecklistData_Test()
        {
            // Arrange.
            var nodeFactory = new ExpressionNodeFactory();
            var connection1 = new Connection();
            connection1.Source = new ConnectorOut(connection1);
            connection1.Sink = new ConnectorIn(connection1);

            var connection2 = new Connection();
            connection2.Source = new ConnectorOut(connection2);
            connection2.Sink = new ConnectorIn(connection2);

            var connection3 = new Connection();
            connection3.Source = new ConnectorOut(connection3);
            connection3.Sink = new ConnectorIn(connection3);

            var destination = new DestinationFieldList { UniqueName = "Destination" };
            destination.Fields.Add(new DestinationField(destination));
            destination.Fields.Add(new DestinationField(destination));
            var source = new SourceFieldList();
            source.Fields.Add(new SourceField(source) { Name = "Field" });

            var func = new SetChecklistDataExpression { UniqueName = "Function" };

            func.ConnectorIn.Id = connection1.Sink.Id;
            source.Fields[0].ConnectorOut.Id = connection1.Source.Id;

            destination.Fields[0].ConnectorIn.Id = connection2.Sink.Id;
            func.Connector1Out.Id = connection2.Source.Id;

            destination.Fields[1].ConnectorIn.Id = connection3.Sink.Id;
            func.Connector2Out.Id = connection3.Source.Id;

            var objects = new List<IExpressionObjectBase> { source, destination, func, connection1, connection2, connection3 };

            // Act.
            var destNode = nodeFactory.CreateExpressionNodes(objects);

            // Assert.
            Assert.IsTrue(destNode.ResultNodes.ElementAt(0).Expression is SetChecklistDataFunctionNode);
            Assert.IsTrue(destNode.ResultNodes.ElementAt(1).Expression is GetContextValueFunctionNode);
        }
        public void RestoreConnectionsShouldConnectSourceToDestAndSinkToSourve()
        {
            var obj = new ExpressionNodeFactory();
            var connection = new Connection();
            connection.Source = new ConnectorOut(connection);
            connection.Sink = new ConnectorIn(connection);

            var destination = new DestinationFieldList { UniqueName = "Destination" };
            destination.Fields.Add(new DestinationField(destination));
            var source = new ConstantExpression();

            destination.Fields[0].ConnectorIn.Id = connection.Source.Id;
            source.ConnectorOut.Id = connection.Sink.Id;

            var objects = new List<IExpressionObjectBase>
                              {   
                                  source,
                                  destination,
                                  connection
                              };

            obj.RestoreConnections(objects);

            Assert.AreSame(destination.Fields[0].ConnectorIn, connection.Sink);
            Assert.AreSame(source.ConnectorOut, connection.Source);
        }
 /// <summary>
 /// Adds state-related system fields.
 /// </summary>
 /// <param name="process">The process.</param>
 /// <param name="destination">The destination field list.</param>
 protected virtual void AddStateFields(IProcessEdit process, DestinationFieldList destination)
 {
     if (process.IsStateEnabled)
         destination.Fields.AddRange(CreateStateFields(destination));
 }
        public void ToExpressionNode_Constant_Test()
        {
            var obj = new ExpressionNodeFactory();

            var connection2 = new Connection();
            connection2.Source = new ConnectorOut(connection2);
            connection2.Sink = new ConnectorIn(connection2);

            var destination = new DestinationFieldList { UniqueName = "Destination" };
            destination.Fields.Add(new DestinationField(destination));
            var func = new ConstantExpression();
            destination.Fields[0].ConnectorIn.Id = connection2.Sink.Id;
            func.ConnectorOut.Id = connection2.Source.Id;

            var objects = new List<IExpressionObjectBase>
                              {   
                                  destination,
                                  func,
                                  connection2
                              };

            var destNode = obj.CreateExpressionNodes(objects);
            Assert.AreEqual(typeof(ConstantNode), destNode.ResultNodes.FirstOrDefault().Expression.GetType());
        }
        public void CheckMultipleDestinationsInAddDestinationNode()
        {
            var obj = new ExpressionNodeFactory();
            var connection1 = new Connection();
            connection1.Source = new ConnectorOut(connection1);
            connection1.Sink = new ConnectorIn(connection1);

            var connection2 = new Connection();
            connection2.Source = new ConnectorOut(connection2);
            connection2.Sink = new ConnectorIn(connection2);

            var destination = new DestinationFieldList { UniqueName = "Destination" };
            destination.Fields.Add(new DestinationField(destination) { SystemName = "Field" });
            destination.Fields[0].Subfields.Add(new DestinationField(destination) { SystemName = "Subfield", ParentField = destination.Fields[0] });

            var source = new SourceFieldList();
            source.Fields.Add(new SourceField(source) { Name = "Field" });

            var func = new OneInOneOutExpression(ExpressionNodeType.Count) { UniqueName = "Function" };

            func.ConnectorIn.Id = connection1.Sink.Id;
            source.Fields[0].ConnectorOut.Id = connection1.Source.Id;

            ((DestinationField)destination.Fields[0].Subfields[0]).ConnectorIn.Id = connection2.Sink.Id;
            func.ConnectorOut.Id = connection2.Source.Id;

            var objects = new List<IExpressionObjectBase>
                              {   
                                  source,
                                  destination,
                                  func,
                                  connection1,
                                  connection2
                              };

            var destNode = obj.CreateExpressionNodes(objects);

            Assert.AreEqual("Field.Subfield", destNode.ResultNodes.ToArray()[0].FieldName);
        }
 /// <summary>
 /// Adds version-related system fields.
 /// </summary>
 /// <param name="process">The process.</param>
 /// <param name="destination">The destination field list.</param>
 protected virtual void AddVersionFields(IProcessEdit process, DestinationFieldList destination)
 {
     if (process.ProcessOptionChoose == ProcessOption.VersionEnabled)
         destination.Fields.AddRange(CreateVersionFields(destination));
 }
        public void AddDestinationStateFieldsFromPublishedProcessInfoTest()
        {
            // Arrange.
            var process1 = Mock.Create<PublishedProcessInfo>();
            Mock.Arrange(() => process1.IsStateEnabled).Returns(false);

            var process2 = Mock.Create<PublishedProcessInfo>();
            Mock.Arrange(() => process2.IsStateEnabled).Returns(true);

            var fields1 = new DestinationFieldList();
            var fields2 = new DestinationFieldList();

            var vm = new ExpressionDesignerWindowViewModelBase();
            var accessor = new PrivateAccessor(vm);

            // Act.
            accessor.CallMethod("AddStateFields", process1, fields1);
            accessor.CallMethod("AddStateFields", process2, fields2);

            // Assert.
            Assert.AreEqual(0, fields1.Fields.Count);
            
            Assert.AreEqual(2, fields2.Fields.Count);

            var currentStateField = fields2.Fields.First(f => f.SystemName == Constants.CurrentStateColumnName);

            Assert.AreEqual(NodeDataType.String, currentStateField.DataType);
            Assert.AreEqual(Constants.CurrentStateDisplayName, currentStateField.Name);
            Assert.AreEqual(Constants.CurrentStateColumnName, currentStateField.SystemName);
            Assert.AreEqual(Constants.CurrentStateColumnName, currentStateField.InnerName);
            Assert.IsTrue(string.IsNullOrEmpty(currentStateField.SetName));

            var stateModifiedOnField = fields2.Fields.First(f => f.SystemName == Constants.StateModifiedColumnName);

            Assert.AreEqual(NodeDataType.DateTime, stateModifiedOnField.DataType);
            Assert.AreEqual(Constants.StateModifiedDisplayName, stateModifiedOnField.Name);
            Assert.AreEqual(Constants.StateModifiedColumnName, stateModifiedOnField.SystemName);
            Assert.AreEqual(Constants.StateModifiedColumnName, stateModifiedOnField.InnerName);
            Assert.IsTrue(string.IsNullOrEmpty(stateModifiedOnField.SetName));
        }
        public void ToSourceExpressionNodeShouldThrowExceptionIdSourceFieldListIsInvalid()
        {
            var obj = new ExpressionNodeFactory();
            var connection = new Connection();
            connection.Source = new ConnectorOut(connection);
            connection.Sink = new ConnectorIn(connection);

            var destination = new DestinationFieldList { UniqueName = "Destination" };
            destination.Fields.Add(new DestinationField(destination));
            var source = new SourceFieldList();
            source.Fields.Add(new SourceField(source) { Name = "Field" });

            destination.Fields[0].ConnectorIn.Id = connection.Sink.Id;
            source.Fields[0].ConnectorOut.Id = connection.Source.Id;

            Mock.Arrange(() => source.IsValid).Returns(true).InSequence().Returns(true).InSequence().Returns(false).InSequence();

            var objects = new List<IExpressionObjectBase>
                              {   
                                  source,
                                  destination,
                                  connection
                              };

            obj.CreateExpressionNodes(objects);
        }
        /// <summary>
        /// The get variable list.
        /// </summary>
        /// <param name="variableList">
        /// The variable list.
        /// </param>
        /// <param name="expressionResult">
        /// The expression result.
        /// </param>
        /// <returns>
        /// The <see cref="DestinationFieldList"/>.
        /// </returns>
        public static DestinationFieldList GetVariableList(IEnumerable<DataVariableEdit> variableList, string expressionResult)
        {
            var destination = new DestinationFieldList
            {
                Top = 200,
                Left = 600,
                ExpressionName = expressionResult
            };

            foreach (var variable in variableList)
            {
                destination.Fields.Add(new DestinationField(destination)
                {
                    Name = variable.VariableName,
                    SystemName = variable.VariableSystemName,
                    InnerName = variable.VariableName,
                    DataType = GetNodeType(variable.VariableDataType),
                    ConnectorIn = { Name = variable.VariableName, DataType = GetNodeType(variable.VariableDataType) }
                });
            }
            return destination;
        }
 /// <summary>
 /// Adds the field node.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <param name="diagramViewModel">The diagram view model.</param>
 private static void AddFieldNode(DestinationFieldList item, IDiagramViewModel diagramViewModel)
 {
     var dfl = new DestinationFieldsExpressionNode(diagramViewModel, item);
     diagramViewModel.Items.Add(new NodeViewModel<DestinationFieldsExpressionNode, ExpressionConnection>(dfl, diagramViewModel));
 }
        /// <summary>
        /// Creates the LastModifiedOn system field.
        /// </summary>
        /// <param name="destination">
        /// The destination.
        /// </param>
        /// <returns>
        /// The LastModifiedOn system field.
        /// </returns>
        protected virtual DestinationField CreateLastModifiedOnField(DestinationFieldList destination)
        {
            const string LastModifiedOnDisplayName = "Last Modified On";

            var dataType = SourceNodeFactory.GetDataType(typeof(DateTime));
            var df = new DestinationField(destination)
                         {
                             DataType = dataType,
                             Name = LastModifiedOnDisplayName,
                             ConnectorIn = { DataType = dataType, Name = Constants.LastModifiedOn },
                             InnerName = Constants.LastModifiedOn,
                             SystemName = Constants.LastModifiedOn
                         };

            return df;
        }
 /// <summary>
 /// The add last modified date field.
 /// </summary>
 /// <param name="process"> The process. </param>
 /// <param name="destination"> The destination. </param>
 protected virtual void AddLastModifiedOnField(IProcessEdit process, DestinationFieldList destination)
 {
     destination.Fields.Add(CreateLastModifiedOnField(destination));
 }
        /// <summary>
        /// Creates version-related system fields.
        /// </summary>
        /// <param name="destination">
        /// The destination field list.
        /// </param>
        /// <returns>
        /// The collection of version-related system fields.
        /// </returns>
        protected virtual IEnumerable<DestinationField> CreateVersionFields(DestinationFieldList destination)
        {
            var dataType = SourceNodeFactory.GetDataType(typeof(string));
            var df = new DestinationField(destination)
                         {
                             DataType = dataType,
                         Name = Constants.VersionNumberName,
                         ConnectorIn = { DataType = dataType, Name = Constants.VersionNumberName, IsNullable = false },
                             InnerName = Constants.VersionNumber,
                             SystemName = Constants.VersionNumber
                         };

            yield return df;

            dataType = SourceNodeFactory.GetDataType(typeof(DateTime));
            df = new DestinationField(destination)
                     {
                         DataType = dataType,
                         Name = VersionDateDisplayName,
                         ConnectorIn = { DataType = dataType, Name = VersionDateDisplayName },
                         InnerName = Constants.VersionDate,
                         SystemName = Constants.VersionDate
                     };

            yield return df;

            dataType = SourceNodeFactory.GetDataType(typeof(int));
            df = new DestinationField(destination)
                     {
                         DataType = dataType,
                         Name = VersionMasterIdDisplayName,
                         ConnectorIn = { DataType = dataType, Name = VersionMasterIdDisplayName, IsNullable = false },
                         InnerName = Constants.VersionMasterId,
                         SystemName = Constants.VersionMasterId
                     };

            yield return df;
        }
        private void ToExpressionNodeThreeInOneOutFunctionTest(ExpressionNodeType nodeType, Type functionNode)
        {
            var obj = new ExpressionNodeFactory();
            var connection1 = new Connection();
            connection1.Source = new ConnectorOut(connection1);
            connection1.Sink = new ConnectorIn(connection1);

            var connection2 = new Connection();
            connection2.Source = new ConnectorOut(connection2);
            connection2.Sink = new ConnectorIn(connection2);

            var connection3 = new Connection();
            connection3.Source = new ConnectorOut(connection3);
            connection3.Sink = new ConnectorIn(connection3);

            var connection4 = new Connection();
            connection4.Source = new ConnectorOut(connection4);
            connection4.Sink = new ConnectorIn(connection4);

            var destination = new DestinationFieldList { UniqueName = "Destination" };
            destination.Fields.Add(new DestinationField(destination));
            var source = new SourceFieldList();
            source.Fields.Add(new SourceField(source) { Name = "Field" });
            source.Fields.Add(new SourceField(source) { Name = "Field" });
            source.Fields.Add(new SourceField(source) { Name = "Field" });

            var func = new ThreeInOneOutExpression(nodeType) { UniqueName = "Function" };

            func.Connector1In.Id = connection1.Sink.Id;
            source.Fields[0].ConnectorOut.Id = connection1.Source.Id;
            func.Connector2In.Id = connection2.Sink.Id;
            source.Fields[1].ConnectorOut.Id = connection2.Source.Id;
            func.Connector3In.Id = connection3.Sink.Id;
            source.Fields[2].ConnectorOut.Id = connection3.Source.Id;

            destination.Fields[0].ConnectorIn.Id = connection4.Sink.Id;
            func.ConnectorOut.Id = connection4.Source.Id;

            var objects = new List<IExpressionObjectBase>
                              {   
                                  source,
                                  destination,
                                  func,
                                  connection1,
                                  connection2,
                                  connection3,
                                  connection4
                              };

            var destNode = obj.CreateExpressionNodes(objects);
            Assert.AreEqual(functionNode, destNode.ResultNodes.FirstOrDefault().Expression.GetType());
        }
        /// <summary>
        /// Creates the destination item.
        /// </summary>
        /// <returns>DestinationFieldList.</returns>
        private static DestinationFieldList CreateDestinationItem()
        {
            var result = new DestinationFieldList
                {
                    ExpressionName = "Expression Result",
                    Top = 200,
                    Left = 600,
                    UniqueName = DestinationItemName
                };

            result.Fields.Add(
                new DestinationField(result)
                {
                    Name = "Result",
                    SystemName = "Result",
                    InnerName = "Result",
                    DataType = NodeDataType.Boolean,
                    ConnectorIn = { Name = "Result", DataType = NodeDataType.Boolean }
                });

            return result;
        }
        /// <summary>
        /// Adds the 'Id' field to the specified <see cref="DestinationFieldList" />.
        /// </summary>
        /// <param name="destination">The destination.</param>
        /// <exception cref="System.ArgumentNullException">destination</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="destination" /> parameter is null.</exception>
        protected virtual void AddIdField(DestinationFieldList destination)
        {
            if (destination == null)
                throw new ArgumentNullException("destination");

            var dataType = DestinationNodeFactory.GetDataType(typeof(int));

            var df = new DestinationField(destination)
                         {
                             Name = "Id",
                             SystemName = Constants.IdColumnName,
                             DataType = dataType,
                             ConnectorIn = { DataType = dataType, Name = "Id", IsNullable = false },
                             IsKeyEnabled = true,
                             IsKeyVisible = true
                         };

            destination.Fields.Add(df);
        }
        public void ToSourceExpressionNodeShouldReturnFieldWithValue()
        {
            var obj = new ExpressionNodeFactory();
            var connection = new Connection();
            connection.Source = new ConnectorOut(connection);
            connection.Sink = new ConnectorIn(connection);

            var destination = new DestinationFieldList { UniqueName = "Destination" };
            destination.Fields.Add(new DestinationField(destination));
            var source = new SourceFieldList();
            source.Fields.Add(new SourceField(source) { Name = "Field" });

            destination.Fields[0].ConnectorIn.Id = connection.Sink.Id;
            source.Fields[0].ConnectorOut.Id = connection.Source.Id;

            var objects = new List<IExpressionObjectBase>
                              {   
                                  source,
                                  destination,
                                  connection
                              };

            var destNode = obj.CreateExpressionNodes(objects, new Dictionary<string, object> { { "Field", "Value" } });
            var sourceNode = destNode.ResultNodes.FirstOrDefault().Expression as SourceFieldNode;

            Assert.AreEqual("Field", sourceNode.FieldName);
            Assert.AreEqual("Value", sourceNode.Value);
        }
        /// <summary>
        /// Creates state-related system fields.
        /// </summary>
        /// <param name="destination">
        /// The destination field list.
        /// </param>
        /// <returns>
        /// The collection of state-related system fields.
        /// </returns>
        protected virtual IEnumerable<DestinationField> CreateStateFields(DestinationFieldList destination)
        {
            var dataType = SourceNodeFactory.GetDataType(typeof(string));
            var df = new DestinationField(destination)
                         {
                             DataType = dataType,
                             Name = Constants.CurrentStateDisplayName,
                             ConnectorIn = { DataType = dataType, Name = Constants.CurrentStateDisplayName, IsNullable = false },
                             InnerName = Constants.CurrentStateColumnName,
                             SystemName = Constants.CurrentStateColumnName
                         };

            yield return df;

            dataType = SourceNodeFactory.GetDataType(typeof(DateTime));
            df = new DestinationField(destination)
                     {
                         DataType = dataType,
                         Name = Constants.StateModifiedDisplayName,
                         ConnectorIn = { DataType = dataType, Name = Constants.StateModifiedDisplayName },
                         InnerName = Constants.StateModifiedColumnName,
                         SystemName = Constants.StateModifiedColumnName
                     };

            yield return df;
        }
        public void CustomFunctionNodeTest()
        {
            var obj = new ExpressionNodeFactory();
            var connection = new Connection();
            connection.Source = new ConnectorOut(connection);
            connection.Sink = new ConnectorIn(connection);

            var destination = new DestinationFieldList { UniqueName = "Destination" };
            destination.Fields.Add(new DestinationField(destination));
            var source = new FunctionExpression { FunctionName = "Function" };

            destination.Fields[0].ConnectorIn.Id = connection.Sink.Id;
            source.ConnectorOut.Id = connection.Source.Id;

            var objects = new List<IExpressionObjectBase>
                              {   
                                  source,
                                  destination,
                                  connection
                              };

            var destNode = obj.CreateExpressionNodes(objects);
            var sourceNode = destNode.ResultNodes.FirstOrDefault().Expression as CustomFunctionNode;

            Assert.AreEqual("Function", sourceNode.FunctionName);
        }
        private static OneInTwoOutExpression CreateValidExpression()
        {
            var source = new ConstantExpression();
            var destination = new DestinationFieldList();
            var destinationField1 = new DestinationField(destination);
            var destinationField2 = new DestinationField(destination);
            var expression = new OneInTwoOutExpression();
            expression.ConnectorIn.ConnectedTo = source.ConnectorOut;
            expression.Connector1Out.ConnectedTo = destinationField1.ConnectorIn;
            expression.Connector2Out.ConnectedTo = destinationField2.ConnectorIn;

            return expression;
        }