Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jirikostiha committed Dec 28, 2024
1 parent 71d9899 commit adf58f0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/SystemTests/XApiClientTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
39 changes: 34 additions & 5 deletions src/UnitTests/XApiClientTest.cs
Original file line number Diff line number Diff line change
@@ -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<IClient>();
_streamingConnector = Substitute.For<IClient>();
_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<string>()).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);
}
}

0 comments on commit adf58f0

Please sign in to comment.