Esempio n. 1
0
        public void CreateModel_WithMapping()
        {
            var service = this.GetService();

            var db = new EasyDb();

            db.SetTable <FakeModelMapped>("users")
            .SetColumn("id", p => p.Id)
            .SetColumn("first", p => p.FirstName);

            var data = new Dictionary <string, FakeContainerItem>
            {
                ["id"] = new FakeContainerItem {
                    IsDBNull = false, Name = "id", Value = 1
                },
                ["first"] = new FakeContainerItem {
                    IsDBNull = false, Name = "first", Value = "Marie"
                }
            };
            var reader = new MyReaderContainer(data);

            var result = (FakeModelMapped)service.CreateModel <FakeModelMapped>(reader, db);

            Assert.AreEqual(1, result.Id);
            Assert.AreEqual("Marie", result.FirstName);
        }
Esempio n. 2
0
        public void CreateModel_ConvertStringToInt()
        {
            var service = this.GetService();

            var db = new EasyDb();

            var data = new Dictionary <string, FakeContainerItem>
            {
                ["id"] = new FakeContainerItem {
                    IsDBNull = false, Name = "id", Value = "10"
                },
                ["first"] = new FakeContainerItem {
                    IsDBNull = false, Name = "first", Value = "Marie"
                }
            };
            var reader = new MyReaderContainer(data);

            var result = (FakeModel)service.CreateModel <FakeModel>(reader, db);

            Assert.AreEqual(10, result.id);
        }