public void GivenValidObjectWithUserIdShouldAddObject() { var data = new List <Device>().AsQueryable(); var mockContext = new Mock <UserDataContext>(); var mockSet = SetupDbSet(data); mockContext.Setup(c => c.Device).Returns(mockSet.Object); mockContext.Setup(c => c.DeviceType.Find(0)).Returns(new DeviceType() { Id = 1, Type = "Temperature" }); mockContext.Setup(c => c.User.Find(0)).Returns(new User() { Id = 0, UserId = "ABCDEF" }); mockSet.Setup(c => c.Add(It.IsAny <Device>())).Returns(new Device() { Id = 1, DeviceTypeId = 1, UserId = 1 }); var dao = new DeviceDAO(mockContext.Object); var newUserType = dao.Add(new Device() { DeviceTypeId = 1, UserId = 1 }); mockSet.Verify(m => m.Add(It.IsAny <Device>()), Times.Once()); mockContext.Verify(m => m.SaveChanges(), Times.Once()); }
public DeviceModel RegisterDevice(string deviceType) { try { DeviceType type = DeviceTypeDAO.GetByTypeName(deviceType); if (type == null) { throw new Exception("Invalid Device Type"); } UserData.DAL.Device device = new UserData.DAL.Device() { DeviceType = type, DeviceTypeId = type.Id }; var insertedDevice = DeviceDAO.Add(device); return(new DeviceModel() { Id = insertedDevice.Id, DeviceType = insertedDevice.DeviceType.Type }); } catch (Exception ex) { throw new WebFaultException <string>(ex.Message, HttpStatusCode.MethodNotAllowed); } }
public void GivenObjectWithInvalidTypeIdShouldThrowException() { var data = new List <Device>().AsQueryable(); var mockContext = new Mock <UserDataContext>(); var mockSet = SetupDbSet(data); mockContext.Setup(c => c.Device).Returns(mockSet.Object); mockContext.Setup(c => c.DeviceType.Find(0)).Returns((DeviceType)null); var dao = new DeviceDAO(mockContext.Object); var ex = Assert.Throws <Exception>(() => dao.Add(new Device() { DeviceTypeId = 0 })); Assert.AreEqual("Device.TypeId doesn't exist.", ex.Message); }
protected void deviceGrid_InsertCommand(object sender, GridCommandEventArgs e) { GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item; //device type RadComboBox type = (RadComboBox)insertedItem .FindControl("device_type_RadComboBox"); SetInstance(type.SelectedItem.Text); _device.Type = decimal.Parse(type.SelectedValue); RadComboBox name = (RadComboBox)insertedItem.FindControl("rcbName"); //device name _device.DeviceName = name.SelectedValue; //workstation RadComboBox workstation = (RadComboBox)insertedItem .FindControl("workstation_label_RadComboBox"); _device.WorkstationId = decimal.Parse(workstation.SelectedValue); //serial number //_device.SerialNumber = (insertedItem["serial_number"] // .Controls[0] as TextBox).Text; //barcode _device.Barcode = (insertedItem["barcode"] .Controls[0] as TextBox).Text; //username //RadComboBox username = (RadComboBox)insertedItem // .FindControl("username_RadComboBox"); //_device.CurrentUser = username.SelectedValue; _device.CreatedBy = User.Identity.Name; _deviceDAO.Add(_device); }
public bool Add(DeviceEntity _DeviceEntity) { return(deviceDAO.Add(_DeviceEntity)); }