Exemplo n.º 1
0
        public void ValidateSimpleMapper()
        {
            var source = new ValidationTestObjectA()
            {
                Id                    = Guid.NewGuid(),
                SampleDecimal         = 65.99m,
                SampleGuid            = Guid.NewGuid(),
                SampleInt             = 69,
                SampleString          = "Happy Days",
                SampleObject          = "Sample Object",
                SampleNullableInt     = 69 + 2,
                SampleNullableDecimal = 99.345m,
                SampleNullableGuid    = Guid.NewGuid(),
                SampleNullNumber1     = 1,
                SampleNullNumber2     = 5.6m,
                SampleNullNumber5     = 67,
            };

            source.SampleStrings.Add("This better work!");
            var dest = SimpleMapper <ValidationTestObjectA, ValidationTestObjectB> .Instance.Convert(source);

            Assert.AreNotEqual(source.Id, dest.Id);
            Assert.AreEqual(0, dest.SampleStrings.Count);
            Assert.AreEqual(source.SampleDecimal, dest.SampleDecimal);
            Assert.AreEqual(source.SampleGuid, dest.SampleGuid);
            Assert.AreEqual(source.SampleInt, dest.SampleInt);
            Assert.AreEqual(source.SampleString, dest.SampleString);
            Assert.AreEqual(source.SampleObject, dest.SampleObject);

            Assert.AreEqual(source.SampleNullableInt, dest.SampleNullableInt);
            Assert.AreEqual(source.SampleNullableDecimal, dest.SampleNullableDecimal);
            Assert.AreEqual(source.SampleNullableGuid, dest.SampleNullableGuid);

            _ = SimpleMapper <ValidationTestObjectB, ValidationTestObjectA> .Instance.Convert(dest);
        }
Exemplo n.º 2
0
        public void ValidateSimpleMapperWithNullables()
        {
            var source = new ValidationTestObjectA()
            {
                Id            = Guid.NewGuid(),
                SampleDecimal = 65.99m,
                SampleGuid    = Guid.NewGuid(),
                SampleInt     = 69,
                SampleString  = "Happy Days",
                SampleObject  = "Sample Object"
            };

            source.SampleStrings.Add("This better work!");
            var dest = SimpleMapper <ValidationTestObjectA> .Instance.Convert(source);

            Assert.AreNotEqual(source.Id, dest.Id);
            Assert.AreEqual(0, dest.SampleStrings.Count);
            Assert.AreEqual(source.SampleDecimal, dest.SampleDecimal);
            Assert.AreEqual(source.SampleGuid, dest.SampleGuid);
            Assert.AreEqual(source.SampleInt, dest.SampleInt);
            Assert.AreEqual(source.SampleString, dest.SampleString);
            Assert.AreEqual(source.SampleObject, dest.SampleObject);

            Assert.AreEqual(source.SampleNullableInt, dest.SampleNullableInt);
            Assert.AreEqual(source.SampleNullableDecimal, dest.SampleNullableDecimal);
            Assert.AreEqual(source.SampleNullableGuid, dest.SampleNullableGuid);
        }