public void GivenDeviceNameShouldReturnDevice() { var data = new List <Device> { new Device() { Id = 0, Name = "A", UserId = 0 }, new Device() { Id = 1, Name = "B", UserId = 1 }, new Device() { Id = 2, Name = "C", UserId = 0 } }.AsQueryable(); var mockContext = new Mock <UserDataContext>(); var mockSet = SetupDbSet(data); mockContext.Setup(c => c.Device).Returns(mockSet.Object); var dao = new DeviceDAO(mockContext.Object); var result = dao.GetByName("A"); Assert.AreEqual("A", result.Name); }