Skip to content

Commit

Permalink
Another big refactoring, added tests, and now uses subresults to grou…
Browse files Browse the repository at this point in the history
…p results under their fixture
  • Loading branch information
daveaglick committed Dec 14, 2018
1 parent 29c6cf9 commit e3cfe46
Show file tree
Hide file tree
Showing 15 changed files with 585 additions and 135 deletions.
17 changes: 17 additions & 0 deletions AzurePipelines.TestLogger.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C95ECC05-F3E
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzurePipelines.TestLogger", "src\AzurePipelines.TestLogger\AzurePipelines.TestLogger.csproj", "{77CA5040-B4A0-4D0B-ADDD-09853A385007}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{FA92AD98-1291-4A90-A3AA-ED81A9BBC86E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzurePipelines.TestLogger.Tests", "tests\AzurePipelines.TestLogger.Tests\AzurePipelines.TestLogger.Tests.csproj", "{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -28,12 +32,25 @@ Global
{77CA5040-B4A0-4D0B-ADDD-09853A385007}.Release|x64.Build.0 = Release|Any CPU
{77CA5040-B4A0-4D0B-ADDD-09853A385007}.Release|x86.ActiveCfg = Release|Any CPU
{77CA5040-B4A0-4D0B-ADDD-09853A385007}.Release|x86.Build.0 = Release|Any CPU
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Debug|x64.ActiveCfg = Debug|Any CPU
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Debug|x64.Build.0 = Debug|Any CPU
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Debug|x86.ActiveCfg = Debug|Any CPU
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Debug|x86.Build.0 = Debug|Any CPU
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Release|Any CPU.Build.0 = Release|Any CPU
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Release|x64.ActiveCfg = Release|Any CPU
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Release|x64.Build.0 = Release|Any CPU
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Release|x86.ActiveCfg = Release|Any CPU
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{77CA5040-B4A0-4D0B-ADDD-09853A385007} = {C95ECC05-F3E8-49F4-B7C5-A29CD7EACFC1}
{8C42EBD4-FF36-44B6-A70E-7D83CB0626F8} = {FA92AD98-1291-4A90-A3AA-ED81A9BBC86E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A7517899-6171-4E6B-BDD7-DBE01B34E83A}
Expand Down
4 changes: 4 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.4.0

- [Feature] Now groups tests under their fixture

# 0.3.0

- [Refactoring] Renamed to AzurePipelines.TestLogger
Expand Down
17 changes: 15 additions & 2 deletions src/AzurePipelines.TestLogger/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace AzurePipelines.TestLogger
{
internal class ApiClient
internal class ApiClient : IApiClient
{
private static readonly HttpClient _client = new HttpClient();

Expand All @@ -26,9 +26,22 @@ public ApiClient(string accessToken, string collectionUri, string teamProject)

public async Task<string> SendAsync(HttpMethod method, string endpoint, string apiVersion, string body, CancellationToken cancellationToken)
{
if (method == null)
{
throw new ArgumentNullException(nameof(method));
}

if (apiVersion == null)
{
throw new ArgumentNullException(nameof(apiVersion));
}

string requestUri = $"{ _baseUrl }{ endpoint }?api-version={ apiVersion }";
HttpRequestMessage request = new HttpRequestMessage(method, requestUri);
request.Content = new StringContent(body, Encoding.UTF8, "application/json");
if (body != null)
{
request.Content = new StringContent(body, Encoding.UTF8, "application/json");
}
HttpResponseMessage response = await _client.SendAsync(request, cancellationToken);
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@
<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="15.0.0" />
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>AzurePipelines.TestLogger.Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Project>
21 changes: 18 additions & 3 deletions src/AzurePipelines.TestLogger/AzurePipelinesTestLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,19 @@ public class AzurePipelinesTestLogger : ITestLogger
/// </summary>
public const string FriendlyName = "AzurePipelines";

private IApiClient _apiClient;
private LoggerQueue _queue;

public AzurePipelinesTestLogger()
{
}

// Used for testing
internal AzurePipelinesTestLogger(IApiClient apiClient)
{
_apiClient = apiClient;
}

public void Initialize(TestLoggerEvents events, string testRunDirectory)
{
if(!GetRequiredVariable("SYSTEM_ACCESSTOKEN", out string accessToken)
Expand All @@ -38,8 +49,11 @@ public void Initialize(TestLoggerEvents events, string testRunDirectory)
return;
}

ApiClient apiClient = new ApiClient(accessToken, collectionUri, teamProject);
_queue = new LoggerQueue(apiClient, buildId, agentName, jobName);
if (_apiClient == null)
{
_apiClient = new ApiClient(accessToken, collectionUri, teamProject);
}
_queue = new LoggerQueue(_apiClient, buildId, agentName, jobName);

// Register for the events
events.TestRunMessage += TestMessageHandler;
Expand All @@ -63,7 +77,8 @@ private void TestMessageHandler(object sender, TestRunMessageEventArgs e)
// Add code to handle message
}

private void TestResultHandler(object sender, TestResultEventArgs e) => _queue.Enqueue(e.Result);
private void TestResultHandler(object sender, TestResultEventArgs e) =>
_queue.Enqueue(new VstpTestResult(e.Result));

private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e) => _queue.Flush();
}
Expand Down
11 changes: 11 additions & 0 deletions src/AzurePipelines.TestLogger/IApiClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace AzurePipelines.TestLogger
{
internal interface IApiClient
{
Task<string> SendAsync(HttpMethod method, string endpoint, string apiVersion, string body, CancellationToken cancellationToken);
}
}
20 changes: 20 additions & 0 deletions src/AzurePipelines.TestLogger/ITestResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;

namespace AzurePipelines.TestLogger
{
internal interface ITestResult
{
string Source { get; }
string FullyQualifiedName { get; }
string DisplayName { get; }
TestOutcome Outcome { get; }
TimeSpan Duration { get; }
string ErrorStackTrace { get; }
string ErrorMessage { get; }
IList<TestResultMessage> Messages { get; }
}
}
Loading

0 comments on commit e3cfe46

Please sign in to comment.