From 72f20e39421a537bdc1b0f8f86d38a344e817b33 Mon Sep 17 00:00:00 2001 From: Jared Parsons Date: Wed, 24 Feb 2016 14:57:52 -0800 Subject: [PATCH] More JSON --- .../Source/RunTests/Cache/WebDataStorage.cs | 34 +++++++++++++++++-- src/Tools/Source/RunTests/Program.cs | 2 +- src/Tools/Source/RunTests/RunTests.csproj | 11 ++++++ src/Tools/Source/RunTests/packages.config | 5 +++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/Tools/Source/RunTests/packages.config diff --git a/src/Tools/Source/RunTests/Cache/WebDataStorage.cs b/src/Tools/Source/RunTests/Cache/WebDataStorage.cs index 5f896849455..05331f90366 100644 --- a/src/Tools/Source/RunTests/Cache/WebDataStorage.cs +++ b/src/Tools/Source/RunTests/Cache/WebDataStorage.cs @@ -1,5 +1,7 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using Newtonsoft.Json.Linq; +using RestSharp; using System; using System.Collections.Generic; using System.IO; @@ -11,14 +13,40 @@ namespace RunTests.Cache { internal sealed class WebDataStorage : IDataStorage { + private const string NameExitCode = "exitCode"; + private const string NameOutputStandard = "outputStandard"; + private const string NameOutputError = "outputError"; + private const string NameResultsFileName = "resultsFileName"; + private const string NameResultsFileContent = "resultsFileContent"; + private const string DashboardUriString = "http://jdash.azurewebsites.net"; + + private readonly RestClient _restClient = new RestClient(DashboardUriString); + public Task AddCachedTestResult(ContentFile conentFile, CachedTestResult testResult) { - throw new NotImplementedException(); + var obj = new JObject(); + obj[NameExitCode] = testResult.ExitCode; + obj[NameOutputStandard] = testResult.StandardOutput; + obj[NameOutputStandard] = testResult.ErrorOutput; + obj[NameResultsFileName] = testResult.ResultsFileName; + obj[NameResultsFileContent] = testResult.ResultsFileContent; + + var json = obj.ToString(); + return Task.FromResult(true); } - public Task TryGetCachedTestResult(string checksum) + public async Task TryGetCachedTestResult(string checksum) { - throw new NotImplementedException(); + var request = new RestRequest($"api/testcache/{checksum}"); + var response = await _restClient.ExecuteGetTaskAsync(request); + var obj = JObject.Parse(response.Content); + var result = new CachedTestResult( + exitCode: obj.Value(NameExitCode), + standardOutput: obj.Value(NameOutputStandard), + errorOutput: obj.Value(NameOutputError), + resultsFileName: obj.Value(NameResultsFileName), + resultsFileContent: obj.Value(NameResultsFileContent)); + return result; } } } diff --git a/src/Tools/Source/RunTests/Program.cs b/src/Tools/Source/RunTests/Program.cs index dd579e5a6f8..3803618dac4 100644 --- a/src/Tools/Source/RunTests/Program.cs +++ b/src/Tools/Source/RunTests/Program.cs @@ -33,7 +33,7 @@ internal static int Main(string[] args) ITestExecutor testExecutor = new ProcessTestExecutor(options); if (options.UseCachedResults) { - testExecutor = new CachingTestExecutor(options, testExecutor, new LocalDataStorage()); + testExecutor = new CachingTestExecutor(options, testExecutor, new WebDataStorage()); } var testRunner = new TestRunner(options, testExecutor); diff --git a/src/Tools/Source/RunTests/RunTests.csproj b/src/Tools/Source/RunTests/RunTests.csproj index 6b9f437b1c2..9707c091c7d 100644 --- a/src/Tools/Source/RunTests/RunTests.csproj +++ b/src/Tools/Source/RunTests/RunTests.csproj @@ -17,6 +17,14 @@ + + ..\..\..\..\..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll + True + + + ..\..\..\..\..\packages\RestSharp.105.2.3\lib\net45\RestSharp.dll + True + @@ -40,6 +48,9 @@ + + + diff --git a/src/Tools/Source/RunTests/packages.config b/src/Tools/Source/RunTests/packages.config new file mode 100644 index 00000000000..a1971b489b6 --- /dev/null +++ b/src/Tools/Source/RunTests/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file -- GitLab