예제 #1
0
        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);
        }
예제 #2
0
        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);
            }
        }