Ejemplo n.º 1
0
        public void TestManualMap()
        {
            DtoMap<Source, Target> map = DtoMap<Source, Target>.New
                .AddMap(a => a.Source1, b => b.Target1)
                .AddMap(a => a.Source2, b => b.Target2)
                .AddMap(a => a.Source3, b => b.Target3)
                .AddMap(a => a.Source4, b => b.Target4)
                .AddMap(a => a.Source5, b => b.Target5);

            Guid guid = Guid.NewGuid();

            Source source = new Source(1, "as", null, guid, 2);

            Target target = new Target();
            Assert.That(target.Target1, Is.EqualTo(default(int)));
            Assert.That(target.Target2, Is.EqualTo(default(string)));
            Assert.That(target.Target3, Is.EqualTo(default(object)));
            Assert.That(target.Target4, Is.EqualTo(default(Guid)));
            Assert.That(target.Target5, Is.EqualTo(default(int)));

            target = source.Map(map);
            Assert.That(target.Target1, Is.EqualTo(source.Source1));
            Assert.That(target.Target2, Is.EqualTo(source.Source2));
            Assert.That(target.Target3, Is.EqualTo(source.Source3));
            Assert.That(target.Target4, Is.EqualTo(source.Source4));
            Assert.That(target.Target5, Is.EqualTo(source.Source5));
        }
Ejemplo n.º 2
0
        public void TestAutoConvertInterface()
        {
            Guid guid = Guid.NewGuid();

            AutoSource source = new AutoSource(1, "as", null, guid, 2);

            Target target = new Target();
            Assert.That(target.Target1, Is.EqualTo(default(int)));
            Assert.That(target.Target2, Is.EqualTo(default(string)));
            Assert.That(target.Target3, Is.EqualTo(default(object)));
            Assert.That(target.Target4, Is.EqualTo(default(Guid)));
            Assert.That(target.Target5, Is.EqualTo(default(int)));

            target = source.AutoConvert<IAutoSource, Target>();
            Assert.That(target.Target1, Is.EqualTo(source.Target1));
            Assert.That(target.Target2, Is.EqualTo(source.Target2));
            Assert.That(target.Target3, Is.EqualTo(source.Target3));
            Assert.That(target.Target4, Is.EqualTo(source.Target4));
            Assert.That(target.Target5, Is.EqualTo(source.Target5));
        }