Пример #1
0
        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);
        }
Пример #2
0
        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());
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
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);
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Generates parameters for a location object.
        /// </summary>
        /// <param name="location"></param>
        /// <param name="includeLocationID"></param>
        /// <returns></returns>
        public static DynamicParameters FromLocation(BaseStationLocation location, bool includeLocationID = true)
        {
            var result = new DynamicParameters();

            if (includeLocationID)
            {
                result.Add(nameof(location.LocationID), value: location.LocationID);
            }
            result.Add(nameof(location.LocationName), value: location.LocationName);
            result.Add(nameof(location.Latitude), value: location.Latitude);
            result.Add(nameof(location.Longitude), value: location.Longitude);
            result.Add(nameof(location.Altitude), value: location.Altitude);

            return(result);
        }
Пример #7
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);
        }
Пример #8
0
        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);
        }
Пример #9
0
        /// <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));
        }
Пример #10
0
        /// <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();
        }
Пример #11
0
        /// <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();
        }
Пример #12
0
 public void DeleteLocation(BaseStationLocation location)
 {
     ;
 }
Пример #13
0
 public void UpdateLocation(BaseStationLocation location)
 {
     ;
 }
Пример #14
0
 public void InsertLocation(BaseStationLocation location)
 {
     ;
 }