Exemple #1
0
        public void CreateContDeviceHistory()
        {
            var devicesGroup = new GroupModel
            {
                Id = 1,
                Description = "TestDescription",
                Devices = new List<DeviceModel>(),
                Name = "TestGroup",
            };

            devicesGroup.AuditEntity("TestUser");

            var model = new ContinousSettingDeviceModel
            {
                Id = 1,
                ContinousSetting = 20.5d,
                Description = "TestDescription",
                DeviceHistory = new List<DeviceHistoryModel>(),
                Name = "TestDevice",
                DeviceType = DeviceType.Thermometer,
                Group = devicesGroup,
                GroupId = devicesGroup.Id,
            };

            model.AuditEntity("TestUser");

            var historyEntity = model.CreateDeviceHistoryModel();

            Assert.IsNotNull(historyEntity);

            Assert.IsFalse(historyEntity is BinaryDeviceHistoryModel);

            Assert.IsTrue(historyEntity is ContinousDeviceHistoryModel);

            var contHistoryEntity = (ContinousDeviceHistoryModel) historyEntity;

            Assert.AreEqual(model.ContinousSetting, contHistoryEntity.ContinousSetting, 1d);
        }
Exemple #2
0
        public void CreateDeviceHistoryModelNoHistory()
        {
            var devicesGroup = new GroupModel
            {
                Id = 1,
                Description = "TestDescription",
                Devices = new List<DeviceModel>(),
                Name = "TestGroup",
            };

            devicesGroup.AuditEntity("TestUser");

            var model = new BinarySettingDeviceModel
            {
                Id = 1,
                BinarySetting = false,
                Description = "TestDescription",
                DeviceHistory = null,
                Name = "TestDevice",
                DeviceType = DeviceType.Thermometer,
                Group = devicesGroup,
                GroupId = devicesGroup.Id,
            };

            model.AuditEntity("TestUser");

            var viewModel = model.CreateDeviceViewModel();

            Assert.IsNull(viewModel.History);
        }
Exemple #3
0
        public async Task<IHttpActionResult> PostGroupModel(AddGroupViewModel groupVm)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var existingGroup = await _repository.GetFirstAsync(gr => gr.Name == groupVm.Name);

            if (existingGroup != null)
            {
                return BadRequest("Name is taken");
            }
            
            var groupModel = new GroupModel
            {
                Name = groupVm.Name,
                Description = groupVm.Description,
            };
            
            try
            {
                await _repository.AddAsync(groupModel);
            }
            catch (DbUpdateException)
            {
                return BadRequest();
            }

            return CreatedAtRoute("DefaultApi", new { id = groupModel.Id }, groupModel.CreateGroupViewModel());
        }