Пример #1
0
        public void ShouldMapIgnoreInsert()
        {
            // db config
            var conn = new MockDb()
                       .NewNonQuery();

            using (conn)
                using (var db = new DbManager(conn))
                {
                    // fluent config
                    new FluentMap <MapIgnoreInsertDbo>()
                    .MapIgnore(_ => _.Field2)
                    .MapTo(db);

                    // when / then
                    new SqlQuery <MapIgnoreInsertDbo>(db).Insert(new MapIgnoreInsertDbo {
                        Field1 = 20, Field2 = 2
                    });

                    AssertExceptionEx.AreException <LinqException>(
                        () => db.GetTable <MapIgnoreInsertDbo>().Insert(() => new MapIgnoreInsertDbo {
                        Field1 = 10, Field2 = 1
                    })
                        , "Fail for linq");

                    // then
                    conn.Commands[0]
                    .Assert().AreNotField("Field2", "Field exists");
                    Assert.AreEqual(1, conn.Commands[0].Parameters.Count, "Fail params");
                }
        }
Пример #2
0
        public void ShouldMapPrimaryKeyForChild()
        {
            // db config
            var conn = new MockDb()
                       .NewReader("Field1", "Field2")
                       .NewRow(1, 2);

            using (conn)
                using (var db = new DbManager(conn))
                {
                    // fluent config
                    new FluentMap <PrimaryKeyDbo>()
                    .PrimaryKey(_ => _.Field2)
                    .MapTo(db);

                    // when
                    AssertExceptionEx.AreNotException <Exception>(() => new SqlQuery <PrimaryKeyChildDbo>(db).SelectByKey(1)
                                                                  , "Fail query");

                    // then
                    Assert.AreEqual(1, conn.Commands[0].Parameters.Count, "Fail params");
                    conn.Commands[0]
                    .Assert().AreField("Field2", 2, "Not where part");
                }
        }