コード例 #1
0
        public async Task RemoveAllRadioChannelsAsync_Should_Not_Throw_ExceptionsAsync()
        {
            // Arrange
            var miioDevice  = new Mock <IMiioTransport>();
            var miioGateway = new MiioGateway(miioDevice.Object);

            miioDevice.Setup(x => x.SendMessageAsync(It.Is <string>(s => s.Contains("get_channels"))))
            .Returns(Task.FromResult("{\"result\":{\"chs\":[" +
                                     "{\"id\":1025,\"type\":0,\"url\":\"http://192.168.1.1/radio1.m3u8\"}," +
                                     "{\"id\":1026,\"type\":0,\"url\":\"http://192.168.1.1/radio2.m3u8\"}," +
                                     "{\"id\":1027,\"type\":0,\"url\":\"http://192.168.1.1/radio3.m3u8\"}," +
                                     "]}}"));

            miioDevice.Setup(x => x.SendMessageAsync(It.Is <string>(s => s.Contains("remove_channels"))))
            .Returns(Task.FromResult("{\"result\":[\"ok\"],\"id\":2}"));

            // Act
            await miioGateway.RemoveAllRadioChannelsAsync();

            // Assert
            var msg = "{\"id\": 2, \"method\": \"remove_channels\", \"params\": {\"chs\":[" +
                      "{\"id\":1025,\"url\":\"http://192.168.1.1/radio1.m3u8\",\"type\":0}," +
                      "{\"id\":1026,\"url\":\"http://192.168.1.1/radio2.m3u8\",\"type\":0}," +
                      "{\"id\":1027,\"url\":\"http://192.168.1.1/radio3.m3u8\",\"type\":0}" +
                      "]}}";

            miioDevice.Verify(x => x.SendMessageAsync(msg), Times.Once());
        }