Skip to content

Commit

Permalink
Add null check for API data folder (QuantConnect#5774)
Browse files Browse the repository at this point in the history
- Api.Initialize will not throw for null data folder. Adding unit test
  • Loading branch information
Martin-Molinero authored Jul 16, 2021
1 parent 522fe14 commit f75e81b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Api/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class Api : IApi, IDownloadProvider
public virtual void Initialize(int userId, string token, string dataFolder)
{
ApiConnection = new ApiConnection(userId, token);
_dataFolder = dataFolder.Replace("\\", "/", StringComparison.InvariantCulture);
_dataFolder = dataFolder?.Replace("\\", "/", StringComparison.InvariantCulture);

//Allow proper decoding of orders from the API.
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
Expand Down
7 changes: 7 additions & 0 deletions Tests/Api/ApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ public void ApiWillAuthenticate_InvalidCredentials_Unsuccessfully()
Assert.IsFalse(api.Connected);
}

[Test]
public void NullDataFolder()
{
var api = new Api.Api();
Assert.DoesNotThrow(() => api.Initialize(TestAccount, "", null));
}

[TestCase("C:\\Data", "forex/oanda/daily/eurusd.zip")]
[TestCase("C:\\Data\\", "forex/oanda/daily/eurusd.zip")]
[TestCase("C:/Data/", "forex/oanda/daily/eurusd.zip")]
Expand Down

0 comments on commit f75e81b

Please sign in to comment.