public void A_ToEntity__It_Should_Throw_An_Exception()
        {
            var mapping = new MappingImpl();

            mapping.FromTable = new Table();
            new MappingSetSerialisationScheme().SerialiseMapping(mapping);
        }
Beispiel #2
0
        public LambdaExpression GetExpression()
        {
            var pFrom = Parameter(_fromType, "from");
            var pTo   = Parameter(_toType, "to");
            var pDic  = Parameter(typeof(IDictionary <object, object>), "dic" + ++_data.NameCounter);

            if (_mapperBuilder.MappingSchema.IsScalarType(_fromType) || _mapperBuilder.MappingSchema.IsScalarType(_toType))
            {
                return(Lambda(
                           _mapperBuilder.MappingSchema.GetConvertExpression(_fromType, _toType).ReplaceParameters(pFrom),
                           pFrom,
                           pTo,
                           pDic));
            }

            _data.LocalDic = Parameter(typeof(IDictionary <object, object>), "ldic" + ++_data.NameCounter);
            _data.Locals.Add(_data.LocalDic);
            _data.Expressions.Add(Assign(_data.LocalDic, pDic));

            var expr = new MappingImpl(this, pFrom, pTo).GetExpression();

            var l = Lambda(Block(_data.Locals, _data.Expressions.Concat(expr)), pFrom, pTo, pDic);

            return(l);
        }
Beispiel #3
0
        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());
        }
        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 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);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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");
        }
Beispiel #9
0
        private LambdaExpression GetExpressionInner()
        {
            var pFrom = Parameter(_fromType, "from");
            var pTo   = Parameter(_toType, "to");

            if (_mapperBuilder.MappingSchema.IsScalarType(_fromType) || _mapperBuilder.MappingSchema.IsScalarType(_toType))
            {
                return(Lambda(
                           _mapperBuilder.MappingSchema.GetConvertExpression(_fromType, _toType).ReplaceParameters(pFrom),
                           pFrom,
                           pTo));
            }

            var expr = new MappingImpl(this, pFrom, pTo).GetExpression();

            var l = Lambda(expr, pFrom, pTo);

            return(l);
        }
Beispiel #10
0
        public LambdaExpression GetExpressionEx()
        {
            if (_mapperBuilder.MappingSchema.IsScalarType(_fromType) || _mapperBuilder.MappingSchema.IsScalarType(_toType))
            {
                return(_mapperBuilder.MappingSchema.GetConvertExpression(_fromType, _toType));
            }

            var pFrom = Parameter(_fromType, "from");

            Expression expr;

            if (_mapperBuilder.MappingSchema.IsScalarType(_fromType) || _mapperBuilder.MappingSchema.IsScalarType(_toType))
            {
                expr = GetExpressionExImpl(pFrom, _toType);
            }
            else if (_processCrossReferences)
            {
                _data.LocalDic = Parameter(typeof(IDictionary <object, object>), "ldic" + ++_data.NameCounter);
                _data.Locals.Add(_data.LocalDic);
                _data.Expressions.Add(Assign(_data.LocalDic, New(InfoOf.Constructor(() => new Dictionary <object, object>()))));

                expr = new MappingImpl(this, pFrom, Constant(_mapperBuilder.MappingSchema.GetDefaultValue(_toType), _toType)).GetExpression();
            }
            else
            {
                expr = GetExpressionExImpl(pFrom, _toType);
            }

            if (_data.IsRestart)
            {
                _mapperBuilder.ProcessCrossReferences = true;
                return(new ExpressionBuilder(_mapperBuilder, new BuilderData(_data.MemberMappers)).GetExpressionEx());
            }

            var l = Lambda(
                _data.Locals.Count > 0 || _data.Expressions.Count > 0 ?
                Block(_data.Locals, _data.Expressions.Concat(expr)) :
                expr,
                pFrom);

            return(l);
        }
Beispiel #11
0
            private Expression BuildClassMapper(Expression getValue, MemberAccessor toMember)
            {
                var key   = ValueTuple.Create(_fromExpression.Type, toMember.Type);
                var pFrom = Parameter(getValue.Type, "pFrom");
                var pTo   = Parameter(toMember.Type, "pTo");
                var toObj = toMember.GetterExpression.ReplaceParameters(_localObject);

                ParameterExpression nullPrm = null;

                if (_cacheMapper)
                {
                    if (_builder._data.Mappers.TryGetValue(key, out nullPrm))
                    {
                        return(Invoke(nullPrm, getValue, toObj));
                    }

                    nullPrm = Parameter(
                        Lambda(
                            Constant(
                                _builder._mapperBuilder.MappingSchema.GetDefaultValue(toMember.Type),
                                toMember.Type),
                            pFrom,
                            pTo).Type);

                    _builder._data.Mappers.Add(key, nullPrm);
                    _builder._data.Locals.Add(nullPrm);
                }

                var expr = new MappingImpl(_builder, _cacheMapper ? pFrom : getValue, _cacheMapper ? pTo : toObj).GetExpression();

                if (_cacheMapper)
                {
                    var lex = Lambda(expr, pFrom, pTo);

                    _builder._data.Expressions.Add(Assign(nullPrm, lex));

                    expr = Invoke(nullPrm, getValue, toObj);
                }

                return(expr);
            }
Beispiel #12
0
        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));
        }
Beispiel #13
0
        public void Setup()
        {
            EntitySet entitySet = new EntitySetImpl();

            entity = new EntityImpl("Entity1");
            entity.AddProperty(new PropertyImpl {
                Name = "Property1"
            });
            entitySet.AddEntity(entity);

            IDatabase database = new Database("DB1");

            table = new Table("Table");
            table.AddColumn(new Column("Column1"));
            database.AddEntity(table);

            Mapping mapping = new MappingImpl();

            mapping.AddPropertyAndColumn(entity.Properties.ElementAt(0), table.Columns[0]);

            MappingSet mappingSet = new MappingSetImpl(database, entitySet);

            mappingSet.AddMapping(mapping);
        }
        public void It_Does_Not_Throw_An_Exception()
        {
            Mapping m = new MappingImpl();

            m.Delete();
        }