-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
namespace AzureMapsControl.Components.Tests.Runtime | ||
{ | ||
using System.Threading.Tasks; | ||
using AzureMapsControl.Components.Runtime; | ||
|
||
using Microsoft.Extensions.Logging; | ||
using Microsoft.JSInterop; | ||
|
||
using Moq; | ||
|
||
using Xunit; | ||
|
||
public class MapJsRuntimeTests | ||
{ | ||
private readonly Mock<IJSRuntime> _jsRuntimeMock = new Mock<IJSRuntime>(); | ||
private readonly Mock<ILogger<MapJsRuntime>> _loggerMock = new Mock<ILogger<MapJsRuntime>>(); | ||
|
||
private readonly MapJsRuntime _sut; | ||
|
||
public MapJsRuntimeTests() => _sut = new(_jsRuntimeMock.Object, _loggerMock.Object); | ||
|
||
[Fact] | ||
public async Task Should_InvokeVoidAsync() | ||
{ | ||
var identifier = "identifier"; | ||
var args = new object[] { 1, 2 }; | ||
|
||
await _sut.InvokeVoidAsync(identifier, args); | ||
|
||
_jsRuntimeMock.Verify(runtime => runtime.InvokeAsync<Microsoft.JSInterop.Infrastructure.IJSVoidResult>(identifier, args), Times.Once); | ||
_jsRuntimeMock.VerifyNoOtherCalls(); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_InvokeAsync() | ||
{ | ||
var identifier = "identifier"; | ||
var args = new object[] { 1, 2 }; | ||
var expected = "expected"; | ||
_jsRuntimeMock.Setup(runtime => runtime.InvokeAsync<string>(identifier, args)).ReturnsAsync(expected).Verifiable(); | ||
|
||
var result = await _sut.InvokeAsync<string>(identifier, args); | ||
|
||
Assert.Equal(expected, result); | ||
_jsRuntimeMock.Verify(); | ||
_jsRuntimeMock.VerifyNoOtherCalls(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
namespace AzureMapsControl.Components.Tests.Traffic | ||
{ | ||
using AzureMapsControl.Components.Tests.Json; | ||
using AzureMapsControl.Components.Traffic; | ||
|
||
using Xunit; | ||
|
||
public class TrafficOptionsJsonConverterTests : JsonConverterTests<TrafficOptions> | ||
{ | ||
public TrafficOptionsJsonConverterTests() : base(new TrafficOptionsJsonConverter()) { } | ||
|
||
[Fact] | ||
public void Should_ReadTrafficFlow() | ||
{ | ||
var json = "{" | ||
+ "\"flow\":\"" + TrafficFlow.Relative.ToString() + "\"" | ||
+ "}"; | ||
var result = Read(json); | ||
Assert.Equal(TrafficFlow.Relative, result.Flow); | ||
Assert.Null(result.Incidents); | ||
} | ||
|
||
[Fact] | ||
public void Should_ReadIncidents() | ||
{ | ||
var json = "{" | ||
+ "\"incidents\":true" | ||
+ "}"; | ||
var result = Read(json); | ||
Assert.True(result.Incidents); | ||
} | ||
|
||
[Fact] | ||
public void Should_ReadTrafficOptions() | ||
{ | ||
var json = "{" | ||
+ "\"flow\":\"" + TrafficFlow.Relative.ToString() + "\"," | ||
+ "\"incidents\":true" | ||
+ "}"; | ||
var result = Read(json); | ||
Assert.Equal(TrafficFlow.Relative, result.Flow); | ||
Assert.True(result.Incidents); | ||
} | ||
|
||
[Fact] | ||
public async void Should_WriteTrafficOptions() | ||
Check warning on line 46 in tests/AzureMapsControl.Components.Tests/Traffic/TrafficOptions.cs
|
||
{ | ||
var trafficOptions = new TrafficOptions { | ||
Flow = TrafficFlow.Relative | ||
}; | ||
|
||
var expectedJson = "{" | ||
+ "\"flow\":\"" + trafficOptions.Flow.ToString() + "\"" | ||
+ "}"; | ||
|
||
TestAndAssertWrite(trafficOptions, expectedJson); | ||
} | ||
|
||
[Fact] | ||
public async void Should_WriteTrafficOptions_WithIncidents() | ||
Check warning on line 60 in tests/AzureMapsControl.Components.Tests/Traffic/TrafficOptions.cs
|
||
{ | ||
var trafficOptions = new TrafficOptions { | ||
Flow = TrafficFlow.Relative, | ||
Incidents = true | ||
}; | ||
|
||
var expectedJson = "{" | ||
+ "\"flow\":\"" + trafficOptions.Flow.ToString() + "\"," | ||
+ "\"incidents\":true" | ||
+ "}"; | ||
|
||
TestAndAssertWrite(trafficOptions, expectedJson); | ||
} | ||
} | ||
} |