Пример #1
0
 public async Task <IActionResult> AddValueType(ValueTypeViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (_sensorsManager.CreateValueType(model.SensorId, model.Name, model.Type) != null)
         {
             return(RedirectToAction(nameof(Info), new { id = model.SensorId }));
         }
     }
     return(View(model));
 }
Пример #2
0
        public void ReturnAddValueTypeModel(ValueTypeViewModel model)
        {
            var sensorRepo = new Mock <ISensorsRepository>();

            sensorRepo.Setup(s => s.GetById(model.SensorId)).Returns(GetSensors().FirstOrDefault(s => s.Id == model.SensorId));

            var sensorValueTypeRepo = new Mock <IValueTypesRepository>();

            sensorValueTypeRepo.Setup(s => s.Create(It.IsAny <ValueType>())).Returns(true);

            var _sensorsManager = new SensorsManager(sensorRepo.Object, sensorValueTypeRepo.Object, null);

            var sensorController = new SensorController(_sensorsManager, null);

            var result = sensorController.AddValueType(model).Result;

            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Info", redirectToActionResult.ActionName);
        }