Esempio n. 1
0
        public void ObjectFiller_TargetTypeIsStruct_StructIsFilledCorrectly()
        {
            var today      = Date.Today;
            var now        = DateTime.Now;
            var dataRecord = new MockDataReader(
                new List <MockRecordField>()
            {
                new MockRecordField(1, "productId", typeof(int)),
                new MockRecordField(1L, "nullableProductId", typeof(long)),
                new MockRecordField("woohoo!", "someString", typeof(string)),
                new MockRecordField(1.345356m, "price", typeof(decimal)),
                new MockRecordField(null, "maybePrice", typeof(decimal)),
                new MockRecordField(today, "date", "date", typeof(DateTime)),
                new MockRecordField(now, "datetime", typeof(DateTime)),
            });

            var objectFiller = new ObjectFiller();

            var result = (StructWithSingleConstructor)objectFiller.Build(typeof(StructWithSingleConstructor), dataRecord);

            Assert.AreEqual(result.productId, 1);
            Assert.AreEqual(new LongId <Product>(1) as LongId <Product>?, result.nullableProductId);
            Assert.AreEqual(result.someString, "woohoo!");
            Assert.AreEqual(result.price, 1.345356m);
            Assert.AreEqual(result.maybePrice, null);
            Assert.AreEqual(result.date, today);
            Assert.AreEqual(result.datetime, now);
        }
Esempio n. 2
0
        public void ObjectFiller_TargetTypeIsClassWithConstructorsAndAdditionalColumnsAreSelectedForSorting_ClassIsFilledCorrectly()
        {
            var today      = Date.Today;
            var now        = DateTime.Now;
            var dataRecord = new MockDataReader(
                new List <MockRecordField>()
            {
                new MockRecordField(1, "productId", typeof(int)),
                new MockRecordField("woohoo!", "someString", typeof(string)),
                new MockRecordField(1.345356m, "price", typeof(decimal)),
                new MockRecordField(today, "date", "date", typeof(DateTime)),
                new MockRecordField(now, "datetime", typeof(DateTime)),
                new MockRecordField(now, "insertDate", typeof(DateTime)),
                new MockRecordField(now, "updateDate", typeof(DateTime)),
            });

            var objectFiller = new ObjectFiller();

            var result = (ClassWithMultipleConstructors)objectFiller.Build(typeof(ClassWithMultipleConstructors), dataRecord);

            Assert.AreEqual(result.productId, 1);
            Assert.AreEqual(result.nullableProductId, null);
            Assert.AreEqual(result.someString, "woohoo!");
            Assert.AreEqual(result.price, 1.345356m);
            Assert.AreEqual(result.maybePrice, null);
            Assert.AreEqual(result.date, today);
            Assert.AreEqual(result.datetime, now);
        }
Esempio n. 3
0
        public void ObjectFiller_TargetTypeIsNullableTypedId_ClassIsFilledCorrectly()
        {
            var dataRecord = new MockDataReader(
                new List <MockRecordField>()
            {
                new MockRecordField(null, "productId", typeof(int))
            });

            var objectFiller = new ObjectFiller();

            var result = (Id <Product>?)objectFiller.Build(typeof(Id <Product>?), dataRecord);

            Assert.AreEqual(result, null);
        }