Exemple #1
0
        public void Test()
        {
            var e = new Entity
            {
                Color  = Colors.Blue,
                Color2 = Colors.Green,
                Mood   = Moods.VeryHappy,
                Mood2  = Moods.Great,
            };

            var dto = new Dto();

            dto.InjectFrom <EnumToInt>(e);

            var deltas = dto.DeltaResults();

            Assert.AreEqual(2, dto.Color);
            Assert.AreEqual(1, dto.Color2);
            Assert.AreEqual(2, dto.Mood);
            Assert.AreEqual(3, dto.Mood2);

            Assert.IsTrue(deltas.Any());
            Assert.IsTrue(deltas.Count == 4);
            Assert.IsTrue((Colors)deltas[0].SourceValue == e.Color);
            Assert.IsTrue((int)deltas[0].TargetValueOld == 0);
            Assert.IsTrue((int)deltas[0].TargetValueNew == dto.Color);

            var e2 = new Entity();

            e2.InjectFrom <IntToEnum>(dto);
            Assert.AreEqual(dto.Color, 2);
            Assert.AreEqual(dto.Color2, 1);
            Assert.AreEqual(dto.Mood, 2);
            Assert.AreEqual(dto.Mood2, 3);
        }