Skip to content

Commit 8b88fe9

Browse files
committed
Minor backtest API changes
1 parent 60e88cc commit 8b88fe9

File tree

3 files changed

+23
-108
lines changed

3 files changed

+23
-108
lines changed

Api/Api.cs

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -633,79 +633,6 @@ public RestResponse DeleteBacktest(int projectId, string backtestId)
633633
return result;
634634
}
635635

636-
/// <summary>
637-
/// List all the tags for a backtest
638-
/// </summary>
639-
/// <param name="projectId">Project for the backtest we want to update</param>
640-
/// <param name="backtestId">Backtest id we want to update</param>
641-
/// <returns><see cref="BacktestTags"/></returns>
642-
public BacktestTags GetBacktestTags(int projectId, string backtestId)
643-
{
644-
var request = new RestRequest("backtests/tags/list", Method.POST)
645-
{
646-
RequestFormat = DataFormat.Json
647-
};
648-
649-
request.AddParameter("application/json", JsonConvert.SerializeObject(new
650-
{
651-
projectId,
652-
backtestId,
653-
}), ParameterType.RequestBody);
654-
655-
ApiConnection.TryRequest(request, out BacktestTags result);
656-
return result;
657-
}
658-
659-
/// <summary>
660-
/// Add new tags to a backtest
661-
/// </summary>
662-
/// <param name="projectId">Project for the backtest we want to update</param>
663-
/// <param name="backtestId">Backtest id we want to update</param>
664-
/// <param name="tags">The tags to add to the backtest</param>
665-
/// <returns><see cref="RestResponse"/></returns>
666-
public RestResponse AddBacktestTags(int projectId, string backtestId, IReadOnlyCollection<string> tags)
667-
{
668-
var request = new RestRequest("backtests/tags/create", Method.POST)
669-
{
670-
RequestFormat = DataFormat.Json
671-
};
672-
673-
request.AddParameter("application/json", JsonConvert.SerializeObject(new
674-
{
675-
projectId,
676-
backtestId,
677-
tags
678-
}), ParameterType.RequestBody);
679-
680-
ApiConnection.TryRequest(request, out RestResponse result);
681-
return result;
682-
}
683-
684-
/// <summary>
685-
/// Deletes tags from a backtest
686-
/// </summary>
687-
/// <param name="projectId">Project for the backtest we want to update</param>
688-
/// <param name="backtestId">Backtest id we want to update</param>
689-
/// <param name="tags">The tags to delete from the backtest</param>
690-
/// <returns><see cref="RestResponse"/></returns>
691-
public RestResponse DeleteBacktestTags(int projectId, string backtestId, IReadOnlyCollection<string> tags)
692-
{
693-
var request = new RestRequest("backtests/tags/delete", Method.POST)
694-
{
695-
RequestFormat = DataFormat.Json
696-
};
697-
698-
request.AddParameter("application/json", JsonConvert.SerializeObject(new
699-
{
700-
projectId,
701-
backtestId,
702-
tags
703-
}), ParameterType.RequestBody);
704-
705-
ApiConnection.TryRequest(request, out RestResponse result);
706-
return result;
707-
}
708-
709636
/// <summary>
710637
/// Updates the tags collection for a backtest
711638
/// </summary>

Common/Api/Backtest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ public class Backtest : RestResponse
110110
/// </summary>
111111
[JsonProperty(PropertyName = "parameterSet")]
112112
public ParameterSet ParameterSet { get; set; }
113+
114+
/// <summary>
115+
/// Collection of tags for the backtest
116+
/// </summary>
117+
[JsonProperty(PropertyName = "tags")]
118+
public List<string> Tags { get; set; }
113119
}
114120

115121
/// <summary>

Tests/Api/ProjectTests.cs

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -363,48 +363,30 @@ public void UpdateBacktestName()
363363
}
364364

365365
[Test]
366-
public void AddAndDeleteBacktestTags()
366+
public void UpdatesBacktestTags()
367367
{
368368
// We will be using the existing TestBacktest for this test
369369
var tags = new List<string> { "tag1", "tag2", "tag3" };
370370

371371
// Add the tags to the backtest
372-
var addTagsResult = ApiClient.AddBacktestTags(TestProject.ProjectId, TestBacktest.BacktestId, tags);
372+
var addTagsResult = ApiClient.UpdateBacktestTags(TestProject.ProjectId, TestBacktest.BacktestId, tags);
373373
Assert.IsTrue(addTagsResult.Success, $"Error adding tags to backtest:\n {string.Join("\n ", addTagsResult.Errors)}");
374374

375-
// Read the backtest tags and verify they were added
376-
var readTagsResult = ApiClient.GetBacktestTags(TestProject.ProjectId, TestBacktest.BacktestId);
377-
Assert.IsTrue(readTagsResult.Success, $"Error reading backtest tags:\n {string.Join("\n ", readTagsResult.Errors)}");
378-
CollectionAssert.AreEquivalent(tags, readTagsResult.Tags);
379-
380-
// Delete one tag from the backtest
381-
var deleteTagResult = ApiClient.DeleteBacktestTags(TestProject.ProjectId, TestBacktest.BacktestId, tags.Take(1).ToList());
382-
Assert.IsTrue(deleteTagResult.Success, $"Error deleting tag from backtest:\n {string.Join("\n ", deleteTagResult.Errors)}");
383-
384-
// Read the backtest tags and verify the tag was deleted
385-
readTagsResult = ApiClient.GetBacktestTags(TestProject.ProjectId, TestBacktest.BacktestId);
386-
Assert.IsTrue(readTagsResult.Success, $"Error reading backtest tags:\n {string.Join("\n ", readTagsResult.Errors)}");
387-
var remainingTags = tags.Skip(1).ToList();
388-
CollectionAssert.AreEquivalent(remainingTags, readTagsResult.Tags);
389-
390-
// Delete the remaining tags from the backtest
391-
deleteTagResult = ApiClient.DeleteBacktestTags(TestProject.ProjectId, TestBacktest.BacktestId, remainingTags);
392-
Assert.IsTrue(deleteTagResult.Success, $"Error deleting tag from backtest:\n {string.Join("\n ", deleteTagResult.Errors)}");
393-
394-
// Read the backtest tags and verify the tags were deleted
395-
readTagsResult = ApiClient.GetBacktestTags(TestProject.ProjectId, TestBacktest.BacktestId);
396-
Assert.IsTrue(readTagsResult.Success, $"Error reading backtest tags:\n {string.Join("\n ", readTagsResult.Errors)}");
397-
CollectionAssert.IsEmpty(readTagsResult.Tags);
398-
399-
// Override the whole set of tags
400-
var newTags = new List<string> { "tag4", "tag5", "tag6" };
401-
var updateTagsResult = ApiClient.UpdateBacktestTags(TestProject.ProjectId, TestBacktest.BacktestId, newTags);
402-
Assert.IsTrue(updateTagsResult.Success, $"Error updating backtest tags:\n {string.Join("\n ", updateTagsResult.Errors)}");
403-
404-
// Read the backtest tags and verify the tags were updated
405-
readTagsResult = ApiClient.GetBacktestTags(TestProject.ProjectId, TestBacktest.BacktestId);
406-
Assert.IsTrue(readTagsResult.Success, $"Error reading backtest tags:\n {string.Join("\n ", readTagsResult.Errors)}");
407-
CollectionAssert.AreEquivalent(newTags, readTagsResult.Tags);
375+
// Read the backtest and verify the tags were added
376+
var backtestsResult = ApiClient.ListBacktests(TestProject.ProjectId);
377+
Assert.IsTrue(backtestsResult.Success, $"Error getting backtests:\n {string.Join("\n ", backtestsResult.Errors)}");
378+
Assert.AreEqual(1, backtestsResult.Backtests.Count);
379+
CollectionAssert.AreEquivalent(tags, backtestsResult.Backtests[0].Tags);
380+
381+
// Remove all tags from the backtest
382+
var deleteTagsResult = ApiClient.UpdateBacktestTags(TestProject.ProjectId, TestBacktest.BacktestId, new List<string>());
383+
Assert.IsTrue(deleteTagsResult.Success, $"Error deleting tags from backtest:\n {string.Join("\n ", deleteTagsResult.Errors)}");
384+
385+
// Read the backtest and verify the tags were deleted
386+
backtestsResult = ApiClient.ListBacktests(TestProject.ProjectId);
387+
Assert.IsTrue(backtestsResult.Success, $"Error getting backtests:\n {string.Join("\n ", backtestsResult.Errors)}");
388+
Assert.AreEqual(1, backtestsResult.Backtests.Count);
389+
Assert.AreEqual(0, backtestsResult.Backtests[0].Tags.Count);
408390
}
409391

410392
private static string GetTimestamp()

0 commit comments

Comments
 (0)