Ejemplo n.º 1
0
        public void map_to_dynamic()
        {
            var reader = Setup.FakeReader();
            var sut = new DynamicMapper();
            //var manual=new ManualMapper<dynamic>(r =>
            //{
            //    dynamic d = new ExpandoObject();
            //    d.Id = (Guid) r["Id"];
            //    d.Name = r["Name"];
            //    d.Address = r["Address"];
            //    return d;
            //});

            //var b = new BenchmarkAction(i => sut.Map(reader, ""));
            //Setup.DoBenchmark(1000, b, new BenchmarkAction(i =>
            // {
            //     manual.Map(reader);
            // }));
            dynamic poco = sut.Map(reader, "");
            AssertionExtensions.Should((object) poco.Id).Be(Guid.Empty);
            AssertionExtensions.Should((object) poco.Name).Be("bla");
            AssertionExtensions.Should((object) poco.Address).Be("");

           
        }
Ejemplo n.º 2
0
        public void DynamicMapper_TestEmpty()
        {
            var obj = new ExpandoObject();

            DynamicMapper.Map <EmptyClass>(obj);

            // Shouldn't throw
        }
Ejemplo n.º 3
0
        public void DynamicMapper_TestDefaultsMapping()
        {
            dynamic obj = new ExpandoObject();

            TypesClass mapped = DynamicMapper.Map <TypesClass>(obj, true);

            // Shouldn't throw
        }
Ejemplo n.º 4
0
        public void RuntimeMapperSuccessfulyResolvesObjects()
        {
            var sourceObject = new Source
            {
                Id   = 1,
                Name = "source",
                SourceSpecificProperty = "SourceSpecificProperty"
            };

            var destinationObject = DynamicMapper.CreateMapper <Source, Destination>()
                                    .Invoke(sourceObject);

            Assert.AreEqual(destinationObject.Id, sourceObject.Id);
            Assert.AreEqual(destinationObject.Name, sourceObject.Name);
            Assert.AreNotEqual(destinationObject.DestinationSpecificProperty, sourceObject.SourceSpecificProperty);
        }
Ejemplo n.º 5
0
        public void DynamicMapper_TestTypesConversion()
        {
            dynamic obj = new ExpandoObject();

            obj.BoolProperty   = "true";
            obj.IntProperty    = "10";
            obj.FloatProperty  = "13.37";
            obj.StringProperty = "foo";
            obj.EnumProperty   = ((int)TestEnum.Value2).ToString();
            obj.ObjectProperty = "";

            TypesClass mapped = DynamicMapper.Map <TypesClass>(obj);

            Assert.AreEqual(true, mapped.BoolProperty);
            Assert.AreEqual(10, mapped.IntProperty);
            Assert.AreEqual(13.37f, mapped.FloatProperty);
            Assert.AreEqual("foo", mapped.StringProperty);
            Assert.AreEqual(TestEnum.Value2, mapped.EnumProperty);
            Assert.AreEqual(obj.ObjectProperty, mapped.ObjectProperty);
        }
    public override void PreBuildUp(IBuilderContext context)
    {
        var policy = context.Policies.Get <IBuildKeyMappingPolicy>(context.BuildKey);

        if (policy != null)
        {
            context.BuildKey = policy.Map(context.BuildKey, context);
        }
        else
        {
            var oldMapping = context.BuildKey;
            var mappedType = DynamicMapper.GetMapping(oldMapping.Type);
            context.BuildKey = new NamedTypeBuildKey(mappedType, null);
            var lifetime = context.PersistentPolicies.Get <ILifetimePolicy>(oldMapping, true);
            if (lifetime != null)
            {
                context.PersistentPolicies.Set(lifetime, context.BuildKey);
            }
        }
    }
Ejemplo n.º 7
0
        public void DynamicMapper_TestTypesMapping()
        {
            dynamic obj = new ExpandoObject();

            obj.BoolProperty   = true;
            obj.IntProperty    = 10;
            obj.FloatProperty  = 13.37f;
            obj.StringProperty = "foo";
            obj.EnumProperty   = TestEnum.Value2;
            obj.ObjectProperty = new object();

            TypesClass mapped = DynamicMapper.Map <TypesClass>(obj);

            Assert.AreEqual(obj.BoolProperty, mapped.BoolProperty);
            Assert.AreEqual(obj.IntProperty, mapped.IntProperty);
            Assert.AreEqual(obj.FloatProperty, mapped.FloatProperty);
            Assert.AreEqual(obj.StringProperty, mapped.StringProperty);
            Assert.AreEqual(obj.EnumProperty, mapped.EnumProperty);
            Assert.AreEqual(obj.ObjectProperty, mapped.ObjectProperty);

            Assert.AreEqual(0, mapped.GetDummy());
        }
Ejemplo n.º 8
0
        public void map_to_dynamic()
        {
            var reader = Setup.FakeReader();
            var sut    = new DynamicMapper();
            //var manual=new ManualMapper<dynamic>(r =>
            //{
            //    dynamic d = new ExpandoObject();
            //    d.Id = (Guid) r["Id"];
            //    d.Name = r["Name"];
            //    d.Address = r["Address"];
            //    return d;
            //});

            //var b = new BenchmarkAction(i => sut.Map(reader, ""));
            //Setup.DoBenchmark(1000, b, new BenchmarkAction(i =>
            // {
            //     manual.Map(reader);
            // }));
            dynamic poco = sut.Map(reader, "");

            AssertionExtensions.Should((object)poco.Id).Be(Guid.Empty);
            AssertionExtensions.Should((object)poco.Name).Be("bla");
            AssertionExtensions.Should((object)poco.Address).Be("");
        }