Ejemplo n.º 1
0
        public void TestDoNotSanitize()
        {
            var fieldmappings = new List <FieldMapping>()
            {
                new FieldMapping()
                {
                    DatabaseFieldName = "db1", MappedFieldName = "mp1"
                },
                new FieldMapping()
                {
                    DatabaseFieldName = "db2", MappedFieldName = "mp2"
                },
                new FieldMapping()
                {
                    DatabaseFieldName = "db3", MappedFieldName = "mp3"
                },
                new FieldMapping()
                {
                    DatabaseFieldName = "db4", MappedFieldName = "mp4"
                },
            };

            Sanitizer.CheckAndFixSanityOfFieldMappings(fieldmappings);

            Assert.That(fieldmappings.Count, Is.EqualTo(4));
        }
Ejemplo n.º 2
0
        public void TestSanitize()
        {
            var fieldmappings = new List <FieldMapping>()
            {
                new FieldMapping()
                {
                    DatabaseFieldName = "db1", MappedFieldName = "mp1"
                },
                new FieldMapping()
                {
                    DatabaseFieldName = "db1", MappedFieldName = "mp2"
                },
                new FieldMapping()
                {
                    DatabaseFieldName = "db2", MappedFieldName = "mp3"
                },
                new FieldMapping()
                {
                    DatabaseFieldName = "db3", MappedFieldName = "mp3"
                },
            };


            Sanitizer.CheckAndFixSanityOfFieldMappings(fieldmappings);

            var expectedFieldmappings = new List <FieldMapping>()
            {
                new FieldMapping()
                {
                    DatabaseFieldName = "db1", MappedFieldName = "mp2"
                },
                new FieldMapping()
                {
                    DatabaseFieldName = "db3", MappedFieldName = "mp3"
                },
            };

            Assert.That(fieldmappings[0].MappedFieldName, Is.EqualTo(expectedFieldmappings[0].MappedFieldName));
            Assert.That(fieldmappings[0].DatabaseFieldName, Is.EqualTo(expectedFieldmappings[0].DatabaseFieldName));
            Assert.That(fieldmappings[1].MappedFieldName, Is.EqualTo(expectedFieldmappings[1].MappedFieldName));
            Assert.That(fieldmappings[1].DatabaseFieldName, Is.EqualTo(expectedFieldmappings[1].DatabaseFieldName));
            Assert.That(fieldmappings.Count, Is.EqualTo(2));
        }
        private void DragDropEvent(object sender, DragEventArgs e)
        {
            var cursorLocation = PointToClient(new Point(e.X, e.Y));
            var hittest        = HitTest(cursorLocation.X, cursorLocation.Y);

            // Test for valid drop position
            if (hittest.ColumnIndex == 0 && hittest.RowIndex != -1 && hittest.RowIndex != CurrentCell.RowIndex)
            {
                var targetMappedFieldname   = Convert.ToString(this[0, hittest.RowIndex].Value);
                var targetDatabaseFieldname = Convert.ToString(this[1, hittest.RowIndex].Value);

                var listFieldMappings = (List <FieldMapping>)DataSource;
                Enum.TryParse(listFieldMappings.FirstOrDefault()?.Type, out MappingType fieldmappingType);
                var sourceValue = CurrentCell.Value.ToString();

                var targetfieldmapping = listFieldMappings.FirstOrDefault(t => t.DatabaseFieldName == targetDatabaseFieldname);
                var sourcefieldmapping = listFieldMappings.FirstOrDefault(t => t.MappedFieldName == CurrentRow.Cells[0].Value.ToString());
                if (targetfieldmapping != null && sourcefieldmapping != null)
                {
                    targetfieldmapping.MappedFieldName = sourceValue;
                    sourcefieldmapping.MappedFieldName = string.Empty;
                    if (!string.IsNullOrEmpty(targetfieldmapping.MappedFieldName))
                    {
                        if (!listFieldMappings.Exists(t => t.MappedFieldName == targetMappedFieldname))
                        {
                            listFieldMappings.Add(new FieldMapping()
                            {
                                MappedFieldName = targetMappedFieldname, Type = fieldmappingType.ToString()
                            });
                        }
                    }

                    // cleanup empty rows
                    listFieldMappings.RemoveAll(t => string.IsNullOrEmpty(t.MappedFieldName) && string.IsNullOrEmpty(t.DatabaseFieldName));
                    Sanitizer.CheckAndFixSanityOfFieldMappings(listFieldMappings);
                    DataSource = listFieldMappings.ToList();
                }
            }
        }