Ejemplo n.º 1
0
 public void TestStringMappingSet()
 {
     var mapping = new ColumnPropertyMapping<TestUser, string>("UserName", model => model.Name);
     var user = new TestUser();
     mapping.SetValue(user, "Pelle");
     Assert.Equal("Pelle", user.Name);
 }
Ejemplo n.º 2
0
        public void StringToDateConversion()
        {
            var mapping = new ColumnPropertyMapping<TestUser, DateTime>("CreatedAt", model => model.CreatedAt, ctx => ctx.ToDateTime());
            var user = new TestUser();

            var context = new ValueContext<TestUser> { ColumnValue = "2009-11-01", Entity = user };
            var value = mapping.ConvertValue(context);
            Assert.Equal(new DateTime(2009,11,01), value);
        }
Ejemplo n.º 3
0
        public void TestSimpleConverterForNull()
        {
            var record = new DataRecord(new Tuple<string, object>("Id", null));
            _mapper.Column(model => model.Id, "Id", ctx => int.Parse(ctx.ColumnValue.As<string>() ?? "0"));

            var user = new TestUser();
            _mapper.Map(user, record);
            Assert.Equal(0, user.Id);
        }
Ejemplo n.º 4
0
        public void TestSimpleConverterForIntToString()
        {
            var record = new DataRecord(new Tuple<string, object>("Name", 42));
            _mapper.Column(model => model.Name, "Name", ctx => ctx.ColumnValue.As<string>());

            var user = new TestUser();
            _mapper.Map(user, record);
            Assert.Equal("42", user.Name);
        }
Ejemplo n.º 5
0
        public void AutoToStringConversion()
        {
            var mapping = new ColumnPropertyMapping<TestUser, string>("UserName", model => model.Name);
            var user = new TestUser();

            var ctx = new ValueContext<TestUser> {ColumnValue = 22, Entity = user};
            var value = mapping.ConvertValue(ctx);
            Assert.Equal("22", value);
            mapping.SetValue(user, value);
        }
Ejemplo n.º 6
0
        public void TestPrimaryKey()
        {
            _mapper.PrimaryKey(model => model.Id, "Id");
            Assert.Equal("Id", _mapper.PrimaryKeys.First());
            Assert.Equal("Id", _mapper.GetColumnName("Id"));

            var record = new DataRecord();
            record.Fields.Add(new Tuple<string, object>("Id", 10));
            var user = new TestUser();
            _mapper.Map(user, record);
            Assert.Equal(10, user.Id);
        }
Ejemplo n.º 7
0
 public void TestStringMappingNullSet()
 {
     var mapping = new ColumnPropertyMapping<TestUser, string>("UserName", model => model.Name);
     var user = new TestUser();
     Assert.Equal(null, mapping.GetValue(user));
 }
Ejemplo n.º 8
0
 public void TestStringMappingGet()
 {
     var mapping = new ColumnPropertyMapping<TestUser, string>("UserName", model => model.Name);
     var user = new TestUser {Name = "Arne"};
     Assert.Equal("Arne", mapping.GetValue(user));
 }
Ejemplo n.º 9
0
 public void InvalidMapping()
 {
     var mapping = new ColumnPropertyMapping<TestUser, DateTime>("CreatedAt", model => model.CreatedAt);
     var user = new TestUser();
     Assert.Throws<MappingException>(() => mapping.SetValue(user, 22));
 }