IContextualResourceModel CreateComplexItemModelResourceModel(bool isConnected = true)
        {
            var moqModel = new Mock <IContextualResourceModel>();

            moqModel.SetupAllProperties();
            moqModel.Setup(model => model.DisplayName).Returns("My WF");
            moqModel.Setup(model => model.Environment.Connection.IsConnected).Returns(isConnected);
            moqModel.Setup(model => model.Environment.IsConnected).Returns(isConnected);
            moqModel.Setup(model => model.Environment.Connection.WebServerUri).Returns(new Uri("http://rsaklf/bob"));
            moqModel.Setup(model => model.Category).Returns("My WF");
            moqModel.Setup(model => model.Environment.IsLocalHost).Returns(isConnected);
            moqModel.Setup(model => model.ResourceName).Returns("My WF");
            var dataListViewModel = new DataListViewModel();

            dataListViewModel.InitializeDataListViewModel(moqModel.Object);

            var complexObject = new ComplexObjectItemModel("Person", null, enDev2ColumnArgumentDirection.Input);

            complexObject.Children.Add(new ComplexObjectItemModel("Name", complexObject, enDev2ColumnArgumentDirection.Input));
            complexObject.Children.Add(new ComplexObjectItemModel("Surname", complexObject, enDev2ColumnArgumentDirection.Input));
            dataListViewModel.Add(complexObject);

            dataListViewModel.WriteToResourceModel();
            return(moqModel.Object);
        }
        void AddComplexObjectFromXmlNode(XmlNode c, ComplexObjectItemModel parent)
        {
            var isArray     = false;
            var ioDirection = enDev2ColumnArgumentDirection.None;

            if (c.Attributes != null)
            {
                isArray     = ParseBoolAttribute(c.Attributes["IsArray"]);
                ioDirection = ParseColumnIODirection(c.Attributes[GlobalConstants.DataListIoColDirection]);
            }
            var name = GetNameForArrayComplexObject(c, isArray);
            var complexObjectItemModel = new ComplexObjectItemModel(name)
            {
                IsArray = isArray, Parent = parent, ColumnIODirection = ioDirection
            };

            if (parent != null)
            {
                parent.Children.Add(complexObjectItemModel);
            }
            else
            {
                _complexObjects.Add(complexObjectItemModel);
            }
            if (c.HasChildNodes)
            {
                var children = c.ChildNodes;
                foreach (XmlNode childNode in children)
                {
                    AddComplexObjectFromXmlNode(childNode, complexObjectItemModel);
                }
            }
        }
示例#3
0
        public void GenerateComplexObjectFromJson(string parentObjectName, string json)
        {
            if (parentObjectName.Contains("."))
            {
                parentObjectName = parentObjectName.Split('.')[0];
            }

            var parentObj = _vm.ComplexObjectCollection.FirstOrDefault(model => model.Name == parentObjectName);

            if (parentObj == null)
            {
                parentObj = new ComplexObjectItemModel(parentObjectName);
                _vm.Add(parentObj);
            }

            if (json.IsXml())
            {
                var xDocument = XDocument.Parse(json);
                json = JsonConvert.SerializeXNode(xDocument, Newtonsoft.Json.Formatting.Indented, true);
            }

            if (JsonConvert.DeserializeObject(json) is JObject objToProcess)
            {
                ProcessObjectForComplexObjectCollection(parentObj, objToProcess);
            }
            else
            {
                if (JsonConvert.DeserializeObject(json) is JArray arrToProcess)
                {
                    var child = arrToProcess.Children().FirstOrDefault();
                    ProcessObjectForComplexObjectCollection(parentObj, child as JObject);
                }
            }
        }
        public void AddComplexObject(IDataListVerifyPart part)
        {
            var paths = part.DisplayValue.Split('.');
            IComplexObjectItemModel itemModel = null;

            for (var index = 0; index < paths.Length; index++)
            {
                var path = paths[index];
                if (string.IsNullOrEmpty(path) || char.IsNumber(path[0]))
                {
                    return;
                }
                path = DataListUtil.ReplaceRecordsetIndexWithBlank(path);
                var pathToMatch = path.Replace("@", "");
                if (string.IsNullOrEmpty(pathToMatch) || pathToMatch == "()")
                {
                    return;
                }

                var isArray = DataListUtil.IsArray(ref path);

                if (itemModel == null)
                {
                    itemModel =
                        _vm.ComplexObjectCollection.FirstOrDefault(
                            model => model.DisplayName == pathToMatch && model.IsArray == isArray);
                    if (itemModel != null)
                    {
                        continue;
                    }
                    itemModel = new ComplexObjectItemModel(path)
                    {
                        IsArray = isArray
                    };
                    _vm.ComplexObjectCollection.Add(itemModel);
                }
                else
                {
                    if (index == 0)
                    {
                        continue;
                    }
                    var item =
                        itemModel.Children.FirstOrDefault(
                            model => model.DisplayName == pathToMatch && model.IsArray == isArray);
                    if (item == null)
                    {
                        item = new ComplexObjectItemModel(path)
                        {
                            Parent = itemModel, IsArray = isArray
                        };
                        itemModel.Children.Add(item);
                    }
                    itemModel = item;
                }
            }
        }
        public void ComplexObjectItemModel_ValidateNames_WithInvalidComplexObjectParentNameWithDot_ShouldHaveError()
        {
            //------------Setup for test--------------------------
            var complexObject = new ComplexObjectItemModel("Parent.");

            //------------Execute Test---------------------------

            //------------Assert Results-------------------------
            Assert.IsTrue(complexObject.HasError);
            Assert.AreEqual("Complex Object name [[Parent.]] contains invalid character(s). Only use alphanumeric _ and - ", complexObject.ErrorMessage);
        }
        public void ComplexObjectItemModel_Children_GetWhenNotSet_ShouldReturnNewCollection()
        {
            //------------Setup for test--------------------------
            var complexObjectItemModel = new ComplexObjectItemModel("TestItem");

            //------------Execute Test---------------------------
            var children = complexObjectItemModel.Children;

            //------------Assert Results-------------------------
            Assert.IsNotNull(children);
            Assert.AreEqual(0, children.Count);
        }
        public void ComplexObjectItemModel_Parent_Set_ShouldUpdateNameIsParentObject()
        {
            //------------Setup for test--------------------------
            var complexObjectItemModel = new ComplexObjectItemModel("TestItem");

            //------------Execute Test---------------------------
            complexObjectItemModel.Parent = new ComplexObjectItemModel("ParentItem");
            //------------Assert Results-------------------------
            Assert.IsNotNull(complexObjectItemModel.Parent);
            Assert.AreEqual("@ParentItem.TestItem", complexObjectItemModel.Name);
            Assert.AreEqual("TestItem", complexObjectItemModel.DisplayName);
            Assert.IsFalse(complexObjectItemModel.IsParentObject);
        }
        public void ComplexObjectItemModel_GetJson_PrimitiveChildren_ShouldReturnCorrectJson()
        {
            //------------Setup for test--------------------------
            var complexObject = new ComplexObjectItemModel("Parent");

            complexObject.Children.Add(new ComplexObjectItemModel("Name", complexObject));
            complexObject.Children.Add(new ComplexObjectItemModel("Age", complexObject));
            complexObject.Children.Add(new ComplexObjectItemModel("Gender", complexObject));
            //------------Execute Test---------------------------
            var jsonString = complexObject.GetJson();

            //------------Assert Results-------------------------
            Assert.AreEqual("{\"Parent\":{\"Name\":\"\",\"Age\":\"\",\"Gender\":\"\"}}", jsonString);
        }
        public void ComplexObjectItemModel_Children_GetWhenSet_ShouldReturnSetCollection()
        {
            //------------Setup for test--------------------------
            var complexObjectItemModel = new ComplexObjectItemModel("TestItem");

            //------------Execute Test---------------------------
            complexObjectItemModel.Children = new ObservableCollection <IComplexObjectItemModel> {
                new ComplexObjectItemModel("TestChild")
            };
            var children = complexObjectItemModel.Children;

            //------------Assert Results-------------------------
            Assert.IsNotNull(children);
            Assert.AreEqual(1, children.Count);
        }
        public void ComplexObjectItemModel_ValidateNames_WithValidComplexObject_IsUsed()
        {
            //------------Setup for test--------------------------
            var complexObject = new ComplexObjectItemModel("Parent");

            complexObject.Children.Add(new ComplexObjectItemModel("Name", complexObject));
            //------------Execute Test---------------------------

            //------------Assert Results-------------------------
            //Parent
            Assert.IsTrue(complexObject.IsUsed);

            //Child
            Assert.IsTrue(complexObject.Children[0].IsUsed);
        }
        public void ComplexObjectItemModel_ValidateNames_WithInvalidComplexObjectChildNameWithDot_ShouldHaveError()
        {
            //------------Setup for test--------------------------
            var complexObject = new ComplexObjectItemModel("Parent");

            complexObject.Children.Add(new ComplexObjectItemModel("Name.", complexObject));
            //------------Execute Test---------------------------

            //------------Assert Results-------------------------
            //Parent
            Assert.IsFalse(complexObject.HasError);
            Assert.IsNull(complexObject.ErrorMessage);
            //Child
            Assert.IsTrue(complexObject.Children[0].HasError);
            Assert.AreEqual("Complex Object name [[Name.]] contains invalid character(s). Only use alphanumeric _ and - ", complexObject.Children[0].ErrorMessage);
        }
        public void ComplexObjectItemModel_Constructor_ShouldCreateItem()
        {
            //------------Setup for test--------------------------

            //------------Execute Test---------------------------
            var complexObjectItemModel = new ComplexObjectItemModel("TestItem");

            //------------Assert Results-------------------------
            Assert.IsNotNull(complexObjectItemModel);
            Assert.IsInstanceOfType(complexObjectItemModel, typeof(DataListItemModel));
            Assert.IsInstanceOfType(complexObjectItemModel, typeof(IComplexObjectItemModel));
            Assert.IsNull(complexObjectItemModel.Parent);
            Assert.IsTrue(complexObjectItemModel.IsParentObject);
            Assert.AreEqual("TestItem", complexObjectItemModel.DisplayName);
            Assert.AreEqual("@TestItem", complexObjectItemModel.Name);
        }
示例#13
0
        public void SetWorkflowInputData_WithObject_ShouldAddToPayload()
        {
            //------------Setup for test--------------------------
            const string Shape = @"<DataList><rec Description="""" IsEditable=""True"" ColumnIODirection=""None"" ><a Description="""" IsEditable=""True"" ColumnIODirection=""Input"" /><b Description="""" IsEditable=""True"" ColumnIODirection=""None"" /></rec><Person Description="""" IsEditable=""True"" ColumnIODirection=""Input"" IsJson=""True""><Name></Name><Age></Age></Person></DataList>";

            var rm = new Mock <IContextualResourceModel>();

            rm.Setup(r => r.ServerID).Returns(_serverID);
            rm.Setup(r => r.ResourceName).Returns(ResourceName);
            rm.Setup(r => r.WorkflowXaml).Returns(new StringBuilder(StringResourcesTest.DebugInputWindow_WorkflowXaml));
            rm.Setup(r => r.ID).Returns(_resourceID);
            rm.Setup(r => r.DataList).Returns(Shape);
            var mockDataListViewModel = new Mock <IDataListViewModel>();
            var personObject          = new ComplexObjectItemModel("Person", null, enDev2ColumnArgumentDirection.Input);

            personObject.Children.Add(new ComplexObjectItemModel("Age", personObject, enDev2ColumnArgumentDirection.Input));
            personObject.Children.Add(new ComplexObjectItemModel("Name", personObject, enDev2ColumnArgumentDirection.Input));
            var complexObjectItemModels = new ObservableCollection <IComplexObjectItemModel> {
                personObject
            };

            mockDataListViewModel.Setup(model => model.ComplexObjectCollection).Returns(complexObjectItemModels);
            DataListSingleton.SetDataList(mockDataListViewModel.Object);
            var serviceDebugInfoModel = new ServiceDebugInfoModel
            {
                DebugModeSetting = DebugMode.DebugInteractive,
                RememberInputs   = true,
                ResourceModel    = rm.Object,
                ServiceInputData = "xxxxx"
            };

            var debugVM = CreateDebugOutputViewModel();

            var workflowInputDataViewModel = new WorkflowInputDataViewModel(serviceDebugInfoModel, debugVM.SessionID);

            workflowInputDataViewModel.LoadWorkflowInputs();
            var inputs = workflowInputDataViewModel.WorkflowInputs;

            Assert.AreEqual(2, inputs.Count);
            inputs[0].Value = "bob";
            //------------Execute Test---------------------------
            workflowInputDataViewModel.SetXmlData();
            //------------Assert Results-------------------------
            Assert.AreEqual("<DataList><recjson:Array=\"true\"xmlns:json=\"http://james.newtonking.com/projects/json\"><a>bob</a></rec><Person><Age></Age><Name></Name></Person></DataList>", workflowInputDataViewModel.XmlData.Replace(Environment.NewLine, "").Replace(" ", ""));
        }
        public void ComplexObjectItemModel_GetJson_HasObjectChildren_ShouldReturnCorrectJson()
        {
            //------------Setup for test--------------------------
            var complexObject = new ComplexObjectItemModel("Parent");

            complexObject.Children.Add(new ComplexObjectItemModel("Name", complexObject));
            complexObject.Children.Add(new ComplexObjectItemModel("Age", complexObject));
            var schoolObject = new ComplexObjectItemModel("School", complexObject);

            complexObject.Children.Add(schoolObject);
            schoolObject.Children.Add(new ComplexObjectItemModel("Name", schoolObject));
            schoolObject.Children.Add(new ComplexObjectItemModel("Location", schoolObject));
            complexObject.Children.Add(new ComplexObjectItemModel("Gender", complexObject));
            //------------Execute Test---------------------------
            var jsonString = complexObject.GetJson();

            //------------Assert Results-------------------------
            Assert.AreEqual("{\"Parent\":{\"Name\":\"\",\"Age\":\"\",\"School\":{\"Name\":\"\",\"Location\":\"\"},\"Gender\":\"\"}}", jsonString);
        }
 private void ProcessObjectForComplexObjectCollection(IComplexObjectItemModel parentObj, JObject objToProcess)
 {
     if (objToProcess != null)
     {
         var properties = objToProcess.Properties();
         foreach (var property in properties)
         {
             var displayname = property.Name;
             displayname = JPropertyExtensionMethods.IsEnumerable(property) ? displayname + "()" : displayname;
             var childObj = parentObj.Children.FirstOrDefault(model => model.DisplayName == displayname);
             if (childObj == null)
             {
                 childObj = new ComplexObjectItemModel(displayname, parentObj)
                 {
                     IsArray = JPropertyExtensionMethods.IsEnumerable(property)
                 };
                 parentObj.Children.Add(childObj);
             }
             if (property.Value.IsObject())
             {
                 ProcessObjectForComplexObjectCollection(childObj, property.Value as JObject);
             }
             else
             {
                 if (!property.Value.IsEnumerable())
                 {
                     continue;
                 }
                 var arrayVal = property.Value as JArray;
                 if (arrayVal == null)
                 {
                     continue;
                 }
                 var obj = arrayVal.FirstOrDefault() as JObject;
                 if (obj != null)
                 {
                     ProcessObjectForComplexObjectCollection(childObj, obj);
                 }
             }
         }
     }
 }
        public void ComplexObjectItemModel_ValidateNames_WithValidLongComplexObject_IsUsed()
        {
            //------------Setup for test--------------------------
            var complexObject = new ComplexObjectItemModel("Pet");

            complexObject.Children.Add(new ComplexObjectItemModel("O()", complexObject));
            complexObject.Children.Add(new ComplexObjectItemModel("n()", complexObject));
            complexObject.Children.Add(new ComplexObjectItemModel("l()", complexObject));
            complexObject.Children.Add(new ComplexObjectItemModel("m(*)", complexObject));
            complexObject.Children.Add(new ComplexObjectItemModel("X", complexObject));
            //------------Execute Test---------------------------

            //------------Assert Results-------------------------
            //Parent
            Assert.IsTrue(complexObject.IsUsed);

            //Child
            Assert.IsTrue(complexObject.Children[0].IsUsed);
            Assert.IsTrue(complexObject.Children[1].IsUsed);
            Assert.IsTrue(complexObject.Children[2].IsUsed);
            Assert.IsTrue(complexObject.Children[3].IsUsed);
            Assert.IsTrue(complexObject.Children[4].IsUsed);
        }