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); } }
public void updateRecord(int id, string name, string producer, decimal capacity, decimal exchangeCost) { IDBatteryType dbBatteryType = new DBatteryType(); dbBatteryType.updateRecord(id, name, producer, capacity, exchangeCost); }
//[TestMethod] public void Main() { List<Station> stations = new List<Station>(); List<Connection> conns = new List<Connection>(); IDBatteryType dbType = new DBatteryType(); int sId1 = 0; int i = 1; Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); string[] lines = System.IO.File.ReadAllLines(@"TestNodeSize50.txt"); lines[0] = ""; foreach (string line in lines) { int x; int[] numbers = (from Match m in Regex.Matches(line, @"\d+") select int.Parse(m.Value)).ToArray(); string digits = new String(line.TakeWhile(Char.IsDigit).ToArray()); int neighbor; int.TryParse(digits, out neighbor); if (int.TryParse(line, out x)) { Station station = new Station(); station.Id = x; station.name = "Station_" + x; station.state = "Open"; station.address = "Address" + x; station.country = "Denmark"; stations.Add(station); sId1 = x; } else if(line != "" && sId1<neighbor) { Connection conn = new Connection(); conn.sId1 = sId1; conn.sId2 = neighbor; conn.distance = numbers[1]; decimal drive = (decimal)numbers[1] / (decimal)70; conn.driveHour = Math.Round(drive, 1); conns.Add(conn); } } List<string> output = new List<string>(); List<string> storages = new List<string>(); List<string> periods = new List<string>(); foreach (Station station in stations) { string text = "insert into Station values ('" + station.Id + "', '" + station.name + "', '" + station.address + "', '" + station.country + "', '" + station.state + "')"; output.Add(text); foreach (MBatteryType bt in dbType.getAllRecord(true)) { string s = "insert into BatteryStorage values ('" + i + "', '" + bt.id + "', '" +station.Id + "',"+ "10)"; storages.Add(s); string p = "insert into Period values ('" + i + "', '" + DateTime.Today + "', 10, 0)"; periods.Add(p); i++; } } foreach (Connection conn in conns) { decimal d = conn.driveHour.Value; string withDot = d.ToString(CultureInfo.InvariantCulture); string text = "insert into Connection values ('" + conn.sId1 + "', '" + conn.sId2 + "', '" + conn.distance + "', '" + withDot + "')"; output.Add(text); } output.AddRange(storages); output.AddRange(periods); System.IO.File.WriteAllLines(@"\TestNode50.txt", output); }
public MBatteryType getRecord(int id, Boolean getAssociation) { IDBatteryType dbBatteryType = new DBatteryType(); return dbBatteryType.getRecord(id, true); }
public List<MBatteryType> getAllRecord(Boolean getAssociation) { IDBatteryType dbBatteryType = new DBatteryType(); return dbBatteryType.getAllRecord(getAssociation); }
public List<string> getAllInfo() { IDBatteryType dbBatteryType = new DBatteryType(); return dbBatteryType.getAllInfo(); }
public void deleteRecord(int id) { IDBatteryType dbBatteryType = new DBatteryType(); dbBatteryType.deleteRecord(id); }
public int addNewRecord(string name, string producer, decimal capacity, decimal exchangeCost) { IDBatteryType dbBatteryType = new DBatteryType(); return dbBatteryType.addNewRecord(name, producer, capacity, exchangeCost); }