-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix interface method/property handling
- Add missing interface method/property handling when they had no access modifiers. Adding new unit tests
- Loading branch information
1 parent
4e8b435
commit 31803ff
Showing
3 changed files
with
207 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using NUnit.Framework; | ||
using QuantConnectStubsGenerator.Model; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace QuantConnectStubsGenerator.Tests | ||
{ | ||
[TestFixture] | ||
public class GeneratorTests | ||
{ | ||
[TestCase("public", true)] | ||
[TestCase("protected", true)] | ||
[TestCase("", false)] | ||
[TestCase("private", false)] | ||
public void Interfaces(string interfaceModifier, bool expected) | ||
{ | ||
var testGenerator = new TestGenerator | ||
{ | ||
Files = new() | ||
{ | ||
{ "Test.cs", $@" | ||
using System; | ||
namespace QuantConnect.Benchmarks | ||
{{ | ||
/// <summary> | ||
/// Specifies how to compute a benchmark for an algorithm | ||
/// </summary> | ||
{interfaceModifier} interface IBenchmark | ||
{{ | ||
/// <summary> | ||
/// Evaluates this benchmark at the specified time | ||
/// </summary> | ||
/// <param name=""time"">The time to evaluate the benchmark at</param> | ||
/// <returns>The value of the benchmark at the specified time</returns> | ||
decimal Evaluate(DateTime time); | ||
DateTime TestProperty {{get;}} | ||
}} | ||
}}" } | ||
} | ||
}; | ||
|
||
var result = testGenerator.GenerateModelsPublic(); | ||
|
||
var namespaces = result.GetNamespaces().ToList(); | ||
Assert.AreEqual(2, namespaces.Count); | ||
|
||
var baseNameSpace = namespaces.Single(x => x.Name == "QuantConnect"); | ||
var benchmarksNameSpace = namespaces.Single(x => x.Name == "QuantConnect.Benchmarks"); | ||
|
||
if (!expected) | ||
{ | ||
Assert.AreEqual(0, benchmarksNameSpace.GetClasses().Count()); | ||
return; | ||
} | ||
var benchmark = benchmarksNameSpace.GetClasses().Single(); | ||
|
||
Assert.AreEqual("Evaluate", benchmark.Methods.Single().Name); | ||
Assert.IsFalse(string.IsNullOrEmpty(benchmark.Methods.Single().Summary)); | ||
|
||
Assert.AreEqual("TestProperty", benchmark.Properties.Single().Name); | ||
Assert.IsTrue(string.IsNullOrEmpty(benchmark.Properties.Single().Summary)); | ||
} | ||
|
||
private class TestGenerator : Generator | ||
{ | ||
public Dictionary<string, string> Files { get; set; } | ||
public TestGenerator() : base("/", "/", "/") | ||
{ | ||
} | ||
|
||
protected override IEnumerable<SyntaxTree> GetSyntaxTrees() | ||
{ | ||
foreach (var fileContent in Files) | ||
{ | ||
yield return CSharpSyntaxTree.ParseText(fileContent.Value, path: fileContent.Key); | ||
} | ||
} | ||
|
||
public ParseContext GenerateModelsPublic() | ||
{ | ||
ParseContext context = new(); | ||
|
||
base.GenerateModels(context); | ||
|
||
return context; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters