Test connecting with uri

This commit is contained in:
Paul Pacheco 2019-12-23 16:44:40 -06:00
parent 1eff4ed4e6
commit 3e0802607a

View File

@ -1,4 +1,5 @@
using System.Collections; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using NSubstitute; using NSubstitute;
using NUnit.Framework; using NUnit.Framework;
@ -57,5 +58,40 @@ public void TestConnect()
transport1.DidNotReceive().ClientConnect(Arg.Any<string>()); transport1.DidNotReceive().ClientConnect(Arg.Any<string>());
transport2.Received().ClientConnect("some.server.com"); transport2.Received().ClientConnect("some.server.com");
} }
// A Test behaves as an ordinary method
[Test]
public void TestConnectFirstUri()
{
Uri uri = new Uri("tcp://some.server.com");
transport1.Available().Returns(true);
transport2.Available().Returns(true);
transport.ClientConnect(uri);
transport1.Received().ClientConnect(uri);
transport2.DidNotReceive().ClientConnect(uri);
}
// A Test behaves as an ordinary method
[Test]
public void TestConnectSecondUri()
{
Uri uri = new Uri("ws://some.server.com");
transport1.Available().Returns(true);
// first transport does not support websocket
transport1
.When(x => x.ClientConnect(uri))
.Do(x => { throw new ArgumentException("Scheme not supported"); });
transport2.Available().Returns(true);
transport.ClientConnect(uri);
transport2.Received().ClientConnect(uri);
}
} }
} }