Skip to content

Commit

Permalink
Handler implrovements
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Tacke committed Oct 10, 2021
1 parent 3d11e0a commit e1b8150
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 15 deletions.
17 changes: 8 additions & 9 deletions Meadow.TestSuite.Worker/Handlers/ResultsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@ public class ResultsHandler : RequestHandlerBase
[HttpGet]
public IActionResult GetResults()
{
Console.WriteLine("GET Results");

// TODO

return new JsonResult(MeadowApp.Worker.Results.GetResults());
}

[HttpGet("{testID}")]
public IActionResult GetResults(string testID)
{
Console.WriteLine("GET Results");

// TODO

return new JsonResult(MeadowApp.Worker.Results.GetResults(testID));
if (Guid.TryParse(testID, out Guid id))
{
return new JsonResult(MeadowApp.Worker.Results.GetResult(id));
}
else
{
return new JsonResult(MeadowApp.Worker.Results.GetResults(testID));
}
}
}
}
17 changes: 12 additions & 5 deletions Meadow.TestSuite.Worker/Handlers/TestsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@ public class TestsHandler : RequestHandlerBase
[HttpGet]
public IActionResult GetTests()
{
Console.WriteLine("GET Tests");
return new JsonResult(MeadowApp.Worker.Registry.GetTestNames());
}

// TODO:
[HttpGet("{testID}")]
public IActionResult GetTestInfo(string testID)
{
var info = MeadowApp.Worker.Provider.GetTest(testID);

if (info == null)
{
return new NotFoundResult();
}

return new JsonResult(MeadowApp.Worker.Registry.GetTestNames());
return new JsonResult(info);
}

[HttpPost("{testID}")]
public IActionResult RunTest(string testID)
{
Console.WriteLine("Post Test");

var result = MeadowApp.Worker.ExecuteTest(testID);

return new JsonResult(result);
Expand Down
56 changes: 56 additions & 0 deletions Meadow.TestSuite.Worker/Handlers/TimeHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Meadow.Foundation.Web.Maple.Server;
using Meadow.Foundation.Web.Maple.Server.Routing;
using System;
using System.IO;

namespace MeadowApp
{
public class TimeHandler : RequestHandlerBase
{
internal class TimeInfo
{
public TimeInfo()
{
SystemTime = DateTime.UtcNow;
}

public DateTime SystemTime { get; set; }
}

public override bool IsReusable => true;

[HttpGet]
public IActionResult GetTime()
{
return new JsonResult(new TimeInfo());
}

[HttpPut]
public IActionResult SetTime()
{
try
{
string json;

using (var reader = new StreamReader(Context.Request.InputStream))
{
json = reader.ReadToEnd();
}

var info = SimpleJson.SimpleJson.DeserializeObject<TimeInfo>(json);

if (info.SystemTime != DateTime.MinValue)
{
MeadowApp.Device.SetClock(info.SystemTime);
return new OkResult();
}

return new StatusCodeResult(System.Net.HttpStatusCode.InternalServerError);
}
catch (Exception ex)
{
return new ServerErrorResult(ex);
}
}
}
}
2 changes: 1 addition & 1 deletion Meadow.TestSuite.Worker/TestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class TestRunner
public bool ShowDebug { get; set; } = false;
public TestResult Result { get; private set; }
private ITestProvider Provider { get; }
public bool RunTestsAsync { get; set; } = false;
public bool RunTestsAsync { get; set; } = true;

internal TestRunner(ITestProvider provider, string testID)
{
Expand Down
10 changes: 10 additions & 0 deletions TestSuite.Unit.Tests/RegistryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,14 @@ public void WorkerRegistryTest()
var names = r.GetTestNames();
}
}

public class SerializationTests
{
[Fact]
public void WorkerRegistryTest()
{
var r = new WorkerRegistry(null, null);
var names = r.GetTestNames();
}
}
}
4 changes: 4 additions & 0 deletions TestSuite.Unit.Tests/TestSuite.Unit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
<PackageReference Include="coverlet.collector" Version="3.1.0"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="SimpleJson" Version="0.38.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Meadow.TestSuite.Director\Meadow.TestSuite.Director.csproj" />
<ProjectReference Include="..\Meadow.TestSuite.Worker\Meadow.TestSuite.Worker.F7.csproj" />
</ItemGroup>

<ItemGroup>
<None Remove="SimpleJson" />
</ItemGroup>
</Project>

0 comments on commit e1b8150

Please sign in to comment.