Пример #1
0
        private LineInfo[] getLineList(double Longitude, double Latitude, double radius, string owner, byte device)
#endif
        {
            _log.Info(MethodInfo.GetCurrentMethod().Name);
            List <LineInfo> list = new List <LineInfo>();

            using (var db = BusWebDataService.GetServiceInstance())
            {
                DsBusWeb.UsageStatisticRow log = new DsBusWeb.UsageStatisticDataTable().NewUsageStatisticRow();
                log.Device    = device;
                log.Latitude  = Latitude;
                log.Longitude = Longitude;
                log.Radius    = radius;
                log.UserCode  = owner;
                db.LogAUsageCase(log);
                var dt = db.GetLinesList(Longitude, Latitude, radius, owner);
                foreach (var dr in dt)
                {
                    list.Add(new LineInfo()
                    {
                        LineID = dr.LineID, LineName = dr.LineName
                    });
                }
            }
            return(list.ToArray());
        }
Пример #2
0
        public void getLineListTest()
        {
            #region prepare testing data

            #region line-1
            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Lines(LineName) VALUES('286')";
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = "SELECT MAX(LineID) FROM Lines";
            int lineID = Convert.ToInt32(_coreDb.ExecuteScalar());

            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude) VALUES('DOWILL', 121.543615, 25.033369)";
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops";
            int stopID = Convert.ToInt32(_coreDb.ExecuteScalar());

            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineID, stopID);
            _coreDb.Execute();

            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude) VALUES('DOWILL-1', 119.543615, 24.033369)";
            _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})", lineID, stopID);
            _coreDb.Execute();
            #endregion

            #region line-2
            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Lines(LineName) VALUES('287')";
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = "SELECT MAX(LineID) FROM Lines";
            lineID = Convert.ToInt32(_coreDb.ExecuteScalar());

            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude) VALUES('DOWILL-2', 110.543615, 35.033369)";
            _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})", lineID, stopID);
            _coreDb.Execute();

            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude) VALUES('DOWILL-3', 100.543615, 30.033369)";
            _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})", lineID, stopID);
            _coreDb.Execute();
            #endregion

            #endregion

            Thread.Sleep(CONST_SLEEP_TIME);
            BusWeb.Spi.Spi target    = new BusWeb.Spi.Spi();
            double         Longitude = 121F;
            double         Latitude  = 25F;
            double         radius    = 1F;
            string         owner     = "*****@*****.**";
            LineInfo[]     actual    = target.getLineList(Longitude, Latitude, radius, owner, 1);
            Thread.Sleep(CONST_SLEEP_TIME);

            #region verifying
            Assert.AreEqual <int>(1, actual.Length, "The row Length of line list is not expected!");
            Assert.AreEqual <string>("286", actual[0].LineName, "The line name is not expected!");

            DsBusWeb.UsageStatisticRow dr = new DsBusWeb.UsageStatisticDataTable().NewUsageStatisticRow();
            dr.Device    = 1;
            dr.Latitude  = 25.0;
            dr.Longitude = 121.0;
            dr.Radius    = 1;
            dr.UserCode  = "*****@*****.**";

            DsBusWeb.UsageStatisticDataTable dt = new DsBusWeb.UsageStatisticDataTable();
            _coreDb.SelectCommand.CommandText = "SELECT * FROM UsageStatistic";
            _coreDb.Fill(dt);
            Assert.AreEqual <int>(1, dt.Count, "Row count is not expeceted!");
            Assert.AreEqual <string>(dr.UserCode, dt[0].UserCode, "UserCode is not expected!");
            Assert.AreEqual <int>(dr.Device, dt[0].Device, "Device is not expected!");
            Assert.AreEqual <double>(dr.Latitude, dt[0].Latitude, "Latitude is not expected!");
            Assert.AreEqual <double>(dr.Longitude, dt[0].Longitude, "Longitude is not expected!");
            Assert.AreEqual <double>(dr.Radius, dt[0].Radius, "Radius is not expected!");
            #endregion
        }