diff --git a/src/SystemTests/XApiClientTestBase.cs b/src/SystemTests/XApiClientTestBase.cs index 8f8afdd..8695444 100644 --- a/src/SystemTests/XApiClientTestBase.cs +++ b/src/SystemTests/XApiClientTestBase.cs @@ -42,13 +42,13 @@ public string? MessageFolder _messageFolder = value; if (value == null) { - Client.ApiConnector.MessageReceived -= Connector_MessageReceived; - Client.ApiConnector.MessageSent -= Connector_MessageSent; + Client.ApiConnector.Connector.MessageReceived -= Connector_MessageReceived; + Client.ApiConnector.Connector.MessageSent -= Connector_MessageSent; } else { - Client.ApiConnector.MessageReceived += Connector_MessageReceived; - Client.ApiConnector.MessageSent += Connector_MessageSent; + Client.ApiConnector.Connector.MessageReceived += Connector_MessageReceived; + Client.ApiConnector.Connector.MessageSent += Connector_MessageSent; } } } diff --git a/src/UnitTests/XApiClientTest.cs b/src/UnitTests/XApiClientTest.cs index 44650f1..2e8e777 100644 --- a/src/UnitTests/XApiClientTest.cs +++ b/src/UnitTests/XApiClientTest.cs @@ -1,15 +1,44 @@ +using NSubstitute; +using System.Diagnostics; + namespace Xtb.XApi.UnitTests; public class XApiClientTest { + private IClient _requestingConnector; + private IClient _streamingConnector; + private IXApiClient _xclient; + + public XApiClientTest() + { + _requestingConnector = Substitute.For(); + _streamingConnector = Substitute.For(); + _xclient = new XApiClient(new ApiConnector(_requestingConnector, new StreamingApiConnector(_streamingConnector))); + } + [Fact] public void Create() { - var client = XApiClient.Create("81.2.190.163", 5112, 5113); + var xclient = XApiClient.Create("81.2.190.163", 5112, 5113); + + Assert.NotNull(xclient.ApiConnector); + Assert.NotNull(xclient.ApiConnector.Endpoint); + Assert.Equal("81.2.190.163", xclient.ApiConnector.Endpoint.Address.ToString()); + Assert.Null(xclient.AccountId); + } + + [Fact] + public void SendCommandsWithDelay() + { + _requestingConnector.SendMessageWaitResponse(Arg.Any()).Returns("{}"); + + var stopwatch = Stopwatch.StartNew(); + + _xclient.GetSymbol("US500"); + _xclient.GetSymbol("US500"); + + stopwatch.Stop(); + Assert.True(stopwatch.Elapsed.TotalMilliseconds > 400); - Assert.NotNull(client.ApiConnector); - Assert.NotNull(client.ApiConnector.Endpoint); - Assert.Equal("81.2.190.163", client.ApiConnector.Endpoint.Address.ToString()); - Assert.Null(client.AccountId); } } \ No newline at end of file