Beispiel #1
0
        public void AutoConvertInterfaceTest()
        {
            Guid guid = Guid.NewGuid();

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

            Target target = new Target();
            Assert.That(target.Prop1, Is.EqualTo(default(int)));
            Assert.That(target.Prop2, Is.EqualTo(default(string)));
            Assert.That(target.Prop3, Is.EqualTo(default(object)));
            Assert.That(target.Prop4, Is.EqualTo(default(Guid)));
            Assert.That(target.Prop5, Is.EqualTo(default(int)));

            SimpleConverter simpleConverter = new SimpleConverter();
            simpleConverter.Map(source, target);

            Assert.That(target.Prop1, Is.EqualTo(source.Prop1));
            Assert.That(target.Prop2, Is.EqualTo(source.Prop2));
            Assert.That(target.Prop3, Is.EqualTo(source.Prop3));
            Assert.That(target.Prop4, Is.EqualTo(source.Prop4));
            Assert.That(target.Prop5, Is.EqualTo(source.Prop5));
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            AutoSource source = new AutoSource(1, "1", new object(), Guid.NewGuid(), 1);
            Target target = new Target();

            SimpleConverter simpleconverter = new SimpleConverter();
            Stopwatch stopwatchSimple = TakeTime(IterateOverTests(() => simpleconverter.Map(source, target)));

            var map = ManualMap<AutoSource, Target>.New
                .AddMap(a => a.Prop1, b => b.Prop1)
                .AddMap(a => a.Prop2, b => b.Prop2)
                .AddMap(a => a.Prop3, b => b.Prop3)
                .AddMap(a => a.Prop4, b => b.Prop4)
                .AddMap(a => a.Prop5, b => b.Prop5);

            Stopwatch stopwatchManual = TakeTime(IterateOverTests(() => map.Map(source, target)));

            Stopwatch stopwatchAuto = TakeTime(IterateOverTests(() => AutoConverter.AutoConvert(source, target)));

            LinqMapSource source2 = new LinqMapSource(1, 2, 3, 4, 5);
            LinqMapTarget target2 = new LinqMapTarget();

            var linqMap = LinqMap<LinqMapSource, LinqMapTarget>.New
                .AddMap(a => a.Source1, (a, b) => a.Target1 = b)
                .AddMap(a => a.Source2, (a, b) => a.Target2 = b)
                .AddMap(a => a.Source3, (a, b) => a.Target3 = b)
                .AddMap(a => a.Source4, (a, b) => a.Target4 = b)
                .AddMap(a => a.Source5, (a, b) => a.Target5 = b);

            Stopwatch stopwatchLinq = TakeTime(IterateOverTests(() => linqMap.Map(source2, target2)));

            Console.WriteLine(stopwatchSimple.ElapsedMilliseconds);
            Console.WriteLine(stopwatchManual.ElapsedMilliseconds);
            Console.WriteLine(stopwatchAuto.ElapsedMilliseconds);
            Console.WriteLine(stopwatchLinq.ElapsedMilliseconds);

            Console.Read();
        }
Beispiel #3
0
        public void AutoConvertUnableToConvertTest()
        {
            Guid guid = Guid.NewGuid();

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

            Target target = new Target();

            SimpleConverter simpleConverter = new SimpleConverter();
            simpleConverter.Map(source, target);
        }