public void BaseStationLocation_Constructor_Initialises_To_Known_State_And_Properties_Work()
        {
            var location = new BaseStationLocation();

            TestUtilities.TestProperty(location, "Altitude", 0.0, 1.23);
            TestUtilities.TestProperty(location, "Latitude", 0.0, 3.45);
            TestUtilities.TestProperty(location, "LocationID", 0, 130);
            TestUtilities.TestProperty(location, "LocationName", null, "Ab");
            TestUtilities.TestProperty(location, "Longitude", 0.0, 7.65);
        }
 public void DeleteLocation(BaseStationLocation location)
 {
     ;
 }
 public void UpdateLocation(BaseStationLocation location)
 {
     ;
 }
 public void InsertLocation(BaseStationLocation location)
 {
     ;
 }
 /// <summary>
 /// Inserts a new record and returns the ID.
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="transaction"></param>
 /// <param name="log"></param>
 /// <param name="location"></param>
 /// <returns></returns>
 public int Insert(IDbConnection connection, IDbTransaction transaction, TextWriter log, BaseStationLocation location)
 {
     var preparedCommand = PrepareInsert(connection, transaction, "Insert", "LocationID", "LocationName", "Latitude", "Longitude", "Altitude");
     return (int)Sql.ExecuteInsert(preparedCommand, log, location.LocationName, location.Latitude, location.Longitude, location.Altitude);
 }
 /// <summary>
 /// Deletes the record passed across.
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="transaction"></param>
 /// <param name="log"></param>
 /// <param name="location"></param>
 public void Delete(IDbConnection connection, IDbTransaction transaction, TextWriter log, BaseStationLocation location)
 {
     var preparedCommand = PrepareCommand(connection, transaction, "Delete", _DeleteCommandText, 1);
     Sql.SetParameters(preparedCommand, location.LocationID);
     Sql.LogCommand(log, preparedCommand.Command);
     preparedCommand.Command.ExecuteNonQuery();
 }
 /// <summary>
 /// Updates an existing record.
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="transaction"></param>
 /// <param name="log"></param>
 /// <param name="location"></param>
 public void Update(IDbConnection connection, IDbTransaction transaction, TextWriter log, BaseStationLocation location)
 {
     var preparedCommand = PrepareCommand(connection, transaction, "Update", _UpdateCommandText, 5);
     Sql.SetParameters(preparedCommand, location.LocationName, location.Latitude, location.Longitude, location.Altitude, location.LocationID);
     Sql.LogCommand(log, preparedCommand.Command);
     preparedCommand.Command.ExecuteNonQuery();
 }
        private long AddLocation(BaseStationLocation location)
        {
            long result = 0;

            using(var connection = new SQLiteConnection(_ConnectionStringBuilder.ConnectionString)) {
                connection.Open();

                using(var command = connection.CreateCommand()) {
                    command.CommandText = "INSERT INTO [Locations] ([Altitude], [Latitude], [LocationName], [Longitude]) VALUES (?,?,?,?); SELECT last_insert_rowid();";
                    command.Parameters.Add(new SQLiteParameter() { Value = location.Altitude });
                    command.Parameters.Add(new SQLiteParameter() { Value = location.Latitude });
                    command.Parameters.Add(new SQLiteParameter() { Value = location.LocationName });
                    command.Parameters.Add(new SQLiteParameter() { Value = location.Longitude });

                    result = (long)command.ExecuteScalar();
                    location.LocationID = (int)result;
                }
            }

            return result;
        }
        public void BaseStationDatabase_DeleteLocation_Throws_If_Writes_Disabled()
        {
            var location = new BaseStationLocation() { LocationName = "B" };
            location.LocationID = (int)AddLocation(location);

            _Database.DeleteLocation(location);
        }
        public void BaseStationDatabase_InsertLocation_Correctly_Inserts_Record()
        {
            _Database.WriteSupportEnabled = true;

            var location = new BaseStationLocation() {
                Altitude = 1.2468,
                Latitude = 51.3921,
                Longitude = 123.9132,
                LocationName = "123456789.123456789.",
            };

            _Database.InsertLocation(location);
            Assert.AreNotEqual(0, location.LocationID);

            var readBack = _Database.GetLocations()[0];
            Assert.AreEqual(location.LocationID, readBack.LocationID);
            Assert.AreEqual(1.2468, readBack.Altitude, 0.00001);
            Assert.AreEqual(51.3921, readBack.Latitude, 0.00001);
            Assert.AreEqual(123.9132, readBack.Longitude, 0.00001);
            Assert.AreEqual("123456789.123456789.", readBack.LocationName);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="location"></param>
        public void DeleteLocation(BaseStationLocation location)
        {
            if(!WriteSupportEnabled) throw new InvalidOperationException("You cannot delete location records when write support is disabled");

            lock(_ConnectionLock) {
                OpenConnection();
                if(_Connection != null) _LocationsTable.Delete(_Connection, _TransactionHelper.Transaction, _DatabaseLog, location);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <returns></returns>
        public IList<BaseStationLocation> GetLocations()
        {
            IList<BaseStationLocation> result = null;

            lock(_ConnectionLock) {
                OpenConnection();
                if(_Connection != null) result = _LocationsTable.GetAllRecords(_Connection, _TransactionHelper.Transaction, _DatabaseLog);
                else                    result = new BaseStationLocation[] {};
            }

            return result;
        }
        public void ReceiverLocationsPresenter_UpdateFromBaseStationDatabaseClicked_Removes_Previous_BaseStationDatabase_Reads_If_No_Longer_In_BaseStation()
        {
            var location1 = new BaseStationLocation() { LocationName = "A", Latitude = 1.2, Longitude = 3.4 };
            _BaseStationDatabase.Setup(r => r.GetLocations()).Returns(new BaseStationLocation[] { location1, });

            _View.Object.ReceiverLocations.Add(new ReceiverLocation() { Name = "B", IsBaseStationLocation = true, UniqueId = 12 });
            _Presenter.Initialise(_View.Object);
            _View.Raise(v => v.UpdateFromBaseStationDatabaseClicked += null, EventArgs.Empty);

            Assert.AreEqual(1, _View.Object.ReceiverLocations.Count);
            Assert.AreEqual("A", _View.Object.ReceiverLocations[0].Name);
        }
        public void ReceiverLocationsPresenter_UpdateFromBaseStationDatabaseClicked_Qualifies_Name_If_Non_BaseStationDatabase_Entry_With_Same_Name_Alredy_On_View()
        {
            var location1 = new BaseStationLocation() { LocationName = "A", Latitude = 1.2, Longitude = 3.4 };
            _BaseStationDatabase.Setup(r => r.GetLocations()).Returns(new BaseStationLocation[] { location1, });

            _View.Object.ReceiverLocations.Add(new ReceiverLocation() { Name = "A", IsBaseStationLocation = false, UniqueId = 12 });
            _Presenter.Initialise(_View.Object);
            _View.Raise(v => v.UpdateFromBaseStationDatabaseClicked += null, EventArgs.Empty);

            Assert.AreEqual(2, _View.Object.ReceiverLocations.Count);
            var locationA = _View.Object.ReceiverLocations.Where(r => r.Name == "A").Single();
            var locationA1 = _View.Object.ReceiverLocations.Where(r => r.Name == "A(1)").Single();

            Assert.AreEqual(0.0, locationA.Latitude);
            Assert.AreEqual(0.0, locationA.Longitude);
            Assert.AreEqual(false, locationA.IsBaseStationLocation);
            Assert.AreEqual(12, locationA.UniqueId);

            Assert.AreEqual("A(1)", locationA1.Name);
            Assert.AreEqual(1.2, locationA1.Latitude);
            Assert.AreEqual(3.4, locationA1.Longitude);
            Assert.AreEqual(true, locationA1.IsBaseStationLocation);
            Assert.AreEqual(13, locationA1.UniqueId);
        }
        public void ReceiverLocationsPresenter_UpdateFromBaseStationDatabaseClicked_Reuses_UniqueId_If_Name_Previously_Read()
        {
            var location1 = new BaseStationLocation() { LocationName = "A", Latitude = 1.2, Longitude = 3.4 };
            _BaseStationDatabase.Setup(r => r.GetLocations()).Returns(new BaseStationLocation[] { location1, });

            _View.Object.ReceiverLocations.Add(new ReceiverLocation() { Name = "A", IsBaseStationLocation = true, UniqueId = 12 });
            _Presenter.Initialise(_View.Object);
            _View.Raise(v => v.UpdateFromBaseStationDatabaseClicked += null, EventArgs.Empty);

            Assert.AreEqual(1, _View.Object.ReceiverLocations.Count);
            var locationA = _View.Object.ReceiverLocations[0];
            Assert.AreEqual("A", locationA.Name);
            Assert.AreEqual(1.2, locationA.Latitude);
            Assert.AreEqual(3.4, locationA.Longitude);
            Assert.AreEqual(true, locationA.IsBaseStationLocation);
            Assert.AreEqual(12, locationA.UniqueId);
        }
        public void ReceiverLocationsPresenter_UpdateFromBaseStationDatabaseClicked_Adds_Entries_From_BaseStation_Database()
        {
            var location1 = new BaseStationLocation() { LocationName = "A", Latitude = 1.2, Longitude = 3.4 };
            var location2 = new BaseStationLocation() { LocationName = "B", Latitude = 5.6, Longitude = 7.8 };
            _BaseStationDatabase.Setup(r => r.GetLocations()).Returns(new BaseStationLocation[] { location1, location2 });

            _Presenter.Initialise(_View.Object);
            _View.Raise(v => v.UpdateFromBaseStationDatabaseClicked += null, EventArgs.Empty);

            Assert.AreEqual(2, _View.Object.ReceiverLocations.Count);
            var locationA = _View.Object.ReceiverLocations.Where(r => r.Name == "A").Single();
            var locationB = _View.Object.ReceiverLocations.Where(r => r.Name == "B").Single();
            Assert.AreEqual(1.2, locationA.Latitude);
            Assert.AreEqual(3.4, locationA.Longitude);
            Assert.AreEqual(5.6, locationB.Latitude);
            Assert.AreEqual(7.8, locationB.Longitude);
            Assert.IsTrue(locationA.IsBaseStationLocation);
            Assert.IsTrue(locationB.IsBaseStationLocation);
            Assert.AreEqual(1, locationA.UniqueId);
            Assert.AreEqual(2, locationB.UniqueId);

            _View.Verify(v => v.RefreshLocations());
        }