Skip to content

Commit 1231b44

Browse files
committed
Updated test to be consistent between runs.
1 parent 8e5b997 commit 1231b44

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ namespace EventHorizon.Blazor.TypeScript.Interop.Generator.Tests.Identifiers
22
{
33
using System.Collections.Generic;
44
using System.IO;
5+
using System.Threading.Tasks;
6+
using EventHorizon.Blazor.TypeScript.Interop.Generator.AstParser.Api;
7+
using EventHorizon.Blazor.TypeScript.Interop.Generator.AstParser.Model.Types;
58
using EventHorizon.Blazor.TypeScript.Interop.Generator.AstParser.NodeImpl;
69
using EventHorizon.Blazor.TypeScript.Interop.Generator.AstParser.SdcdImpl;
710
using EventHorizon.Blazor.TypeScript.Interop.Generator.Identifiers;
811
using EventHorizon.Blazor.TypeScript.Interop.Generator.Model.Statements;
912
using FluentAssertions;
13+
using Moq;
1014
using Xunit;
1115

1216
public class InterfaceResponseTypeIdentifierTests
@@ -365,5 +369,66 @@ bool expected
365369
actual.Should()
366370
.Be(expected);
367371
}
372+
373+
[Theory]
374+
[Trait("Category", "EdgeCase")]
375+
[InlineData(SyntaxKind.ClassDeclaration, false)]
376+
[InlineData(SyntaxKind.InterfaceDeclaration, true)]
377+
public void ShouldValidateAgainstCacheWhenDeclarationTypeIsUsed(
378+
string declarationType,
379+
bool found
380+
)
381+
{
382+
// Given
383+
var expected = 1;
384+
var identifierString = "identifier-string";
385+
var mockNode = new NodeMock
386+
{
387+
IdentifierStr = identifierString,
388+
};
389+
390+
var astMock = new Mock<AbstractSyntaxTree>();
391+
var rootNodeMock = new Mock<Node>();
392+
393+
astMock.Setup(
394+
mock => mock.RootNode
395+
).Returns(
396+
rootNodeMock.Object
397+
);
398+
399+
rootNodeMock.Setup(
400+
mock => mock.OfKind(
401+
declarationType
402+
)
403+
).Returns(
404+
new List<Node>
405+
{
406+
mockNode
407+
}
408+
);
409+
410+
// When
411+
var alias = new InterfaceResponseTypeIdentifierCached();
412+
var actual = alias.Identify(
413+
identifierString,
414+
astMock.Object
415+
);
416+
actual.Should().Be(found);
417+
418+
actual = alias.Identify(
419+
identifierString,
420+
astMock.Object
421+
);
422+
423+
// Then
424+
actual.Should().Be(found);
425+
426+
rootNodeMock.Verify(
427+
mock => mock.OfKind(
428+
declarationType
429+
),
430+
Times.Exactly(expected)
431+
);
432+
}
368433
}
369434
}

0 commit comments

Comments
 (0)