public void TestGetTelemetriesLastManyValues() { //1.1 var db = new DataBaseSqlite(); string deviceCode = RndString(max: 20); string deviceName = RndString(max: 20); string macAddress = RndString(max: 20); string propCode = RndString(max: 20); string propName = RndString(max: 20); List <string> propNames = new List <string> { propName }; string propType = RndPropertyType.ToString(); string isSetter = RndNumber(max: 2).ToString(); string timeMark1 = RndTime.TimeFormater(); string value1 = RndString(3, 3); string timeMark2 = RndTime.TimeFormater(); string value2 = RndString(3, 3); string timeMark3 = RndTime.TimeFormater(); string value3 = RndString(3, 3); var listExpected = new List <(string propName, string timeMarker, string propValue)>(3) { (propName, timeMark1, value1), (propName, timeMark2, value2), (propName, timeMark3, value3) }; //1.2 int err = db.Create(true); Assert.AreEqual(err, 0); err = db.AddDevice(deviceCode, deviceName, macAddress); Assert.AreEqual(err, 0); err = db.AddProperties(deviceCode, propCode, propName, propType, isSetter); Assert.AreEqual(err, 0); err = db.AddTelemetry(deviceCode, propCode, timeMark1, value1); Assert.AreEqual(err, 0); err = db.AddTelemetry(deviceCode, propCode, timeMark2, value2); Assert.AreEqual(err, 0); err = db.AddTelemetry(deviceCode, propCode, timeMark3, value3); Assert.AreEqual(err, 0); //2 err = db.GetTelemetries(out IList <(string propName, string timeMarker, string propValue)> list, deviceCode, propNames); //3 Assert.AreEqual(err, 0); Assert.AreEqual(list.Count, 1); var tMax = listExpected.Max(t => decimal.Parse(t.timeMarker, CultureInfo.InvariantCulture)) .ToString(CultureInfo.InvariantCulture); var m = listExpected.Where(t => t.timeMarker == tMax).ToList(); var d = list[0].timeMarker.TimeFormater(); Assert.AreEqual(decimal.Parse(list[0].timeMarker, CultureInfo.GetCultureInfo("Ru-ru")), decimal.Parse(m[0].timeMarker, CultureInfo.InvariantCulture)); Assert.AreEqual(list[0].propName, m[0].propName); Assert.AreEqual(list[0].propValue, m[0].propValue); }
public void TestGetDevicesProperties() { //1.1 var db = new DataBaseSqlite(); DbControlling.Initialize(db); DbReader = DbControlling.DbReader; string deviceCode1 = RndString(); string deviceCode2 = RndString(); string deviceCode3 = RndString(); string deviceName1 = RndString(); string deviceName2 = RndString(); string deviceName3 = RndString(); string macAddress1 = RndString(); string macAddress2 = RndString(); string macAddress3 = RndString(); string propName1 = RndString(); string propName2 = RndString(); string propName3 = RndString(); string isSetter1 = RndNumber(max: 2).ToString(); string isSetter2 = RndNumber(max: 2).ToString(); string isSetter3 = RndNumber(max: 2).ToString(); string propType1 = RndPropertyType.ToString(); string propType2 = RndPropertyType.ToString(); string propType3 = RndPropertyType.ToString(); string description1 = RndString(); string description2 = RndString(); string description3 = RndString(); string propCode1 = RndString(); string propCode2 = RndString(); string propCode3 = RndString(); var propInfo1 = new PropertyInfo(description1, isSetter1.BoolFormater(), propType1.EnumFotmater <ProperyType>()); var properties1 = new Properties(new Dictionary <string, PropertyInfo> { { propCode1, propInfo1 } }); var propInfo2 = new PropertyInfo(description2, isSetter2.BoolFormater(), propType2.EnumFotmater <ProperyType>()); var properties2 = new Properties(new Dictionary <string, PropertyInfo> { { propCode2, propInfo2 } }); var propInfo3 = new PropertyInfo(description3, isSetter3.BoolFormater(), propType3.EnumFotmater <ProperyType>()); var properties3 = new Properties(new Dictionary <string, PropertyInfo> { { propCode3, propInfo3 } }); var deviceExpected = new Devices { { deviceCode1, new Device(deviceCode1, macAddress1, deviceName1, properties1) }, { deviceCode2, new Device(deviceCode2, macAddress2, deviceName2, properties2) }, { deviceCode3, new Device(deviceCode3, macAddress3, deviceName3, properties3) } }; //1.2 int err = db.Create(true); Assert.AreEqual(err, 0); err = db.AddDevice(deviceCode1, deviceName1, macAddress1); Assert.AreEqual(err, 0); err = db.AddDevice(deviceCode2, deviceName2, macAddress2); Assert.AreEqual(err, 0); err = db.AddDevice(deviceCode3, deviceName3, macAddress3); Assert.AreEqual(err, 0); err = db.AddProperties(deviceCode1, propName1, propType1, isSetter1, description1); Assert.AreEqual(err, 0); err = db.AddProperties(deviceCode2, propName2, propType2, isSetter2, description2); Assert.AreEqual(err, 0); err = db.AddProperties(deviceCode3, propName3, propType3, isSetter3, description3); Assert.AreEqual(err, 0); //2 var devices = GetDevicesProperties(); //3 bool Compare(KeyValuePair <string, Device> a, KeyValuePair <string, Device> b) { return(a.Key == b.Key && a.Value.MacAddress == b.Value.MacAddress && a.Value.Code == b.Value.Code && a.Value.Name == b.Value.Name && !a.Value.Info.Except(b.Value.Info).Any()); } Assert.AreEqual(deviceExpected.Count, devices.Count); var comparer = new EquaComparer <KeyValuePair <string, Device> >(Compare, device => device.Key.GetHashCode()); Assert.IsEmpty(deviceExpected.Except(devices, comparer)); }
public void TestGetDevices() { //1.1 var db = new DataBaseSqlite(); string deviceCode1 = RndString(max: 20); string deviceCode2 = RndString(max: 20); string deviceCode3 = RndString(max: 20); string deviceName1 = RndString(max: 20); string deviceName2 = RndString(max: 20); string deviceName3 = RndString(max: 20); string macAddress1 = RndString(max: 20); string macAddress2 = RndString(max: 20); string macAddress3 = RndString(max: 20); string propName1 = RndString(max: 20); string propName2 = RndString(max: 20); string propName3 = RndString(max: 20); string isSetter1 = RndNumber(max: 2).ToString(); string isSetter2 = RndNumber(max: 2).ToString(); string isSetter3 = RndNumber(max: 2).ToString(); string propType1 = RndPropertyType.ToString(); string propType2 = RndPropertyType.ToString(); string propType3 = RndPropertyType.ToString(); string propCode1 = RndString(max: 20); string propCode2 = RndString(max: 20); string propCode3 = RndString(max: 20); Dictionary <string, IList <string> > devices = new Dictionary <string, IList <string> > { { deviceCode1, new List <string> { propName1 } }, { deviceCode2, new List <string> { propName2 } }, { deviceCode3, new List <string> { propName3 } } }; //1.2 int err = db.Create(true); Assert.AreEqual(err, 0); err = db.AddDevice(deviceCode1, deviceName1, macAddress1); Assert.AreEqual(err, 0); err = db.AddDevice(deviceCode2, deviceName2, macAddress2); Assert.AreEqual(err, 0); err = db.AddDevice(deviceCode3, deviceName3, macAddress3); Assert.AreEqual(err, 0); err = db.AddProperties(deviceCode1, propCode1, propName1, isSetter1, propType1); Assert.AreEqual(err, 0); err = db.AddProperties(deviceCode2, propCode2, propName2, isSetter2, propType2); Assert.AreEqual(err, 0); err = db.AddProperties(deviceCode3, propCode3, propName3, isSetter3, propType3); Assert.AreEqual(err, 0); //2 err = db.GetDevicesPropertyNames(out var devicesAct); //3 Assert.AreEqual(err, 0); Assert.AreEqual(devicesAct.Count, devices.Count); int difCount = 0; foreach (var keyValuePair in devicesAct) { difCount += devices[keyValuePair.Key].Except(keyValuePair.Value).Count(); } Assert.AreEqual(difCount, 0); }