public void insertNewStopWithDoubleSubmittingTest() { #region prepare testing data _coreDb.ExecuteCommand.CommandText = "INSERT INTO Lines(LineName) VALUES('207')"; _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = "SELECT MAX(LineID) FROM Lines"; int lineId1 = Convert.ToInt32(_coreDb.ExecuteScalar()); _coreDb.ExecuteCommand.CommandText = "INSERT INTO Lines(LineName) VALUES('207')"; _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = "SELECT MAX(LineID) FROM Lines"; int lineId2 = Convert.ToInt32(_coreDb.ExecuteScalar()); #endregion Thread.Sleep(CONST_SLEEP_TIME); BusWeb.Spi.Spi target = new BusWeb.Spi.Spi(); int lineID = lineId1; string stopName = "測試路線"; double longitude = 123F; double latitude = 25F; double curLongitude = 124F; double curLatitude = 26F; string owner = "DOWILL"; string culture = "zh-TW"; target.insertNewStop(lineID, stopName, longitude, latitude, curLongitude, curLatitude, owner, culture); Thread.Sleep(CONST_SLEEP_TIME); target.insertNewStop(lineID, stopName, longitude, latitude, curLongitude, curLatitude, owner, culture); Thread.Sleep(CONST_SLEEP_TIME); #region verifying DsBusWeb.LinesDataTable dt = new DsBusWeb.LinesDataTable(); _coreDb.SelectCommand.CommandText = "SELECT * FROM Lines"; _coreDb.Fill(dt); Assert.AreEqual <int>(2, dt.Count, "Line count should be 2!"); DsBusWeb.Line2StopDataTable dt2 = new DsBusWeb.Line2StopDataTable(); _coreDb.SelectCommand.CommandText = "SELECT * FROM Line2Stop"; _coreDb.Fill(dt2); Assert.AreEqual <int>(1, dt2.Count, "Stops should be only 1 links!"); DsBusWeb.StopsDataTable dt3 = new DsBusWeb.StopsDataTable(); _coreDb.SelectCommand.CommandText = "SELECT * FROM Stops"; _coreDb.Fill(dt3); Assert.AreEqual <int>(1, dt3.Count, "Stops should be 1 stops!"); var dr = dt3[0]; Assert.AreEqual <string>(stopName, dr.StopName, "StopName is incorrect!"); Assert.AreEqual <double>(longitude, dr.Longitude, "Longitude is incorrect!"); Assert.AreEqual <double>(latitude, dr.Latitude, "Latitude is incorrect!"); Assert.AreEqual <double>(curLongitude, dr.CreatorLongitude, "CreatorLongitude is incorrect!"); Assert.AreEqual <double>(curLatitude, dr.CreatorLatitude, "CreatorLatitude is incorrect!"); Assert.AreEqual <string>(owner, dr.Owner, "Owner is incorrect!"); Assert.AreEqual(culture, dr["Culture"], "Culture is incorrect!"); #endregion }
public DsBusWeb.LinesDataTable GetLinesList(DateTime stpBgnDT, DateTime stpEndDT) { DsBusWeb.LinesDataTable dt = new DsBusWeb.LinesDataTable(); FillDt(string.Format("SELECT l.*, (SELECT COUNT(1) FROM Line2Stop l2s WHERE l2s.LineID = l.LineID) AS StopCount FROM Lines l WHERE l.LineID IN (SELECT l2s.LineID FROM Line2Stop l2s INNER JOIN Stops s ON l2s.StopID = s.StopID WHERE s.DateCreated BETWEEN {0} AND {1}) ORDER BY l.LineName", OleDbStrHelper.getParamStr(stpBgnDT), OleDbStrHelper.getParamStr(stpEndDT)), dt); return(dt); }
public DsBusWeb.LinesDataTable GetLinesList(double Longitude, double Latitude, double radius, string owner) { DsBusWeb.LinesDataTable dt = new DsBusWeb.LinesDataTable(); FillDt(string.Format("SELECT DISTINCT l.* FROM (Lines l INNER JOIN Line2Stop l2s ON l.LineID = l2s.LineID) INNER JOIN (SELECT StopID FROM Stops WHERE (Owner = {3}) OR (ABS(Longitude - {0}) < {2} AND ABS(Latitude - {1}) < {2})) tmp ON l2s.StopID = tmp.StopID ORDER BY LineName", OleDbStrHelper.getParamStr(new decimal(Longitude)), OleDbStrHelper.getParamStr(new decimal(Latitude)), OleDbStrHelper.getParamStr(new decimal(radius)), OleDbStrHelper.getParamStr(owner)), dt); return(dt); }
private int insertNewLine(string lineName, string culture) #endif { _log.Info(MethodInfo.GetCurrentMethod().Name); var dr = new DsBusWeb.LinesDataTable().NewLinesRow(); dr.LineName = lineName; dr.Culture = culture; using (var db = BusWebDataService.GetServiceInstance()) { return(db.InsertNewLine(dr)); } }
public void deleteStopTest() { #region prepare testing data _coreDb.ExecuteCommand.CommandText = "INSERT INTO Lines(LineName) VALUES('207')"; _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = "SELECT MAX(LineID) FROM Lines"; int lineId1 = Convert.ToInt32(_coreDb.ExecuteScalar()); _coreDb.ExecuteCommand.CommandText = "INSERT INTO Lines(LineName) VALUES('207')"; _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = "SELECT MAX(LineID) FROM Lines"; int lineId2 = Convert.ToInt32(_coreDb.ExecuteScalar()); int stopID = 0; #region line1 #region 周美里 _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('周美里', 121.583377, 25.057018, 0, 0, 'SYSTEM')"; _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops"; stopID = Convert.ToInt32(_coreDb.ExecuteScalar()); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId1, stopID); _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 9, 0)", stopID); _coreDb.Execute(); #endregion #region 後山埤站 _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('後山埤站', 121.582911, 25.04487, 0, 0, 'SYSTEM')"; _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops"; stopID = Convert.ToInt32(_coreDb.ExecuteScalar()); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId1, stopID); _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 3, 1)", stopID); _coreDb.Execute(); #endregion #region 秀朗國小 _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('秀朗國小', 121.521262, 24.999231, 121.58084978, 25.05816265, 'SYSTEM')"; _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops"; stopID = Convert.ToInt32(_coreDb.ExecuteScalar()); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId1, stopID); _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 3, 0)", stopID); _coreDb.Execute(); #endregion #region 週美里 _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('週美里', 121.583377, 25.057018, 121.56014515, 25.03309135, 'SYSTEM')"; _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops"; stopID = Convert.ToInt32(_coreDb.ExecuteScalar()); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId1, stopID); _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 0, 0)", stopID); _coreDb.Execute(); #endregion #region 松山家商 _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('松山家商', 121.580912, 25.035887, 121.5546072, 25.0299129, '*****@*****.**')"; _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops"; stopID = Convert.ToInt32(_coreDb.ExecuteScalar()); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId1, stopID); _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 1, 0)", stopID); _coreDb.Execute(); #endregion #region 永和市永元路 _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('永和市永元路', 121.522975, 25.001647, 121.5525412, 25.0270202, '*****@*****.**')"; _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops"; stopID = Convert.ToInt32(_coreDb.ExecuteScalar()); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId1, stopID); _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 2, 0)", stopID); _coreDb.Execute(); #endregion #endregion #region line2 #region 永和路 _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('永和路', 120.635709, 24.21521, 121.5614992, 25.0326352, 'SYSTEM')"; _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops"; stopID = Convert.ToInt32(_coreDb.ExecuteScalar()); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId2, stopID); _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 0, 0)", stopID); _coreDb.Execute(); #endregion #region 永和市永元路 _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('永和市永元路', 121.522638, 25.000503, 121.5528976, 25.024357, '*****@*****.**')"; _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops"; stopID = Convert.ToInt32(_coreDb.ExecuteScalar()); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId2, stopID); _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 0, 0)", stopID); _coreDb.Execute(); #endregion #region 新湖舊宗路口 _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('新湖舊宗路口', 121.578653, 25.062323, 121.5777363, 25.0634112, '*****@*****.**')"; _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops"; stopID = Convert.ToInt32(_coreDb.ExecuteScalar()); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId2, stopID); _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 0, 0)", stopID); _coreDb.Execute(); #endregion #region 新湖一路口 _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('新湖一路口', 121.579208, 25.060522, 121.57881499, 25.06057842, '*****@*****.**')"; _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops"; stopID = Convert.ToInt32(_coreDb.ExecuteScalar()); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId2, stopID); _coreDb.Execute(); _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 1, 0)", stopID); _coreDb.Execute(); #endregion #endregion #endregion Thread.Sleep(CONST_SLEEP_TIME); BusWeb.Spi.Spi target = new BusWeb.Spi.Spi(); string owner = "*****@*****.**"; bool expected = true; bool actual = target.deleteStop(stopID, owner); Thread.Sleep(CONST_SLEEP_TIME); #region verifying Assert.AreEqual <bool>(expected, actual, "We shall got return value TRUE as success result."); DsBusWeb.LinesDataTable dt = new DsBusWeb.LinesDataTable(); _coreDb.SelectCommand.CommandText = "SELECT * FROM Lines"; _coreDb.Fill(dt); Assert.AreEqual <int>(2, dt.Count, "Line count should be only 2 left!"); DsBusWeb.Line2StopDataTable dt2 = new DsBusWeb.Line2StopDataTable(); _coreDb.SelectCommand.CommandText = "SELECT * FROM Line2Stop"; _coreDb.Fill(dt2); Assert.AreEqual <int>(9, dt2.Count, "Stops should be only 9 links left!"); foreach (var dr in dt2) { Assert.AreNotEqual <int>(stopID, dr.StopID, "There should not be any stopID in link existing as the deleted one!"); } DsBusWeb.StopsDataTable dt3 = new DsBusWeb.StopsDataTable(); _coreDb.SelectCommand.CommandText = "SELECT * FROM Stops"; _coreDb.Fill(dt3); Assert.AreEqual <int>(9, dt3.Count, "Stops should be 9 stops left!"); foreach (var dr in dt3) { Assert.AreNotEqual <int>(stopID, dr.StopID, "There should not be any stopID in stop info existing as the deleted one!"); } #endregion }
public DsBusWeb.LinesDataTable GetLinesList() { DsBusWeb.LinesDataTable dt = new DsBusWeb.LinesDataTable(); FillDt("SELECT l.*, (SELECT COUNT(1) FROM Line2Stop l2s WHERE l2s.LineID = l.LineID) AS StopCount FROM Lines l ORDER BY l.LineName", dt); return(dt); }