Skip to content

Commit

Permalink
added test for issue eclipse#6 StopsItsActivityAfterFailedAttemptToCo…
Browse files Browse the repository at this point in the history
…nnect
  • Loading branch information
codami committed Jan 16, 2017
1 parent 8cf9296 commit 15edf46
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions M2Mqtt.Test/MqttClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
using System.Threading;
using uPLibrary.Networking.M2Mqtt;
using NSubstitute;

Expand Down Expand Up @@ -57,5 +58,23 @@ public void ReceivingErrorOnChannelForwardedWhenConnectFails_Issue27()

messages.ShouldContain(channelErrorMessage);
}

[Test()]
public void StopsItsActivityAfterFailedAttemptToConnect_Issue6()
{
var channel = Substitute.For<IMqttNetworkChannel>();
channel.When((obj) => { obj.Receive(Arg.Any<byte[]>()); }).Do((obj) => { throw new IOException("channel error"); });

var client = new MqttClient(channel);

Assert.That(() => { client.Connect("client1"); }, Throws.Exception);

channel.Received(1).Connect(); // make sure the client used mocked channel
channel.ClearReceivedCalls();

Thread.Sleep(TimeSpan.FromSeconds(1)); // give it some time to accumulate Receive calls when defective

channel.DidNotReceive().Receive(Arg.Any<byte[]>());
}
}
}

0 comments on commit 15edf46

Please sign in to comment.