Skip to content

Commit 331adf1

Browse files
Fix failing protobuf test
1 parent f258a0a commit 331adf1

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

DataLibrary/MyCustomDataType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace DataLibrary
2727
/// <summary>
2828
/// Example custom data type
2929
/// </summary>
30+
[ProtoContract(SkipConstructor = true)]
3031
public class MyCustomDataType : BaseData
3132
{
3233
/// <summary>

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ Once it is cloned locally, should be able to successfully build the solution, ru
3030

3131
#### Usage
3232

33-
- Once the repository is forked, the existing example implementation should be adjusted, in the fork, to create a new data type for a particular data set.
34-
- Converter and downloader scripts should be developed following the [examples in this repository](https://github.com/QuantConnect/LeanDataSdk/tree/master/DataConverterScript).
35-
36-
The script should be provided to `QuantConnect` as well as the fork repository at a particual commit.
33+
- Once the repository is forked, the existing example implementation should be adjusted to create a new data type for a particular data set.
34+
- The Assembly name and data type have to be changed since they should be unique.
35+
- Converter and downloader scripts should be developed following the [examples in this repository](https://github.com/QuantConnect/LeanDataSdk/tree/master/DataConverterScript). These script should be provided to `QuantConnect` as well as the fork repository at a particual commit.
3736

3837
### User guide
3938

Tests/MyCustomDataTypeTests.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
*/
1616

1717
using System;
18+
using ProtoBuf;
1819
using System.IO;
20+
using System.Linq;
1921
using DataLibrary;
2022
using QuantConnect;
2123
using ProtoBuf.Meta;
@@ -39,26 +41,23 @@ public void JsonRoundTrip()
3941
AssertAreEqual(expected, result);
4042
}
4143

42-
[Test, Ignore("TODO: Failing")]
44+
[Test]
4345
public void ProtobufRoundTrip()
4446
{
4547
var expected = CreateNewInstance();
4648
var type = expected.GetType();
4749

48-
var model = RuntimeTypeModel.Create();
49-
var baseType = model.Add(typeof(BaseData), true);
50-
model.Add(type, true);
51-
baseType.AddSubType(2000, type);
50+
RuntimeTypeModel.Default[typeof(BaseData)].AddSubType(2000, type);
5251

5352
using (var stream = new MemoryStream())
5453
{
55-
model.Serialize(stream, expected);
54+
Serializer.Serialize(stream, expected);
5655

5756
stream.Position = 0;
5857

59-
var result = model.Deserialize(type, stream);
58+
var result = Serializer.Deserialize(type, stream);
6059

61-
AssertAreEqual(expected, result);
60+
AssertAreEqual(expected, result, filterByCustomAttributes: true);
6261
}
6362
}
6463

@@ -71,11 +70,15 @@ public void Clone()
7170
AssertAreEqual(expected, result);
7271
}
7372

74-
private void AssertAreEqual(object expected, object result)
73+
private void AssertAreEqual(object expected, object result, bool filterByCustomAttributes = false)
7574
{
7675
foreach (var propertyInfo in expected.GetType().GetProperties())
7776
{
78-
Assert.AreEqual(propertyInfo.GetValue(expected), propertyInfo.GetValue(result));
77+
// we skip Symbol which isn't protobuffed
78+
if (filterByCustomAttributes && propertyInfo.CustomAttributes.Count() != 0)
79+
{
80+
Assert.AreEqual(propertyInfo.GetValue(expected), propertyInfo.GetValue(result));
81+
}
7982
}
8083
foreach (var fieldInfo in expected.GetType().GetFields())
8184
{

0 commit comments

Comments
 (0)