Example #1
0
        // TODO: Test result of invalid type conversions
        //[Test]
        public void InvalidMemberValueConversions()
        {
            var xpoFieldMapper = new XpoFieldMapper();

            var targetObject = ObjectSpace.CreateObject <MockFactObject>();

            var descMember   = XafTypesInfo.Instance.FindTypeInfo(typeof(MockFactObject)).FindMember("Description");
            var amountMember = XafTypesInfo.Instance.FindTypeInfo(typeof(MockFactObject)).FindMember("Amount");
            var lookupMember = XafTypesInfo.Instance.FindTypeInfo(typeof(MockFactObject)).FindMember("MockLookupObject1");

            xpoFieldMapper.SetMemberValue(targetObject, descMember,
                                          "Hello");
            xpoFieldMapper.SetMemberValue(targetObject, amountMember,
                                          "15");
            xpoFieldMapper.SetMemberValue(targetObject, lookupMember,
                                          "ABC");

            foreach (var obj in xpoFieldMapper.LookupsNotFound)
            {
                foreach (var value in obj.Value)
                {
                    Debug.WriteLine("{0} {1}", obj.Key, value);
                }
            }
        }
        public void AddToObjectCacheTwice_Level1()
        {
            #region Arrange

            var xpoFieldMapper = new XpoFieldMapper();

            var typeInfo   = XafTypesInfo.Instance.FindTypeInfo(typeof(MockFactObject));
            var memberInfo = typeInfo.FindMember("MockLookupObject1");

            #endregion

            #region Act

            var targetObj1 = ObjectSpace.CreateObject <MockFactObject>();
            targetObj1.Description = "Target 1";
            xpoFieldMapper.SetMemberValue(targetObj1, memberInfo, "Apple", true, true);

            var targetObj2 = ObjectSpace.CreateObject <MockFactObject>();
            targetObj2.Description = "Target 2";
            xpoFieldMapper.SetMemberValue(targetObj2, memberInfo, "Apple", true, true);

            ObjectSpace.CommitChanges();

            #endregion

            #region Assert

            var targetObjs = ObjectSpace.GetObjects <MockFactObject>();

            var retargetObj1 = targetObjs.Where(x => x.Description == "Target 1").FirstOrDefault();
            var retargetObj2 = targetObjs.Where(x => x.Description == "Target 2").FirstOrDefault();

            Assert.NotNull(retargetObj1);
            Assert.NotNull(retargetObj1.MockLookupObject1);

            Assert.NotNull(retargetObj2);
            Assert.NotNull(retargetObj2.MockLookupObject1);

            #endregion
        }
Example #3
0
        public void AddLookupObject()
        {
            var xpoFieldMapper = new XpoFieldMapper();
            var targetObj      = ObjectSpace.CreateObject <MockFactObject>();

            ObjectSpace.CommitChanges();

            var typeInfo   = XafTypesInfo.Instance.FindTypeInfo(typeof(MockFactObject));
            var memberInfo = typeInfo.FindMember("MockLookupObject1");

            xpoFieldMapper.SetMemberValue(targetObj, memberInfo, "Apple", true, true);

            Assert.AreEqual(1, xpoFieldMapper.LookupsNotFound.Count());
        }
Example #4
0
        public void PasteColumnsToRow(string[] copiedRowValues, IXPObject obj, ListView view, PasteParam pasteParam, int startColumnIndex)
        {
            var listEditor = ((ListView)view).Editor as GridListEditor;
            var objSpace   = ((ListView)view).ObjectSpace;
            var gridView   = listEditor.GridView;

            // iterate through columns in listview
            int gridColumnIndex   = startColumnIndex;
            int copiedColumnIndex = 0;

            var hasGroups = gridView.Columns.Where(x => x.GroupIndex != -1).Count() > 0;

            if (hasGroups)
            {
                throw new UserFriendlyException("Please ungroup columns before pasting rows");
            }

            var gridColumns = gridView.Columns
                              .Where(x => x.Visible && x.GroupIndex == -1 &&
                                     x.VisibleIndex >= startColumnIndex)
                              .OrderBy(x => x.VisibleIndex)
                              .Select(x => x);

            foreach (var gridColumn in gridColumns)
            {
                if (copiedColumnIndex >= copiedRowValues.Length)
                {
                    break;
                }

                var member   = listEditor.Model.Columns[gridColumn.Name];
                var isLookup = typeof(IXPObject).IsAssignableFrom(member.ModelMember.MemberInfo.MemberType);

                var copiedValue = copiedRowValues[copiedColumnIndex];

                // if column is visible in grid, then increment the copiedValue column counter
                if (gridColumn.Visible)
                {
                    gridColumnIndex++;
                    copiedColumnIndex++;
                }
                // skip non-editable, key column, invisible column or blank values
                // otherwise paste values

                var memberInfo = member.ModelMember.MemberInfo;
                if (member.AllowEdit &&
                    member.PropertyName != listEditor.Model.ModelClass.KeyProperty &&
                    !string.IsNullOrEmpty(copiedValue) &&
                    !string.IsNullOrWhiteSpace(copiedValue)
                    )
                {
                    PasteFieldMap fieldMap = null;
                    if (pasteParam != null)
                    {
                        fieldMap = pasteParam.FieldMaps.Where(m => m.TargetName.ToLower() == gridColumn.Name.ToLower()).FirstOrDefault();
                    }

                    #region Core Logic
                    if (fieldMap == null)
                    {
                        xpoFieldMapper.SetMemberValue(obj, memberInfo, copiedValue, true, true);
                    }
                    else
                    {
                        xpoFieldMapper.SetMemberValue(obj, memberInfo, copiedValue,
                                                      fieldMap.CreateMember, fieldMap.CacheObject);
                    }
                    #endregion
                }
            }
        }