private static void TestDBToolCustomer(DBTool <Customer> custDB) { // Initialised PrintDBInfo(custDB, "init"); // Read records from DB custDB.ReadFromDB(); PrintDBInfo(custDB, "readFromDB"); // Insert two records custDB.InsertRecord(new Customer("Erik", "11223344", NextKey(custDB.GetAllKeys().ToList()))); custDB.InsertRecord(new Customer("Fiona", "44332211", NextKey(custDB.GetAllKeys().ToList()))); PrintDBInfo(custDB, "insert"); // Update an object Customer oldObj = custDB.GetRecord(3); Customer newObj = new Customer(oldObj.Name, "13371337", oldObj.Key); custDB.UpdateRecord(oldObj, newObj); PrintDBInfo(custDB, "update"); // Try to remove three object (only two exist) custDB.RemoveRecord(2); custDB.RemoveRecord(8); custDB.RemoveRecord(4); PrintDBInfo(custDB, "delete"); }
private static void PrintDBInfo <T>(DBTool <T> dbTool, string dbOperation) where T : class, IHasKey { Console.WriteLine($"(DBTool) Number of records after DB {dbOperation}: {dbTool.NoOfRecords()}"); foreach (var key in dbTool.GetAllKeys()) { Console.WriteLine($"Record key: {key}"); Console.WriteLine($"Record : {dbTool.GetRecord(key)}"); } Console.WriteLine(); }