Ejemplo n.º 1
0
        public void CanDeleteWithoutPrimaryKey()
        {
            using (var db = OpenDbConnection())
            {
                db.CreateTable <NoPrimaryKey>(true);

                var npk = new NoPrimaryKey {
                    Test = "coucou", Test2 = "Hello"
                };

                db.Insert(npk);
                db.Insert(new NoPrimaryKey {
                    Test = "Hola"
                });
                db.Insert(new NoPrimaryKey {
                    Test = "Hi !"
                });
                db.Insert(new NoPrimaryKey {
                    Test = "coucou"
                });
                db.Insert(new NoPrimaryKey {
                    Test = "coucou", Test2 = "Hello"
                });

                Assert.AreEqual(5, db.Count <NoPrimaryKey>());

                //DELETE FROM NoPrimaryKey Where Test = 'coucou' AND test2 = 'Hello'
                db.Delete(npk);

                Assert.AreEqual(3, db.Count <NoPrimaryKey>());
            }
        }
        public void Create_Without_Primary_Key_Throws_Exception()
        {
            var schema = new SchemaBuilder()
                         .Define <NoPrimaryKey>()
                         .Build();
            var entity = new NoPrimaryKey();
            var threw  = false;

            try
            {
                var deleteQuery = DeleteBuilder <NoPrimaryKey> .Create(schema, entity);
            }
            catch
            {
                threw = true;
            }

            Assert.IsTrue(threw);
        }