Ejemplo n.º 1
0
        public void TestDeleteAllIdsIntPK()
        {
            // In this test we will create three elements in the database and delete
            // two of them using DeleteAllIds extension method

            var conn = Utils.CreateConnection();

            conn.DropTable <DummyClassIntPK>();
            conn.CreateTable <DummyClassIntPK>();

            var elementA = new DummyClassIntPK
            {
                Foo = "Foo A",
                Bar = "Bar A"
            };

            var elementB = new DummyClassIntPK
            {
                Foo = "Foo B",
                Bar = "Bar B"
            };

            var elementC = new DummyClassIntPK
            {
                Foo = "Foo C",
                Bar = "Bar C"
            };

            var elementsList = new List <DummyClassIntPK> {
                elementA, elementB, elementC
            };

            conn.InsertAll(elementsList);

            // Verify that the elements have been inserted correctly
            Assert.AreEqual(elementsList.Count, conn.Table <DummyClassIntPK>().Count());

            var elementsToDelete = new List <DummyClassIntPK> {
                elementA, elementC
            };
            var primaryKeysToDelete = elementsToDelete.Select(e => (object)e.Id);

            // Delete elements from the database
            conn.DeleteAllIds <DummyClassIntPK>(primaryKeysToDelete);

            // Verify that the elements have been deleted correctly
            Assert.AreEqual(elementsList.Count - elementsToDelete.Count, conn.Table <DummyClassIntPK>().Count());
            foreach (var deletedElement in elementsToDelete)
            {
                Assert.IsNull(conn.Find <DummyClassIntPK>(deletedElement.Id));
            }
        }
        public void TestDeleteAllIntPK() {
            // In this test we will create three elements in the database and delete
            // two of them using DeleteAll extension method

            var conn = Utils.CreateConnection();
            conn.DropTable<DummyClassIntPK>();
            conn.CreateTable<DummyClassIntPK>();

            var elementA = new DummyClassIntPK
            {
                Foo = "Foo A",
                Bar = "Bar A"
            };

            var elementB = new DummyClassIntPK
            {
                Foo = "Foo B",
                Bar = "Bar B"
            };

            var elementC = new DummyClassIntPK
            {
                Foo = "Foo C",
                Bar = "Bar C"
            };

            var elementsList = new List<DummyClassIntPK> { elementA, elementB, elementC };
            conn.InsertAll(elementsList);

            // Verify that the elements have been inserted correctly
            Assert.AreEqual(elementsList.Count, conn.Table<DummyClassIntPK>().Count());

            var elementsToDelete = new List<DummyClassIntPK> { elementA, elementC };

            // Delete elements from the database
            conn.DeleteAll(elementsToDelete);

            // Verify that the elements have been deleted correctly
            Assert.AreEqual(elementsList.Count - elementsToDelete.Count, conn.Table<DummyClassIntPK>().Count());
            foreach (var deletedElement in elementsToDelete) {
                Assert.IsNull(conn.Find<DummyClassIntPK>(deletedElement.Id));
            }
        }