public void deleteRecord(int id) { IDBBatteryStorage dbStorage = new DBBatteryStorage(); IDPeriod dbPeriod = new DBPeriod(); bool success = false; using (TransactionScope scope = new TransactionScope()) { try { dbPeriod.deleteRecord(id); dbStorage.deleteRecord(id); success = true; } catch (Exception) { throw new System.NullReferenceException("Can not delete battery."); //throw new SystemException("Can not find battery type"); } if (success) { scope.Complete(); } } }
public void deleteRecord(int id, DateTime time) { IDPeriod dbPeriod = new DBPeriod(); dbPeriod.deleteRecord(id, time); }
public void TestValidateBooking1() { IDStation dbStation = new DStation(); IDBatteryType dbType = new DBatteryType(); IDBBatteryStorage dbStorage = new DBBatteryStorage(); IDPeriod dbPeriod = new DBPeriod(); int sid = dbStation.addNewRecord("name", "address", "country", "state"); int btid = dbType.addNewRecord("name", "producer", 10, 10); int bsid = dbStorage.addNewRecord(btid, sid, 10); MBatteryStorage storage = dbStorage.getRecord(bsid, true); try { MPeriod firstPeriod = new MPeriod(); firstPeriod.bookedBatteryNumber = 6; firstPeriod.initBatteryNumber = 10; firstPeriod.time = DateTime.Today; dbPeriod.addNewRecord(bsid, firstPeriod.time, firstPeriod.initBatteryNumber, firstPeriod.bookedBatteryNumber); storage.periods.Add(firstPeriod); MPeriod testPeriod = new MPeriod(); testPeriod.time = DateTime.Today.AddHours(10); testPeriod.initBatteryNumber = 10; testPeriod.bookedBatteryNumber = 4; dbPeriod.addNewRecord(bsid, testPeriod.time, testPeriod.initBatteryNumber, testPeriod.bookedBatteryNumber); storage.periods.Add(testPeriod); MPeriod lastPeriod = new MPeriod(); lastPeriod.time = DateTime.Today.AddHours(20); lastPeriod.initBatteryNumber = 10; lastPeriod.bookedBatteryNumber = 5; dbPeriod.addNewRecord(bsid, lastPeriod.time, lastPeriod.initBatteryNumber, lastPeriod.bookedBatteryNumber); storage.periods.Add(lastPeriod); BatteryStorageCtr storageCtr = new BatteryStorageCtr(); if (storageCtr.validateBookingForStation(sid, btid, 1, DateTime.Today.AddHours(10))) { Assert.AreEqual(2, 1); } else { Assert.AreEqual(1, 1); //it should fail } if (storageCtr.validateUpdateBookingForStation(sid, btid, 1, DateTime.Today.AddHours(10))) { Assert.AreEqual(2, 1); } else { Assert.AreEqual(1, 1); //it should fail } } finally { foreach (MPeriod p in storage.periods) { dbPeriod.deleteRecord(bsid, p.time); } dbStorage.deleteRecord(bsid); dbType.deleteRecord(btid); dbStation.deleteRecord(sid); } }