public void TestEquals_TelescopeIdDifferent_NotEqual() { SensorNetworkConfig config = new SensorNetworkConfig(5); SensorNetworkConfig other = new SensorNetworkConfig(6); Assert.IsFalse(config.Equals(other)); }
public void TestUpdateSensorNetworkConfig_ChangeAllFields_UpdatesConfig() { int telescopeId = 5; SensorNetworkConfig original = new SensorNetworkConfig(telescopeId); // Save original config DatabaseOperations.AddSensorNetworkConfig(original); // Change values so the updated one is different original.ElevationTemp1Init = false; original.AzimuthTemp1Init = false; original.ElevationAccelerometerInit = false; original.AzimuthAccelerometerInit = false; original.CounterbalanceAccelerometerInit = false; original.ElevationEncoderInit = false; original.AzimuthEncoderInit = false; original.TimeoutDataRetrieval = 5; original.TimeoutInitialization = 5; // Update config DatabaseOperations.UpdateSensorNetworkConfig(original); var retrieved = DatabaseOperations.RetrieveSensorNetworkConfigByTelescopeId(telescopeId); Assert.IsTrue(original.Equals(retrieved)); // Delete config DatabaseOperations.DeleteSensorNetworkConfig(original); }
public void TestDeleteSensorNetworkConfig_TelescopeDoesntExist_ShouldThrowInvalidOperationException() { SensorNetworkConfig invalidConfig = new SensorNetworkConfig(9000); Assert.ThrowsException <InvalidOperationException>(() => DatabaseOperations.DeleteSensorNetworkConfig(invalidConfig) ); }
public void TestGetSensorInitAsBytes_AllTrue_AllBytesOne() { SensorNetworkConfig config = new SensorNetworkConfig(5); var bytes = config.GetSensorInitAsBytes(); // All bytes in the array should be 1 Assert.IsTrue(bytes.All(singleByte => singleByte == 1)); }
public void TestEquals_Identical_Equal() { int telescopeId = 5; SensorNetworkConfig config = new SensorNetworkConfig(telescopeId); SensorNetworkConfig other = new SensorNetworkConfig(telescopeId); Assert.IsTrue(config.Equals(other)); }
public void TestEquals_ElevationEncoderInitDifferent_NotEqual() { int telescopeId = 5; SensorNetworkConfig config = new SensorNetworkConfig(telescopeId); SensorNetworkConfig other = new SensorNetworkConfig(telescopeId); other.ElevationEncoderInit = false; Assert.IsFalse(config.Equals(other)); }
public void TestEquals_AzimuthTemp1InitDifferent_NotEqual() { int telescopeId = 5; SensorNetworkConfig config = new SensorNetworkConfig(telescopeId); SensorNetworkConfig other = new SensorNetworkConfig(telescopeId); other.AzimuthTemp1Init = false; Assert.IsFalse(config.Equals(other)); }
public void TestEquals_CounterbalanceAccelerometerInitDifferent_NotEqual() { int telescopeId = 5; SensorNetworkConfig config = new SensorNetworkConfig(telescopeId); SensorNetworkConfig other = new SensorNetworkConfig(telescopeId); other.CounterbalanceAccelerometerInit = false; Assert.IsFalse(config.Equals(other)); }
public void TestEquals_TimeoutDataRetrievalDifferent_NotEqual() { int telescopeId = 5; SensorNetworkConfig config = new SensorNetworkConfig(telescopeId); SensorNetworkConfig other = new SensorNetworkConfig(telescopeId); other.TimeoutDataRetrieval = 5; Assert.IsFalse(config.Equals(other)); }
public void TestEquals_TimeoutInitializationDifferent_NotEqual() { int telescopeId = 5; SensorNetworkConfig config = new SensorNetworkConfig(telescopeId); SensorNetworkConfig other = new SensorNetworkConfig(telescopeId); other.TimeoutInitialization = 5; Assert.IsFalse(config.Equals(other)); }
/// <summary> /// Constructor used to initialize a SensorNetworkClient, which will allow the SensorNetworkServer /// to use this to send data to the Sensor Network. /// </summary> /// <param name="clientIPAddress">IP address that the client will connect to.</param> /// <param name="clientPort">Port that the client will connect to.</param> /// <param name="telescopeId">The ID of the Radio Telescope so we know what config to grab.</param> public SensorNetworkClient(string clientIPAddress, int clientPort, int telescopeId) { IPAddress = clientIPAddress; Port = clientPort; SensorNetworkConfig = DatabaseOperations.RetrieveSensorNetworkConfigByTelescopeId(telescopeId); // if the config doesn't exist, create a new one if (SensorNetworkConfig == null) { SensorNetworkConfig = new SensorNetworkConfig(telescopeId); DatabaseOperations.AddSensorNetworkConfig(SensorNetworkConfig); } }
public void TestDeleteSensorNetworkConfig_ConfigExists_DeletesConfig() { int telescopeId = 10; SensorNetworkConfig config = new SensorNetworkConfig(telescopeId); // Save config DatabaseOperations.AddSensorNetworkConfig(config); // Delete config DatabaseOperations.DeleteSensorNetworkConfig(config); // Attempt to find config SensorNetworkConfig result = DatabaseOperations.RetrieveSensorNetworkConfigByTelescopeId(telescopeId); Assert.IsTrue(result == null); }
public void TestGetSensorInitAsBytes_AllTrue_AllBytesZero() { SensorNetworkConfig config = new SensorNetworkConfig(5); config.ElevationTemp1Init = false; config.AzimuthTemp1Init = false; config.ElevationAccelerometerInit = false; config.AzimuthAccelerometerInit = false; config.CounterbalanceAccelerometerInit = false; config.ElevationEncoderInit = false; config.AzimuthEncoderInit = false; var bytes = config.GetSensorInitAsBytes(); // All bytes in the array should be 0 Assert.IsTrue(bytes.All(singleByte => singleByte == 0)); }
public void TestAddAndRetrieveSensorNetworkConfig_Valid_CreatesConfig() { int telescopeId = 5; // Create new SensorNetworkConfig with a telescope ID of 5 SensorNetworkConfig original = new SensorNetworkConfig(telescopeId); original.TimeoutDataRetrieval = 5; original.TimeoutInitialization = 5; DatabaseOperations.AddSensorNetworkConfig(original); var retrieved = DatabaseOperations.RetrieveSensorNetworkConfigByTelescopeId(telescopeId); Assert.IsTrue(original.Equals(retrieved)); // Delete config DatabaseOperations.DeleteSensorNetworkConfig(original); }
public void TestEmptyInitialization() { SensorNetworkConfig config = new SensorNetworkConfig(); // All values should be an equivalent of 0 Assert.AreEqual(config.TelescopeId, 0); Assert.AreEqual(config.TimeoutDataRetrieval, 0); Assert.AreEqual(config.TimeoutInitialization, 0); Assert.AreEqual(config.ElevationTemp1Init, false); Assert.AreEqual(config.AzimuthTemp1Init, false); Assert.AreEqual(config.ElevationAccelerometerInit, false); Assert.AreEqual(config.AzimuthAccelerometerInit, false); Assert.AreEqual(config.CounterbalanceAccelerometerInit, false); Assert.AreEqual(config.ElevationEncoderInit, false); Assert.AreEqual(config.AzimuthEncoderInit, false); }
/// <summary> /// Method used to delete a SensorNetworkConfig. This is not currently being /// used in any production code, only for unit tests. /// </summary> /// <param name="config">The SensorNetworkConfig to be deleted.</param> public static void DeleteSensorNetworkConfig(SensorNetworkConfig config) { using (RTDbContext Context = InitializeDatabaseContext()) { var toDelete = Context.SensorNetworkConfig .Where(c => c.TelescopeId == config.TelescopeId).FirstOrDefault(); if (toDelete == null) { throw new InvalidOperationException($"Cannot delete config; no config found with a telescope of ID {config.TelescopeId}"); } else { Context.SensorNetworkConfig.Attach(toDelete); Context.SensorNetworkConfig.Remove(toDelete); SaveContext(Context); logger.Info(Utilities.GetTimeStamp() + ": Deleted Sensor Network Configuration for Telescope ID " + config.TelescopeId); } } }
/// <summary> /// This will update the sensor network configuration for a specific Telescope /// </summary> /// <param name="config">The SensorNetworkConfig to be updated</param> public static void UpdateSensorNetworkConfig(SensorNetworkConfig config) { using (RTDbContext Context = InitializeDatabaseContext()) { var outdated = Context.SensorNetworkConfig .Where(c => c.TelescopeId == config.TelescopeId).FirstOrDefault(); if (outdated == null) { throw new InvalidOperationException($"Cannot update config; no config found with a telescope of ID {config.TelescopeId}"); } else { config.Id = outdated.Id; Context.SensorNetworkConfig.AddOrUpdate(config); SaveContext(Context); logger.Info(Utilities.GetTimeStamp() + ": Updated Sensor Network Configuration for Telescope ID " + config.TelescopeId); } } }
/// <summary> /// Adds a new Sensor Network Configuration to the database /// </summary> public static void AddSensorNetworkConfig(SensorNetworkConfig config) { using (RTDbContext Context = InitializeDatabaseContext()) { // First see if the config already exists (if Add was called by accident) var testConf = Context.SensorNetworkConfig .Where(c => c.TelescopeId == config.TelescopeId).FirstOrDefault(); // if it exists, forward the config to UpdateSensorNetworkConfig if (testConf != null) { UpdateSensorNetworkConfig(config); } else { Context.SensorNetworkConfig.Add(config); SaveContext(Context); logger.Info(Utilities.GetTimeStamp() + $": Created Sensor Network Configuration for Radio Telescope {config.TelescopeId}"); } } }
public void TestInitialization() { int telescopeId = 5; // Create new SensorNetworkConfig with a telescope ID of 5 SensorNetworkConfig config = new SensorNetworkConfig(telescopeId); // telescope ID Assert.AreEqual(config.TelescopeId, telescopeId); // default constants Assert.AreEqual(config.TimeoutDataRetrieval, SensorNetworkConstants.DefaultDataRetrievalTimeout); Assert.AreEqual(config.TimeoutInitialization, SensorNetworkConstants.DefaultInitializationTimeout); // default initialization (all must default to true) Assert.AreEqual(config.ElevationTemp1Init, true); Assert.AreEqual(config.AzimuthTemp1Init, true); Assert.AreEqual(config.ElevationAccelerometerInit, true); Assert.AreEqual(config.AzimuthAccelerometerInit, true); Assert.AreEqual(config.CounterbalanceAccelerometerInit, true); Assert.AreEqual(config.ElevationEncoderInit, true); Assert.AreEqual(config.AzimuthEncoderInit, true); }