public void ShouldReturnAllDevices() { var data = new List <Device> { new Device() { Name = "A" }, new Device() { Name = "B" } }.AsQueryable(); var mockContext = new Mock <UserDataContext>(); mockContext.Setup(c => c.Device).Returns(SetupDbSet(data).Object); var dao = new DeviceDAO(mockContext.Object); var results = dao.All(); Assert.AreEqual(2, results.Count); }
public List <DeviceModel> GetDevices() { try { var devices = DeviceDAO.All(); var results = new List <DeviceModel>(); foreach (var device in devices) { results.Add(new DeviceModel() { Id = device.Id, Name = device.Name, DeviceType = device.DeviceType.Type }); } return(results); } catch (Exception ex) { throw new WebFaultException <string>(ex.Message, HttpStatusCode.InternalServerError); } }