public void RedirectToActionIndex_WithTheCorrectModel__WhenModelStateIsValid() { //Arrange var foodCategoriesServiceMock = new Mock <IFoodCategoriesService>(); var mappingServiceMock = new Mock <IMappingService>(); var controller = new FoodCategoriesController(foodCategoriesServiceMock.Object, mappingServiceMock.Object); Guid id = Guid.NewGuid(); string name = "Tomatos"; FoodType foodType = FoodType.Vegetable; MeasuringUnitType measuringUnit = MeasuringUnitType.Kg; var foodcategory = new FoodCategory() { Id = id, Name = name, FoodType = foodType, MeasuringUnit = measuringUnit }; foodCategoriesServiceMock.Setup(x => x.GetFoodCategoryById(id)).Returns(foodcategory); var model = new FoodCategoryViewModel(); model.Id = foodcategory.Id; model.Name = foodcategory.Name; model.FoodType = foodcategory.FoodType; model.MeasuringUnit = foodcategory.MeasuringUnit; mappingServiceMock.Setup(x => x.Map <FoodCategoryViewModel>(foodcategory)).Returns(model); //Act & Assert controller.WithCallTo(x => x.EditFoodCategory(model)) .ShouldRedirectTo(x => x.Index()); }
public ColumnKey(CalculationType calculationType, MeasuringUnitType measuringUnit, string name, int channel = 0) { CalculationType = calculationType; MeasuringUnitType = measuringUnit; Channel = channel; Name = name; }
public ColumnKey(string name, CalculationType calculationType, int channel = 0, MeasuringUnitType measuringUnit = Agreements.MeasuringUnitType.Unknown) { CalculationType = calculationType; MeasuringUnitType = measuringUnit; Channel = channel; Name = name; }
public static string GetString(this MeasuringUnitType value) { if (value == MeasuringUnitType.Unknown) { return(string.Empty); } string result = "unknown"; var type = value.GetType(); FieldInfo fieldInfo = type.GetField(value.ToString()); if (fieldInfo != null) { var attributes = fieldInfo.GetCustomAttributes(typeof(ParameterAttribute), false); if (attributes.Any()) { var attribute = (ParameterAttribute)attributes.First(); result = attribute.Value; } } return(result); }
public Data(string parameterName, MeasuringUnitType measuringUnit, DateTime date, double value) { ParameterName = parameterName; MeasuringUnit = measuringUnit; Date = date; Value = value; }
public void RedirectToActionIndex__WhenFoodCategoryIsSuccessfullyDeleted() { //Arrange var foodCategoriesServiceMock = new Mock <IFoodCategoriesService>(); var mappingServiceMock = new Mock <IMappingService>(); var controller = new FoodCategoriesController(foodCategoriesServiceMock.Object, mappingServiceMock.Object); var id = Guid.NewGuid(); string name = null; FoodType foodType = FoodType.Vegetable; MeasuringUnitType measuringUnit = MeasuringUnitType.Kg; var foodcategory = new FoodCategory() { Id = id, Name = name, FoodType = foodType, MeasuringUnit = measuringUnit }; foodCategoriesServiceMock.Setup(x => x.GetFoodCategoryById(id)).Returns(foodcategory); foodCategoriesServiceMock.Setup(x => x.DeleteFoodCategory(foodcategory)); //Act & Assert controller.WithCallTo(x => x.DeleteFoodCategoryConfirm(id)) .ShouldRedirectTo(x => x.Index()); }
public Data(string parameterName, MeasuringUnitType measuringUnit, DateTime date, double value, CalculationType calculationType = CalculationType.NotCalculated, int channel = 0) { ParameterName = parameterName; MeasuringUnit = measuringUnit; Date = date; Value = value; CalculationType = calculationType; Channel = channel; }
public static MeasuringUnitType OrFromString(this MeasuringUnitType obj, string value) { var measuringUnitType = MeasuringUnitType.Unknown; if (Enum.TryParse <MeasuringUnitType>(value, out measuringUnitType)) { return(measuringUnitType); } return(obj); }
private static Tuple <DateTime, IEnumerable <Data> > ConvertToData(IEnumerable <VariableDataBlock> collection) { if (collection == null) { return(null); } var colList = collection.ToList(); var list = new List <VariableDataBlock>(); //будем использовать только те элементы, значения unit'а которых будет наибольшим foreach (var variableDataBlock in colList) { //if (colList.Any(c => c.Value is double // && (double)c.Value > 0 // && c.DriverParameter == variableDataBlock.DriverParameter // && c.Drh.Dib.Tarrif == variableDataBlock.Drh.Dib.Tarrif // && c.Drh.Dib.StorageNumber == variableDataBlock.Drh.Dib.StorageNumber // && c.Drh.Dib.Unit > variableDataBlock.Drh.Dib.Unit)) // continue; list.Add(variableDataBlock); } var dateTimeRecord = list.FirstOrDefault(vdb => vdb.DriverParameter == DriverParameter.TimePoint); if (dateTimeRecord == null || !(dateTimeRecord.Value is DateTime)) { return(null); } var recordDateTime = (DateTime)dateTimeRecord.Value; var recordList = new List <Data>(); foreach (var dataBlock in list) { var uglyParameter = mapper[dataBlock.DriverParameter, dataBlock.Drh.Dib.Tarrif, dataBlock.Drh.Dib.Unit]; //ParameterType parameterType = //mapper[dataBlock.DriverParameter, dataBlock.Drh.Dib.Tarrif]; if (uglyParameter.Equals(UglyParameter.Unknown)) { continue; } MeasuringUnitType measuringUnitType = MeasuringUnitType.Unknown; if (dimensionMapper.ContainsKey(dataBlock.DriverParameter)) { measuringUnitType = dimensionMapper[dataBlock.DriverParameter]; } var value = (double)dataBlock.Value; recordList.Add(new Data(string.Format("{0}{1}{2}", uglyParameter.ParameterType, uglyParameter.Channel, uglyParameter.CalculationType), measuringUnitType, recordDateTime, value)); } return(new Tuple <DateTime, IEnumerable <Data> >(recordDateTime, recordList)); }
/// <summary> /// читает регистр текущих показаний /// </summary> /// <param name="register"></param> /// <param name="name"></param> /// <param name="measuringUnit"></param> /// <param name="channel"></param> /// <param name="calculationType"></param> /// <param name="date"></param> /// <returns></returns> private Data ReadCurrent3(int register, string name, MeasuringUnitType measuringUnit, DateTime date) { Data data = null; try { var result = new ResponseFloat(SendMessageToDevice(new Request3(NetworkAddress, register, 2))); data = new Data(name, measuringUnit, date, result.OneValue); } catch (Exception ex) { OnSendMessage(string.Format("не удалось прочитать регистр 0x{0:X}", register)); } return(data); }
public void RenderTheRightView_EditFoodCategory_WithTheCorrectModel_FoodCategoryViewModel_WhenModelStateIsNotValid() { //Arrange var foodCategoriesServiceMock = new Mock <IFoodCategoriesService>(); var mappingServiceMock = new Mock <IMappingService>(); var controller = new FoodCategoriesController(foodCategoriesServiceMock.Object, mappingServiceMock.Object); Guid id = Guid.NewGuid(); string name = null; FoodType foodType = FoodType.Vegetable; MeasuringUnitType measuringUnit = MeasuringUnitType.Kg; var foodcategory = new FoodCategory() { Id = id, Name = name, FoodType = foodType, MeasuringUnit = measuringUnit }; foodCategoriesServiceMock.Setup(x => x.GetFoodCategoryById(id)).Returns(foodcategory); var model = new FoodCategoryViewModel(); model.Id = foodcategory.Id; model.Name = foodcategory.Name; model.FoodType = foodcategory.FoodType; model.MeasuringUnit = foodcategory.MeasuringUnit; mappingServiceMock.Setup(x => x.Map <FoodCategoryViewModel>(foodcategory)).Returns(model); var validationContext = new ValidationContext(model, null, null); var validationResults = new List <ValidationResult>(); Validator.TryValidateObject(model, validationContext, validationResults, true); foreach (var validationResult in validationResults) { controller.ModelState.AddModelError(validationResult.MemberNames.First(), validationResult.ErrorMessage); } //Act & Assert controller.WithCallTo(x => x.EditFoodCategory(model)) .ShouldRenderView("EditFoodCategory") .WithModel <FoodCategoryViewModel>() .AndModelError("Name"); }
/// <summary> /// Creates an instance of the ELM327 driver. /// </summary> /// <param name="serialPortName">The name of the serial port the ELM is connected to /// ("COM1", "COM2", etc.).</param> /// <param name="protocolType">The desired OBD protocol to use. Using /// <see cref="Elm327.Core.Driver.ElmObdProtocolType.Automatic"/> is usually a good idea.</param> /// <param name="measuringUnit">The desired unit type for reporting readings.</param> public Driver( string serialPortName, ObdProtocolType protocolType, MeasuringUnitType measuringUnit) { this.MeasuringUnitType = measuringUnit; this.ElmVersionID = string.Empty; this.ObdMode01 = new ObdGenericMode01(this); this.ObdMode09 = new ObdGenericMode09(this); this.protocolType = protocolType; this.receiveBuffer = new byte[Driver.RECEIVE_BUFFER_SIZE]; this.serialPort = new SerialPort( serialPortName, Driver.BAUD_RATE, Parity.None, 8, StopBits.One); this.serialPort.ErrorReceived += new SerialErrorReceivedEventHandler(this.UartErrorReceived); }
//public static string GetDisplayName(ParameterType parameterType, int channel, CalculationType calculationType) //{ // string result = parameterType.GetString(); // if (calculationType == CalculationType.Total) // { // result = string.Format("{0} {1}", result, "накопл."); // } // if (channel > 0) // { // result = string.Format("{0}{1}", result, channel.ToString()); // } // return result; //} public static string GetDisplayName(MeasuringUnitType unit) { return(unit.GetString()); }
public ColumnKey(string name, string groupName, MeasuringUnitType measuringUnit = Agreements.MeasuringUnitType.Unknown) { MeasuringUnitType = measuringUnit; Name = name; GroupName = groupName; }
public RawData(string p, int vs, MeasuringUnitType m) { Value = new double[vs]; MeasuringUnit = m; Parameter = p; }