public async Task Get_SystemInfo_Error()
        {
            TaskCompletionSource <int> tcs = null;
            var tcpclientmock = new Mock <ITcpClient>();

            var(jsonbytes, responsemodel) = GetJson <NikoResponse <SystemInfo> >(@"Json\GetSystemInfo_Error.json", true, new SystemInfoConverter());
            // ReSharper disable once AccessToModifiedClosure
            tcpclientmock.SetupGet(c => c.IsConnected).Returns(() => false);
            tcpclientmock.Setup(c => c.ReadAsync(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()))
            .Callback <byte[], int, int>((b, o, l) =>
            {
                jsonbytes.CopyTo(b, o);
            })
            .Returns(() => (tcs = new TaskCompletionSource <int>()).Task);


            var client = new NikoClient(tcpclientmock.Object);

            client.StartClient();
            var responsetask = client.GetSystemInfo();

            tcs.SetResult(jsonbytes.Length);
            var response = await responsetask;

            response.Should().NotBeNull();
            response.Command.Should().Be(response.Command);
            response.Data.Should().BeNull();
            response.IsError.Should().BeTrue();
            response.Error.Should().Be(responsemodel.Error);
        }
        public async Task <IActionResult> Get()
        {
            var si = await _nikoClient.GetSystemInfo();

            if (si.Data.IsError)
            {
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }

            return(Ok(si.Data));
        }
        public async Task Get_SystemInfo_Exception()
        {
            var tcpclientmock = new Mock <ITcpClient>();

            // ReSharper disable once AccessToModifiedClosure
            tcpclientmock.SetupGet(c => c.IsConnected).Returns(() => false);
            tcpclientmock.Setup(c => c.ReadAsync(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()))
            .Returns(() => new TaskCompletionSource <int>().Task);

            tcpclientmock.Setup(c => c.WriteAsync(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>()))
            .Throws <ArgumentNullException>();

            var client = new NikoClient(tcpclientmock.Object);

            client.StartClient();
            Func <Task> act = async() => await client.GetSystemInfo();

            await act.Should().ThrowAsync <ArgumentNullException>();
        }