Example #1
0
        public void TestDeleteAllIdsGuidPK()
        {
            // 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 <DummyClassGuidPK>();
            conn.CreateTable <DummyClassGuidPK>();

            var elementA = new DummyClassGuidPK
            {
                Id  = Guid.NewGuid(),
                Foo = "Foo A",
                Bar = "Bar A"
            };

            var elementB = new DummyClassGuidPK
            {
                Id  = Guid.NewGuid(),
                Foo = "Foo B",
                Bar = "Bar B"
            };

            var elementC = new DummyClassGuidPK
            {
                Id  = Guid.NewGuid(),
                Foo = "Foo C",
                Bar = "Bar C"
            };

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

            conn.InsertAll(elementsList);

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

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

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

            // Verify that the elements have been deleted correctly
            Assert.AreEqual(elementsList.Count - elementsToDelete.Count, conn.Table <DummyClassGuidPK>().Count());
            foreach (var deletedElement in elementsToDelete)
            {
                Assert.IsNull(conn.Find <DummyClassGuidPK>(deletedElement.Id));
            }
        }
        public void TestDeleteAllGuidPK() {
            // 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<DummyClassGuidPK>();
            conn.CreateTable<DummyClassGuidPK>();

            var elementA = new DummyClassGuidPK
            {
                Id = Guid.NewGuid(),
                Foo = "Foo A",
                Bar = "Bar A"
            };

            var elementB = new DummyClassGuidPK
            {
                Id = Guid.NewGuid(),
                Foo = "Foo B",
                Bar = "Bar B"
            };

            var elementC = new DummyClassGuidPK
            {
                Id = Guid.NewGuid(),
                Foo = "Foo C",
                Bar = "Bar C"
            };

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

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

            var elementsToDelete = new List<DummyClassGuidPK> { 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<DummyClassGuidPK>().Count());
            foreach (var deletedElement in elementsToDelete) {
                Assert.IsNull(conn.Find<DummyClassGuidPK>(deletedElement.Id));
            }
        }