Skip to content

Commit 63b2824

Browse files
committed
Added to unit testing coverage.
Added Category Traits for No Trait tests.
1 parent d8a7fbe commit 63b2824

File tree

5 files changed

+106
-27
lines changed

5 files changed

+106
-27
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
namespace EventHorizon.Blazor.TypeScript.Interop.Generator.Tests.Identifiers
2+
{
3+
using System.Collections.Generic;
4+
using System.Threading.Tasks;
5+
using EventHorizon.Blazor.TypeScript.Interop.Generator.AstParser.Api;
6+
using EventHorizon.Blazor.TypeScript.Interop.Generator.AstParser.Model.Types;
7+
using EventHorizon.Blazor.TypeScript.Interop.Generator.Identifiers;
8+
using FluentAssertions;
9+
using Moq;
10+
using Xunit;
11+
12+
public class AliasTypeIdentifierCachedTests
13+
{
14+
[Fact]
15+
[Trait("Category", "Caching")]
16+
public async Task ShoudlOnlyReadFromASTOnceWhenCallingIdentifyAsSecondTime()
17+
{
18+
// Given
19+
var expected = 1;
20+
var identifierString = "identifier-string";
21+
var mockNode = new NodeMock
22+
{
23+
IdentifierStr = identifierString,
24+
};
25+
26+
var astMock = new Mock<AbstractSyntaxTree>();
27+
var rootNodeMock = new Mock<Node>();
28+
29+
astMock.Setup(
30+
mock => mock.RootNode
31+
).Returns(
32+
rootNodeMock.Object
33+
);
34+
35+
rootNodeMock.Setup(
36+
mock => mock.OfKind(
37+
SyntaxKind.TypeAliasDeclaration
38+
)
39+
).Returns(
40+
new List<Node>
41+
{
42+
mockNode
43+
}
44+
);
45+
46+
// When
47+
var alias = new AliasTypeIdentifierCached();
48+
var actual = alias.Identify(
49+
identifierString,
50+
astMock.Object
51+
);
52+
actual.Should().BeTrue();
53+
54+
actual = alias.Identify(
55+
identifierString,
56+
astMock.Object
57+
);
58+
59+
// Then
60+
actual.Should().BeTrue();
61+
62+
rootNodeMock.Verify(
63+
mock => mock.OfKind(
64+
SyntaxKind.TypeAliasDeclaration
65+
),
66+
Times.Exactly(expected)
67+
);
68+
}
69+
}
70+
}

Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/Identifiers/AliasTypeStatementIdentifierTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace EventHorizon.Blazor.TypeScript.Interop.Generator.Tests.Identifiers
1010
public class AliasTypeStatementIdentifierTests
1111
{
1212
[Fact]
13+
[Trait("Category", "EdgeCase")]
1314
public void ShouldReturnNullWhenNodeIsNotFound()
1415
{
1516
// Given
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace EventHorizon.Blazor.TypeScript.Interop.Generator.Tests.Identifiers
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using EventHorizon.Blazor.TypeScript.Interop.Generator.AstParser.Api;
6+
7+
public class NodeMock
8+
: Node
9+
{
10+
public Node Parent { get; }
11+
public Node First { get; }
12+
public Node Last { get; }
13+
public string IdentifierStr { get; set; }
14+
public string Kind { get; set; }
15+
public IEnumerable<Node> Modifiers { get; }
16+
public Node Type { get; }
17+
public Node ElementType { get; }
18+
public IEnumerable<Node> TypeParameters { get; set; }
19+
public IEnumerable<Node> HeritageClauses { get; }
20+
public IEnumerable<Node> Types { get; }
21+
public IEnumerable<Node> TypeArguments { get; }
22+
public IEnumerable<Node> Parameters { get; }
23+
public IEnumerable<Node> Children { get; }
24+
25+
public IEnumerable<Node> OfKind(string kind)
26+
{
27+
throw new NotImplementedException();
28+
}
29+
}
30+
}

Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/Identifiers/TypeIdentifyTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace EventHorizon.Blazor.TypeScript.Interop.Generator.Tests.Identifiers
1111
public class TypeIdentifyTests
1212
{
1313
[Fact]
14+
[Trait("Category", "EdgeCase")]
1415
public void ShouldReturnClassMetadataNameWhenNodeIsKindParameter()
1516
{
1617
// Given

Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/Identifiers/TypeParameterIdentifierTests.cs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace EventHorizon.Blazor.TypeScript.Interop.Generator.Tests.Identifiers
22
{
3-
using System;
43
using System.Collections.Generic;
54
using EventHorizon.Blazor.TypeScript.Interop.Generator.AstParser.Api;
65
using EventHorizon.Blazor.TypeScript.Interop.Generator.AstParser.Model.Types;
@@ -11,9 +10,10 @@ namespace EventHorizon.Blazor.TypeScript.Interop.Generator.Tests.Identifiers
1110
public class TypeParameterIdentifierTests
1211
{
1312
[Theory]
13+
[Trait("Category", "EdgeCase")]
1414
[InlineData(SyntaxKind.ClassDeclaration)]
1515
[InlineData(SyntaxKind.InterfaceDeclaration)]
16-
public void ShouldReturnListOfTypeParametersOnNodeWhenKindIsClassDeclaration(
16+
public void ShouldReturnListOfTypeParametersOnNodeWhenKindIsSyntaxKind(
1717
string kind
1818
)
1919
{
@@ -49,9 +49,10 @@ string kind
4949
}
5050

5151
[Theory]
52+
[Trait("Category", "EdgeCase")]
5253
[InlineData(SyntaxKind.ClassDeclaration)]
5354
[InlineData(SyntaxKind.InterfaceDeclaration)]
54-
public void ShouldReturnEmptyListWhenClassDeclarationTypeParametersAreNull(
55+
public void ShouldReturnEmptyListWhenTypeParametersAreNull(
5556
string kind
5657
)
5758
{
@@ -72,29 +73,5 @@ string kind
7273
// Then
7374
actual.Should().BeEmpty();
7475
}
75-
76-
public class NodeMock
77-
: Node
78-
{
79-
public Node Parent { get; }
80-
public Node First { get; }
81-
public Node Last { get; }
82-
public string IdentifierStr { get; set; }
83-
public string Kind { get; set; }
84-
public IEnumerable<Node> Modifiers { get; }
85-
public Node Type { get; }
86-
public Node ElementType { get; }
87-
public IEnumerable<Node> TypeParameters { get; set; }
88-
public IEnumerable<Node> HeritageClauses { get; }
89-
public IEnumerable<Node> Types { get; }
90-
public IEnumerable<Node> TypeArguments { get; }
91-
public IEnumerable<Node> Parameters { get; }
92-
public IEnumerable<Node> Children { get; }
93-
94-
public IEnumerable<Node> OfKind(string kind)
95-
{
96-
throw new NotImplementedException();
97-
}
98-
}
9976
}
10077
}

0 commit comments

Comments
 (0)