-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from gregsdennis/tests
Add Tests for provided solutions
- Loading branch information
Showing
9 changed files
with
163 additions
and
5 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
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,19 @@ | ||
name: Verify solutions | ||
on: | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: restore submodules | ||
run: git submodule update --init | ||
- name: Setup .NET Core | ||
uses: actions/setup-dotnet@v2 | ||
with: | ||
dotnet-version: 8.0.x | ||
- name: Install dependencies | ||
run: dotnet restore | ||
- name: Test | ||
run: dotnet test LearnJsonEverything.sln -c Release --no-restore |
34 changes: 34 additions & 0 deletions
34
LearnJsonEverything.Tests/LearnJsonEverything.Tests.csproj
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,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\LearnJsonEverything\wwwroot\data\lessons\*.yaml"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="NUnit" Version="3.14.0" /> | ||
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\LearnJsonEverything\LearnJsonEverything.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="NUnit.Framework" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,54 @@ | ||
using System.Text.Json; | ||
using LearnJsonEverything.Services; | ||
using LearnJsonEverything.Services.Runners; | ||
using Yaml2JsonNode; | ||
|
||
namespace LearnJsonEverything.Tests; | ||
|
||
public class ProvidedSolutionTests | ||
{ | ||
private static JsonSerializerOptions SerializerOptions = | ||
new() | ||
{ | ||
PropertyNameCaseInsensitive = true | ||
}; | ||
|
||
[OneTimeSetUp] | ||
public void Setup() | ||
{ | ||
CompilationHelpers.TestOnly_SetReferences(ReferenceLoader.Load()); | ||
} | ||
|
||
private static LessonPlan LoadLessonPlan(string filename) | ||
{ | ||
var yamlText = File.ReadAllText(filename); | ||
var yaml = YamlSerializer.Parse(yamlText); | ||
var json = yaml.First().ToJsonNode(); | ||
return json.Deserialize<LessonPlan>(SerializerOptions)!; | ||
} | ||
|
||
public static IEnumerable<TestCaseData> SchemaLessons | ||
{ | ||
get | ||
{ | ||
var lessonPlan = LoadLessonPlan("schema.yaml"); | ||
return lessonPlan.Select(x => | ||
{ | ||
x.UserCode = x.Solution; | ||
return new TestCaseData(x) { TestName = x.Title }; | ||
}); | ||
} | ||
} | ||
|
||
[TestCaseSource(nameof(SchemaLessons))] | ||
public void Schema(LessonData lesson) | ||
{ | ||
var results = SchemaRunner.Run(lesson); | ||
|
||
foreach (var result in results) | ||
{ | ||
Console.WriteLine(result); | ||
Assert.That(result, Does.StartWith(Iconography.SuccessIcon)); | ||
} | ||
} | ||
} |
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,43 @@ | ||
using System.Text.Json.Nodes; | ||
using Json.Schema; | ||
using Microsoft.CodeAnalysis; | ||
using Yaml2JsonNode; | ||
|
||
namespace LearnJsonEverything.Tests; | ||
|
||
public static class ReferenceLoader | ||
{ | ||
private class NullRunner : ILessonRunner<int> | ||
{ | ||
public int Run(JsonObject context) => 0; | ||
} | ||
|
||
static ReferenceLoader() | ||
{ | ||
// force some assemblies to load | ||
SchemaRegistry.Global.Fetch = null!; | ||
_ = YamlSerializer.Parse(string.Empty); | ||
_ = new NullRunner(); | ||
} | ||
|
||
public static MetadataReference[] Load() | ||
{ | ||
var refs = AppDomain.CurrentDomain.GetAssemblies(); | ||
var assemblies = refs | ||
.Where(x => !x.IsDynamic) | ||
.OrderBy(x => x.FullName) | ||
.ToArray(); | ||
|
||
var references = new MetadataReference[assemblies.Length]; | ||
int i = 0; | ||
foreach (var assembly in assemblies) | ||
{ | ||
Console.WriteLine($"Loading {assembly.FullName}..."); | ||
references[i] = MetadataReference.CreateFromFile(assembly.Location); | ||
i++; | ||
} | ||
|
||
return references; | ||
} | ||
|
||
} |
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
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