Skip to content

Commit 9b6ddca

Browse files
committed
update tests
1 parent 20a58b3 commit 9b6ddca

3 files changed

Lines changed: 166 additions & 104 deletions

File tree

tests/MyCustomDataTypeTests.cs

Lines changed: 0 additions & 99 deletions
This file was deleted.
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/*
2+
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3+
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*
15+
*/
16+
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Linq;
20+
using Newtonsoft.Json;
21+
using NUnit.Framework;
22+
using QuantConnect.Data;
23+
using QuantConnect.DataSource;
24+
25+
namespace QuantConnect.DataLibrary.Tests
26+
{
27+
[TestFixture]
28+
public class RegalyticsRegulatoryArticleTests
29+
{
30+
[Test]
31+
public void JsonRoundTrip()
32+
{
33+
var expected = CreateNewInstance();
34+
var type = expected.GetType();
35+
var serialized = JsonConvert.SerializeObject(expected);
36+
var result = JsonConvert.DeserializeObject(serialized, type);
37+
38+
AssertAreEqual(expected, result);
39+
}
40+
41+
[Test]
42+
public void Clone()
43+
{
44+
var expected = CreateNewInstance();
45+
var result = expected.Clone();
46+
47+
AssertAreEqual(expected, result);
48+
}
49+
50+
[Test]
51+
public void CloneCollection()
52+
{
53+
var expected = CreateNewCollectionInstance();
54+
var result = expected.Clone();
55+
56+
AssertAreEqual(expected, result);
57+
}
58+
59+
private void AssertAreEqual(object expected, object result, bool filterByCustomAttributes = false)
60+
{
61+
foreach (var propertyInfo in expected.GetType().GetProperties())
62+
{
63+
// we skip Symbol which isn't protobuffed
64+
if (filterByCustomAttributes && propertyInfo.CustomAttributes.Count() != 0)
65+
{
66+
Assert.AreEqual(propertyInfo.GetValue(expected), propertyInfo.GetValue(result));
67+
}
68+
}
69+
foreach (var fieldInfo in expected.GetType().GetFields())
70+
{
71+
Assert.AreEqual(fieldInfo.GetValue(expected), fieldInfo.GetValue(result));
72+
}
73+
}
74+
75+
private BaseData CreateNewInstance()
76+
{
77+
return new RegalyticsRegulatoryArticle
78+
{
79+
Symbol = Symbol.Empty,
80+
Time = DateTime.Today,
81+
DataType = MarketDataType.Base,
82+
83+
Id = 0,
84+
Title = "string",
85+
Summary = "string",
86+
Status = "string",
87+
Classification = "string",
88+
FilingType = "string",
89+
InFederalRegister = true,
90+
FederalRegisterNumber = "string",
91+
ProposedCommentsDueDate = DateTime.MinValue,
92+
OriginalPublicationDate = DateTime.MinValue,
93+
FederalRegisterPublicationDate = DateTime.MinValue,
94+
RuleEffectiveDate = DateTime.MinValue,
95+
LatestUpdate = DateTime.MinValue,
96+
AlertType = "string",
97+
States = new Dictionary<string, List<string>> { {"string", new List<string>{"string"}} },
98+
Agencies = new List<string>{"string"},
99+
AnnouncementUrl = "string",
100+
CreatedAt = DateTime.MinValue
101+
};
102+
}
103+
104+
private BaseData CreateNewCollectionInstance()
105+
{
106+
return new RegalyticsRegulatoryArticles
107+
{
108+
new RegalyticsRegulatoryArticle
109+
{
110+
Symbol = Symbol.Empty,
111+
Time = DateTime.Today,
112+
DataType = MarketDataType.Base,
113+
114+
Id = 0,
115+
Title = "string",
116+
Summary = "string",
117+
Status = "string",
118+
Classification = "string",
119+
FilingType = "string",
120+
InFederalRegister = true,
121+
FederalRegisterNumber = "string",
122+
ProposedCommentsDueDate = DateTime.MinValue,
123+
OriginalPublicationDate = DateTime.MinValue,
124+
FederalRegisterPublicationDate = DateTime.MinValue,
125+
RuleEffectiveDate = DateTime.MinValue,
126+
LatestUpdate = DateTime.MinValue,
127+
AlertType = "string",
128+
States = new Dictionary<string, List<string>> { {"string", new List<string>{"string"}} },
129+
Agencies = new List<string>{"string"},
130+
AnnouncementUrl = "string",
131+
CreatedAt = DateTime.MinValue
132+
},
133+
new RegalyticsRegulatoryArticle
134+
{
135+
Symbol = Symbol.Empty,
136+
Time = DateTime.Today,
137+
DataType = MarketDataType.Base,
138+
139+
Id = 0,
140+
Title = "string",
141+
Summary = "string",
142+
Status = "string",
143+
Classification = "string",
144+
FilingType = "string",
145+
InFederalRegister = true,
146+
FederalRegisterNumber = "string",
147+
ProposedCommentsDueDate = DateTime.MinValue,
148+
OriginalPublicationDate = DateTime.MinValue,
149+
FederalRegisterPublicationDate = DateTime.MinValue,
150+
RuleEffectiveDate = DateTime.MinValue,
151+
LatestUpdate = DateTime.MinValue,
152+
AlertType = "string",
153+
States = new Dictionary<string, List<string>> { {"string", new List<string>{"string"}} },
154+
Agencies = new List<string>{"string"},
155+
AnnouncementUrl = "string",
156+
CreatedAt = DateTime.MinValue
157+
}
158+
};
159+
}
160+
}
161+
}

tests/Tests.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net5.0</TargetFramework>
3+
<TargetFramework>net6.0</TargetFramework>
44
<RootNamespace>QuantConnect.DataLibrary.Tests</RootNamespace>
55
</PropertyGroup>
66
<ItemGroup>
7-
<Compile Include="..\Demonstration.cs" Link="Demonstration.cs" />
7+
<Compile Include="..\RegalyticsRegulatoryArticlesDataAlgorithm.cs" Link="RegalyticsRegulatoryArticlesDataAlgorithm.cs" />
8+
<Content Include="..\RegalyticsRegulatoryArticlesDataAlgorithm.py" Link="RegalyticsRegulatoryArticlesDataAlgorithm.py" />
89
</ItemGroup>
910
<ItemGroup>
10-
<PackageReference Include="protobuf-net" Version="3.0.29" />
11-
<PackageReference Include="NUnit" Version="3.13.1" />
12-
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
11+
<PackageReference Include="NUnit" Version="3.13.3" />
12+
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1">
1313
<PrivateAssets>all</PrivateAssets>
1414
</PackageReference>
1515
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />

0 commit comments

Comments
 (0)