public void GetAllDevices()
        {
            List <IDevice> list = new List <IDevice>
            {
                new Device {
                    DeviceId = "device id 1", DeviceName = "name", DeviceType = 1, Room = "room", RoomId = new Guid(), IsOnline = true
                },
                new Device {
                    DeviceId = "device id 2", DeviceName = "name2", DeviceType = 1, Room = "room", RoomId = new Guid(), IsOnline = true
                },
            };

            var result = controller.GetAllDevices() as JsonResult;

            Assert.IsNotNull(result.Data);
        }
Ejemplo n.º 2
0
        public void GetAllDevices()
        {
            Random random = new Random();

            var devices = new List <Device> {
                new Device
                {
                    Id               = random.NextGuid(),
                    DUID             = new UUIDDUID(random.NextGuid()),
                    LinkLocalAddress = IPv6Address.FromString("fe80::8e21:d9ff:fecd:e2a"),
                    MacAddress       = new byte[] { 0x8C, 0x21, 0xD9, 0xCD, 0x0E, 0x2A },
                    Name             = "My first test device",
                },
                new Device
                {
                    Id               = random.NextGuid(),
                    DUID             = new UUIDDUID(random.NextGuid()),
                    LinkLocalAddress = IPv6Address.FromString("fe80::449c:35ff:fec0:a1bc"),
                    MacAddress       = new byte[] { 0x46, 0x9C, 0x35, 0xC0, 0xA1, 0xBC },
                    Name             = "a device",
                }
            };

            Mock <IDHCPv6ReadStore> storeMock = new Mock <IDHCPv6ReadStore>(MockBehavior.Strict);

            storeMock.Setup(x => x.GetAllDevices()).Returns(devices).Verifiable();

            var controller = new DeviceController(
                storeMock.Object,
                Mock.Of <ILogger <DeviceController> >());

            var actionResult = controller.GetAllDevices();
            var result       = actionResult.EnsureOkObjectResult <IEnumerable <DeviceOverviewResponse> >(true);

            Assert.Equal(devices.Select(x => new DeviceOverviewResponse {
                Name = x.Name, Id = x.Id
            }), result, new DeviceOverviewComparer());

            storeMock.Verify();
        }