public void DataReceivingTest() { var portMock = new Mock<IBinaryPort>(); portMock.Setup(foo => foo.ReadBytesBlock(1)).Returns(new byte[] {0xA}); // возвращаем сигнатуру // возвращаем тело пакета portMock.Setup(foo => foo.ReadBytesBlock(16)).Returns(new byte[]{0, 0, 0, 0, 0, 0, 52, 64, 0, 0, 0, 0, 0, 192, 82,192}); var loggerStub = new LoggerStub(); var target = new PortListener(portMock.Object, loggerStub); var expected = new AccelData(20.0, -75.0); var syncEvent = new AutoResetEvent(false); AccelData actual = null; target.AccelDataReceived += (sender, dataArgs) => { syncEvent.Set(); actual = dataArgs.Data; }; target.StartListen(); if (!syncEvent.WaitOne(5000)) // ждем события { Assert.Fail("Таймаут ожидания данных"); } target.StopListen(); Assert.AreEqual(expected.Ax, actual.Ax); // проверяем правильность разбора пакета }
public void ConstructorWihoutParametersTest() { var target = new AccelData(); Assert.AreEqual(0F,target.Ax); Assert.AreEqual(0F,target.Ay ); }
public void ConstructorWithParametersTest() { double ax = 10.0; double ay = 50.0; var target = new AccelData(ax,ay); Assert.AreEqual(ax, target.Ax); Assert.AreEqual(ay, target.Ay); }
public void OperatorMinusTest() { var target1 = new AccelData(15.0, 75.0); var target2 = new AccelData(5.0, -150.0); var expected = new AccelData(10.0, 225.0); var actual = target1 - target2; Assert.AreEqual(expected.Ax, actual.Ax); Assert.AreEqual(expected.Ay, actual.Ay); }
public void OperatorDivideTest() { var target = new AccelData(15.0, 75.0); var divizor = 5.0; var expected = new AccelData(3.0, 15.0); var actual = target/divizor; Assert.AreEqual(expected.Ax, actual.Ax); Assert.AreEqual(expected.Ay, actual.Ay); }
public void FromBufferTest() { var target = new AccelData(15.0, 75.0); var expected = new AccelData(20.0, -75.0); var buffer = new DataBuffer(Endianness.LittleEndian); buffer.WriteDouble(20.0); buffer.WriteDouble(-75.0); target.FromBuffer(buffer); Assert.AreEqual(expected.Ax, target.Ax); Assert.AreEqual(expected.Ay, target.Ay); }
/// <summary> /// Возвращает список всех записанных данных акселерометра /// </summary> /// <returns></returns> public IList<AccelData> GetAccelData() { var result = new List<AccelData>(); var command = new SqlCeCommand(); command.Connection = _connection; command.CommandText = @"SELECT date,Ax,Ay FROM accel_data"; var reader = command.ExecuteReader(); while (reader.Read()) { var data = new AccelData(); data.Date = reader.GetDateTime(0); data.Ax = reader.GetDouble(1); data.Ay = reader.GetDouble(2); result.Add(data); } return result; }
public void GetAccelParamsByDateSpanTest() { _testDb.CreateDatabase(); _testDb.InitTestSchema(); _testDb.PopulateTestAccelParams(); string databaseFile = _testDbFile; ILogger logger = new LoggerStub(); var target = new LocalDatabaseStorage(databaseFile, logger); target.Open(); var data = new AccelData(10.0, 50.0); data.Date = DateTime.Now; var actual = target.GetAccelParamsByDateSpan(new DateTime(2012, 1, 1) - TimeSpan.FromDays(10), new DateTime(2012, 1, 1)); Assert.AreEqual(2, actual.Count); target.Close(); }
public void SaveAccelDataTest() { string databaseFile = _testDbFile; ILogger logger = new LoggerStub(); var target = new LocalDatabaseStorage(databaseFile, logger); target.Open(); var data = new AccelData(10.0, 50.0); data.Date = DateTime.Now; target.SaveAccelData(data); var idCount = _testDb.GetIdCount("accel_data"); Assert.AreEqual(idCount,1,"проверяем, что запись добавлена"); Assert.AreEqual(1, data.Id, "проверяем, что изменен идентификатор записи в базе"); target.Close(); }
public void GetAccelParamsBySensorNumberTest() { _testDb.CreateDatabase(); _testDb.InitTestSchema(); _testDb.PopulateTestAccelParams(); string databaseFile = _testDbFile; ILogger logger = new LoggerStub(); var target = new LocalDatabaseStorage(databaseFile, logger); target.Open(); var data = new AccelData(10.0, 50.0); data.Date = DateTime.Now; var actual = target.GetAccelParamsBySensorNumber(1); Assert.AreEqual(2, actual.Count); target.Close(); }
public void ToBufferTest() { var target = new AccelData(20.0, -75.0); var expected = new byte[] {0, 0, 0, 0, 0, 0,52,64,0,0,0,0,0,192,82,192}; var buffer = new DataBuffer(Endianness.LittleEndian); target.ToBuffer(buffer); CollectionAssert.AreEqual(expected, buffer.RawData); }
/// <summary> /// Возвращает список данных акселерометра записанных в промежуток времени (границы промежутка включительно) /// </summary> /// <param name="from">начало промежутка</param> /// <param name="till">конец промежутка</param> /// <returns></returns> public IList<AccelData> GetAccelDataByDateSpan(DateTime from, DateTime till) { var result = new List<AccelData>(); var command = new SqlCeCommand(); command.Connection = _connection; command.CommandText = @"SELECT date,Ax,Ay FROM accel_data WHERE date >= @from AND date <= @till"; command.Parameters.AddWithValue("@from", from); command.Parameters.AddWithValue("@till", till); var reader = command.ExecuteReader(); while (reader.Read()) { var data = new AccelData(); data.Date = reader.GetDateTime(0); data.Ax = reader.GetDouble(1); data.Ay = reader.GetDouble(2); result.Add(data); } return result; }
/// <summary> /// Обновляет запись в базе /// </summary> /// <param name="data"></param> private void UpdateAccelData(AccelData data) { var command = new SqlCeCommand(); command.Connection = _connection; command.CommandText = @"UPDATE accel_data SET date=@date,Ax=@Ax,Ay=@Ay WHERE id = @id"; command.Parameters.AddWithValue("@id", data.Id); command.Parameters.AddWithValue("@date", data.Date); command.Parameters.AddWithValue("@Ax", data.Ax); command.Parameters.AddWithValue("@Ay", data.Ay); command.ExecuteNonQuery(); }
/// <summary> /// Создает в базе запись /// </summary> /// <param name="data"></param> private void CreateAccelData(AccelData data) { var command = new SqlCeCommand(); command.Connection = _connection; command.CommandText = @"INSERT INTO accel_data (date, Ax,Ay) VALUES(@date,@Ax,@Ay)"; command.Parameters.AddWithValue("@date", data.Date); command.Parameters.AddWithValue("@Ax", data.Ax); command.Parameters.AddWithValue("@Ay", data.Ay); command.ExecuteNonQuery(); command.CommandText = "SELECT @@IDENTITY"; var id = command.ExecuteScalar(); if (id != null) { data.Id = Convert.ToInt32((decimal)id); // записываем идентификатор записи в базе } }
/// <summary> /// Сохраняет в базе данные акселерометра /// </summary> /// <param name="data"></param> public void SaveAccelData(AccelData data) { if (data.Id > 0) { UpdateAccelData(data); } else { CreateAccelData(data); } }
/// <summary> /// Делает выборку по результатам калибровки для указанного идентификатора калибровочных параметров /// </summary> public CalibrationResult GetCalibrationResultByParams(AccelParams parameters) { var result = new CalibrationResult {Parameters = parameters}; var command = new SqlCeCommand(); command.Connection = _connection; command.CommandText = @"SELECT data.Id, data.date, data.Ax, data.Ay FROM calibr_result result JOIN accel_data data ON (result.accelDataId = data.id) WHERE result.accelParamsId = @paramsId"; command.Parameters.AddWithValue("@paramsId", parameters.Id); var reader = command.ExecuteReader(); while (reader.Read()) { var data = new AccelData(); data.Id = reader.GetInt32(0); data.Date = reader.GetDateTime(1); data.Ax = reader.GetDouble(2); data.Ay = reader.GetDouble(3); result.Clusters.Add(data); } return result; }