public void The_Presenter_Fills_In_The_Form()
        {
            var m = new MappingImpl();
            m.MappingSet = MockRepository.GenerateMock<MappingSet>();
            m.ToEntity = new EntityImpl("entity1");
            m.FromTable = new Table("table1");
            //presenter.AttachToModel(m);
            form.AssertWasCalled(f => f.Clear());
            form.AssertWasCalled(f => f.ToEntity = m.ToEntity);
            form.AssertWasCalled(f => f.FromTable = m.FromTable);
            form.AssertWasCalled(f => f.SetVirtualProperties(m.Ex));
            // Need to ignore arguments on these one as the description of the
            // object being set is too complex, and gets us very little in the
            // way of coverage. If someone screws this up, it'd be a pretty basic mistake,
            // and very obvious in the UI.
            form.AssertWasCalled(f => f.Mappings = m.Mappings, c => c.IgnoreArguments());
            form.AssertWasCalled(f => f.Entities = null, c => c.IgnoreArguments());
            form.AssertWasCalled(f => f.Tables = null, c => c.IgnoreArguments());

            // If these methods were called, then it is very likely that they
            // were used to initialise the Entities and Tables collections,
            // unlesss someone is trying to break something on purpose.
            m.MappingSet.AssertWasCalled(ms => ms.GetEntitiesFromEntitySet());
            m.MappingSet.AssertWasCalled(ms => ms.GetEntitiesFromDatabase());
        }
Exemplo n.º 2
0
        public void It_Is_Deleted()
        {
            MappingSet ms = new MappingSetImpl();
            Mapping m = new MappingImpl();
            ms.AddMapping(m);

            Assert.That(ms.Mappings.Contains(m));

            m.Delete();

            Assert.That(ms.Mappings.Contains(m) == false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns the mapping object that maps the given entity and table.
        /// If one does not exist, a new Mapping is created and returned.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="table"></param>
        /// <returns></returns>
        public Mapping GetMappingBetween(Entity entity, ITable table)
        {
            Mapping mapping = mappings.FirstOrDefault(m => m.ToEntity == entity && m.FromTable == table);

            if (mapping == null)
            {
                mapping = new MappingImpl {
                    ToEntity = entity, FromTable = table
                };
                AddMapping(mapping);
            }

            return(mapping);
        }
        public Mapping DeserialiseMapping(XmlNode node, IDatabase database, EntitySet set)
        {
            NodeProcessor proc = new NodeProcessor(node);
            Mapping mapping = new MappingImpl();

            mapping.FromTable = database.GetTable(proc.GetString("FromTable"), proc.GetString("FromSchema"));

            if (mapping.FromTable == null)
                mapping.FromTable = database.GetView(proc.GetString("FromTable"), proc.GetString("FromSchema"));

            mapping.ToEntity = set.GetEntity(proc.GetString("ToEntity"));

            if (mapping.FromTable == null || mapping.ToEntity == null)
                return null;

            var columnNodes = node.SelectNodes("FromColumns/Column");
            var propNodes = node.SelectNodes("ToProperties/Property");
            if (columnNodes == null) throw new DeserialisationException("There were no columns in this Mapping xml");
            if (propNodes == null) throw new DeserialisationException("There were no properties in this Mapping xml");

            List<IColumn> columns = new List<IColumn>();
            foreach (XmlNode columnNode in columnNodes)
                columns.Add(mapping.FromTable.GetColumn(columnNode.InnerText));

            List<Property> properties = new List<Property>();
            foreach (XmlNode propNode in propNodes)
                properties.Add(mapping.ToEntity.GetProperty(propNode.InnerText));

            if (columns.Count != properties.Count) throw new DeserialisationException("Mapping contains different numbers of columns and properties");

            for (int i = 0; i < columns.Count; i++)
            {
                if (properties[i] != null && columns[i] != null)
                    mapping.AddPropertyAndColumn(properties[i], columns[i]);
            }

            ProcessScriptBase(mapping, node);

            return mapping;
        }
Exemplo n.º 5
0
        private void ProcessUnionSubclasses(object parent, MappingSet mappingSet, IDatabase database, EntitySet entities, Entity newEntity, IEnumerable<unionsubclass> unionsubclasses, ParseResults results, string unqualifiedNamespace)
        {
            if (unionsubclasses == null) return;

            @class hClass = null;
            unionsubclass parentSubClass = null;

            if (parent is @class)
                hClass = (@class)parent;
            else
                parentSubClass = (unionsubclass)parent;

            foreach (unionsubclass hSubclass in unionsubclasses)
            {
                Entity childEntity;

                string @namespace;
                string name;

                if (IsNameFullyQualified(hSubclass.name, out @namespace, out name))
                {
                    childEntity = new EntityImpl(name);

                    string currentNamespace = ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace") == null ? "" : ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace").ToString();

                    if (string.IsNullOrWhiteSpace(currentNamespace))
                        ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectNamespace", @namespace);
                }
                else
                    childEntity = new EntityImpl(hSubclass.name);

                childEntity.SetEntityLazy(hSubclass.lazy);
                newEntity.AddChild(childEntity);

                var childTableMapping = new MappingImpl();
                childTableMapping.FromTable = database.GetTable(hSubclass.table.UnBackTick(), hSubclass.schema.UnBackTick());
                childTableMapping.ToEntity = childEntity;

                foreach (var ip in childEntity.InheritedProperties)
                {
                    PropertyImpl np = new PropertyImpl(ip);
                    np.IsHiddenByAbstractParent = true;
                    childEntity.AddProperty(np);
                    string columnName = "";
                    var props = hClass.Properties().ToList();

                    if (hClass != null)
                    {
                        property matchingProp = hClass.Properties().SingleOrDefault(p => p.name == ip.Name);

                        if (matchingProp != null)
                        {
                            if (matchingProp.column != null)
                                columnName = matchingProp.column;
                            else if (matchingProp.Columns().Count > 0)
                                columnName = matchingProp.Columns()[0].name;
                        }
                        else
                        {
                            if (hClass.Id().column1 != null)
                                columnName = hClass.Id().column1;
                            else if (hClass.Id().column != null && hClass.Id().column.Count() > 0)
                                columnName = hClass.Id().column[0].name;
                        }
                    }
                    else
                        columnName = parentSubClass.Properties().Single(p => p.name == ip.Name).column;

                    IColumn column = childTableMapping.FromTable.GetColumn(columnName.UnBackTick());

                    if (column != null)
                        childTableMapping.AddPropertyAndColumn(np, column);
                }

                foreach (var hProperty in hSubclass.Properties())
                {
                    var property = CreateProperty(childEntity, childTableMapping, hProperty);
                    SetPropertyInfoFromParsedCode(property, results, unqualifiedNamespace, childTableMapping.FromTable.Schema, hSubclass.name);
                }
                // Add the parent's key properties as hidden properties
                foreach (var keyProp in newEntity.Key.Properties)
                {
                    Property childP = childEntity.PropertiesHiddenByAbstractParent.SingleOrDefault(p => p.Name == keyProp.Name);

                    if (childP != null)
                    {
                        //childP.IsHiddenByAbstractParent = true;
                        childP.IsKeyProperty = true;
                    }
                }

                entities.AddEntity(childEntity);
                mappingSet.AddMapping(childTableMapping);

                ProcessUnionSubclasses(hSubclass, mappingSet, database, entities, childEntity, hSubclass.unionsubclass1, results, unqualifiedNamespace);
            }
        }
Exemplo n.º 6
0
        private void ProcessSubclasses(MappingSet mappingSet, IDatabase database, EntitySet entities, Entity parentEntity, IEnumerable<subclass> subclasses, string schemaName, string tableName, ParseResults parseResults, string unqualifiedNamespace)
        {
            if (subclasses == null) return;

            foreach (subclass hSubclass in subclasses)
            {
                Entity childEntity;

                string @namespace;
                string name;

                if (IsNameFullyQualified(hSubclass.name, out @namespace, out name))
                {
                    childEntity = new EntityImpl(name);

                    string currentNamespace = ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace") == null ? "" : ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace").ToString();

                    if (string.IsNullOrWhiteSpace(currentNamespace))
                        ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectNamespace", @namespace);
                }
                else
                    childEntity = new EntityImpl(hSubclass.name);

                childEntity.SetEntityLazy(hSubclass.lazy);

                #region Discriminator
                if (!string.IsNullOrWhiteSpace(hSubclass.discriminatorvalue))
                {
                    childEntity.DiscriminatorValue = hSubclass.discriminatorvalue;

                    //ArchAngel.Providers.EntityModel.Model.EntityLayer.Discriminator d = new Discriminator()
                    //{
                    //    AllowNull = xx,
                    //    ColumnName = hSubclass.d,
                    //    DiscriminatorType = xx,
                    //    Force = xx,
                    //    Formula = xx,
                    //    Insert = xx
                    //};
                    //throw new NotImplementedException("TODO: fixup discriminator stuff");
                    //Grouping g = new AndGrouping();
                    //IColumn column = parentEntity.Discriminator.RootGrouping.Conditions[0].Column;
                    //ArchAngel.Providers.EntityModel.Model.DatabaseLayer.Discrimination.Operator op = ArchAngel.Providers.EntityModel.Model.DatabaseLayer.Discrimination.Operator.Equal;
                    //ExpressionValue value = new ExpressionValueImpl(hSubclass.discriminatorvalue);

                    //if (column != null && op != null && value != null)
                    //    g.AddCondition(new ConditionImpl(column, op, value));

                    //if (childEntity.Discriminator == null)
                    //    childEntity.Discriminator = new DiscriminatorImpl();

                    //childEntity.Discriminator.RootGrouping = g;
                }
                #endregion

                parentEntity.AddChild(childEntity);

                var childTableMapping = new MappingImpl();

                childTableMapping.FromTable = database.GetTable(tableName, schemaName);
                childTableMapping.ToEntity = childEntity;

                foreach (var hProperty in hSubclass.Properties())
                {
                    var property = CreateProperty(childEntity, childTableMapping, hProperty);
                    SetPropertyInfoFromParsedCode(property, parseResults, unqualifiedNamespace, childTableMapping.FromTable.Schema, hSubclass.name);
                }

                entities.AddEntity(childEntity);
                mappingSet.AddMapping(childTableMapping);

                ProcessSubclasses(mappingSet, database, entities, childEntity, hSubclass.subclass1, schemaName, tableName, parseResults, unqualifiedNamespace);
            }
        }
Exemplo n.º 7
0
        private void ProcessJoinedSubclasses(MappingSet mappingSet, IDatabase database, EntitySet entities, Entity newEntity, IEnumerable<joinedsubclass> joinedsubclasses, ParseResults results, string unqualifiedNamespace)
        {
            if (joinedsubclasses == null) return;

            ITable parentTable = null;

            if (newEntity.MappedTables().Count() > 0)
                parentTable = newEntity.MappedTables().ElementAt(0);

            foreach (joinedsubclass hSubclass in joinedsubclasses)
            {
                Entity childEntity;
                string @namespace;
                string name;

                if (IsNameFullyQualified(hSubclass.name, out @namespace, out name))
                {
                    childEntity = new EntityImpl(name);

                    string currentNamespace = ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace") == null ? "" : ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace").ToString();

                    if (string.IsNullOrWhiteSpace(currentNamespace))
                        ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectNamespace", @namespace);

                    unqualifiedNamespace = @namespace;
                }
                else
                    childEntity = new EntityImpl(hSubclass.name);

                childEntity.SetEntityLazy(hSubclass.lazy);
                newEntity.AddChild(childEntity);

                var childTableMapping = new MappingImpl();
                ITable subClassTable;

                if (!string.IsNullOrEmpty(hSubclass.table))
                {
                    string schema = "";

                    if (!string.IsNullOrEmpty(hSubclass.schema))
                        schema = hSubclass.schema;
                    else if (parentTable != null)
                        schema = parentTable.Schema;

                    subClassTable = database.GetTable(hSubclass.table.UnBackTick(), schema.UnBackTick());
                    subClassTable.Database = database;
                }
                else
                    subClassTable = parentTable;

                childTableMapping.FromTable = subClassTable;
                childTableMapping.ToEntity = childEntity;

                foreach (var hProperty in hSubclass.Properties())
                {
                    var property = CreateProperty(childEntity, childTableMapping, hProperty);
                    SetPropertyInfoFromParsedCode(property, results, unqualifiedNamespace, childTableMapping.FromTable.Schema, hSubclass.name);
                }
                if (hSubclass.key != null)
                {
                    string keyColumnName;

                    if (!string.IsNullOrEmpty(hSubclass.key.column1))
                        keyColumnName = hSubclass.key.column1;
                    else //if (hSubclass.key.column != null && hSubclass.key.column.Count() > 0)
                        keyColumnName = hSubclass.key.column[0].name;

                    Property keyProp = childEntity.Properties.FirstOrDefault(p => p.MappedColumn() != null && p.MappedColumn().Name == keyColumnName);

                    if (keyProp == null)
                    {
                        keyProp = CreateProperty(childEntity, childTableMapping, hSubclass.key, subClassTable);
                        SetPropertyInfoFromParsedCode(keyProp, results, unqualifiedNamespace, childTableMapping.FromTable.Schema, childEntity.Name);
                        keyProp.IsHiddenByAbstractParent = true;
                    }
                    keyProp.IsKeyProperty = true;
                }
                entities.AddEntity(childEntity);
                mappingSet.AddMapping(childTableMapping);

                ProcessJoinedSubclasses(mappingSet, database, entities, childEntity, hSubclass.joinedsubclass1, results, unqualifiedNamespace);
            }
        }
Exemplo n.º 8
0
        private static void CreateMappingForNewTableAndEntity(Entity entity, MappingSet set, ITable table)
        {
            Mapping mapping = new MappingImpl();
            mapping.ToEntity = entity;
            mapping.FromTable = table;

            for (int i = 0; i < table.Columns.Count; i++)
            {
                mapping.AddPropertyAndColumn(entity.Properties.ElementAt(i), table.Columns[i]);
            }

            set.AddMapping(mapping);
        }
        public void It_Returns_The_Mapping_Objects()
        {
            ProviderInfo info = new ProviderInfo();

            var mapping1 = new MappingImpl();
            var mapping2 = new MappingImpl();
            info.MappingSet.AddMapping(mapping1);
            info.MappingSet.AddMapping(mapping2);

            IEnumerable<IScriptBaseObject> objects = info.GetAllObjectsOfType(typeof(Mapping));

            Assert.That(objects, Has.Length(2));
            Assert.That(objects.Contains(mapping1), "Missing mapping1");
            Assert.That(objects.Contains(mapping2), "Missing mapping2");
        }
        public static Mapping GetMapping()
        {
            Mapping mapping = new MappingImpl();
            mapping.FromTable = new Table("Table1");
            mapping.FromTable.AddColumn(new Column("Column1"));
            mapping.ToEntity = new EntityImpl("Entity1");
            mapping.ToEntity.AddProperty(new PropertyImpl("Property1"));
            mapping.AddPropertyAndColumn(mapping.ToEntity.Properties.ElementAt(0), mapping.FromTable.Columns[0]);

            return mapping;
        }
        public Mapping DeserialiseMapping(XmlNode node, IDatabase database, EntitySet set)
        {
            NodeProcessor proc    = new NodeProcessor(node);
            Mapping       mapping = new MappingImpl();

            mapping.FromTable = database.GetTable(proc.GetString("FromTable"), proc.GetString("FromSchema"));

            if (mapping.FromTable == null)
            {
                mapping.FromTable = database.GetView(proc.GetString("FromTable"), proc.GetString("FromSchema"));
            }

            mapping.ToEntity = set.GetEntity(proc.GetString("ToEntity"));

            if (mapping.FromTable == null || mapping.ToEntity == null)
            {
                return(null);
            }

            var columnNodes = node.SelectNodes("FromColumns/Column");
            var propNodes   = node.SelectNodes("ToProperties/Property");

            if (columnNodes == null)
            {
                throw new DeserialisationException("There were no columns in this Mapping xml");
            }
            if (propNodes == null)
            {
                throw new DeserialisationException("There were no properties in this Mapping xml");
            }

            List <IColumn> columns = new List <IColumn>();

            foreach (XmlNode columnNode in columnNodes)
            {
                columns.Add(mapping.FromTable.GetColumn(columnNode.InnerText));
            }

            List <Property> properties = new List <Property>();

            foreach (XmlNode propNode in propNodes)
            {
                properties.Add(mapping.ToEntity.GetProperty(propNode.InnerText));
            }

            if (columns.Count != properties.Count)
            {
                throw new DeserialisationException("Mapping contains different numbers of columns and properties");
            }

            for (int i = 0; i < columns.Count; i++)
            {
                if (properties[i] != null && columns[i] != null)
                {
                    mapping.AddPropertyAndColumn(properties[i], columns[i]);
                }
            }

            ProcessScriptBase(mapping, node);

            return(mapping);
        }
        public void The_Mapping_Should_Be_Deleted()
        {
            var m = new MappingImpl();
            var ms = new MappingSetImpl();

            ms.AddMapping(m);

            Assert.That(ms.Mappings.Contains(m), Is.True);
            //presenter.AttachToModel(m);

            form.Raise(f => f.RemoveMapping += null, form, new EventArgs());

            Assert.That(ms.Mappings.Contains(m), Is.False);
        }
        public void The_Mapping_Mappings_Should_Be_Updated()
        {
            var m = new MappingImpl();
            m.FromTable = new Table("table1");
            m.ToEntity = new EntityImpl("entity1");
            m.MappingSet = new MappingSetImpl();

            var property = new PropertyImpl("Prop");
            var column = new Column("Col");
            m.FromTable.AddColumn(column);
            m.ToEntity.AddProperty(property);

            m.AddPropertyAndColumn(property, column);

            form.Mappings = m.Mappings;
            form.GetEventRaiser(f => f.FromTableChanged += null).Raise(form, new EventArgs());

            var colAndProp = m.Mappings.ElementAt(0);

            Assert.That(colAndProp.Property, Is.SameAs(property));
            Assert.That(colAndProp.Column, Is.SameAs(column));
        }
Exemplo n.º 14
0
 public void It_Does_Not_Throw_An_Exception()
 {
     Mapping m = new MappingImpl();
     m.Delete();
 }
Exemplo n.º 15
0
        private Mapping CreateMappingFor(Entity entity, @class hEntity, IDatabase database, string defaultSchema)
        {
            if (hEntity.table == null)
                return null;

            Mapping mapping = new MappingImpl();
            string schema = string.IsNullOrEmpty(hEntity.schema) ? defaultSchema : hEntity.schema;
            var table = database.GetTable(hEntity.table.UnBackTick(), schema.UnBackTick());

            if (table == null)
            {
                // create the table
                table = entityProcessor.CreateTable(entity);
                database.AddTable(table);
            }

            mapping.FromTable = table;
            mapping.ToEntity = entity;

            return mapping;
        }
 public void A_ToEntity__It_Should_Throw_An_Exception()
 {
     var mapping = new MappingImpl();
     mapping.FromTable = new Table();
     new MappingSetSerialisationScheme().SerialiseMapping(mapping);
 }
Exemplo n.º 17
0
        /// <summary>
        /// Returns the mapping object that maps the given entity and table.
        /// If one does not exist, a new Mapping is created and returned.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="table"></param>
        /// <returns></returns>
        public Mapping GetMappingBetween(Entity entity, ITable table)
        {
            Mapping mapping = mappings.FirstOrDefault(m => m.ToEntity == entity && m.FromTable == table);

            if (mapping == null)
            {
                mapping = new MappingImpl { ToEntity = entity, FromTable = table };
                AddMapping(mapping);
            }

            return mapping;
        }