Skip to content

Commit

Permalink
Merge pull request #1612 from microsoftgraph/dev
Browse files Browse the repository at this point in the history
Merges dev into master
  • Loading branch information
millicentachieng committed Jun 23, 2023
2 parents d1ebc07 + c906340 commit c19ac50
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 34 deletions.
6 changes: 2 additions & 4 deletions GraphWebApi/Controllers/KnownIssuesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ public KnownIssuesController(IKnownIssuesService knownIssuesService, TelemetryCl
[Route("api/[controller]")]
[Route("knownissues")]
[HttpGet]
public async Task<IActionResult> GetKnownIssues()
public async Task<IActionResult> GetKnownIssues([FromQuery] string environment = EnvironmentType.Staging)
{
_telemetryClient?.TrackTrace("Request to query the list of known issues",
SeverityLevel.Information,
_knownIssuesTraceProperties);

List<KnownIssue> result = await _knownIssuesService.QueryBugsAsync();

List<KnownIssue> result = await _knownIssuesService.QueryBugsAsync(environment, null);
return result == null ? NotFound() : Ok(result);
}
}
Expand Down
8 changes: 4 additions & 4 deletions GraphWebApi/GraphWebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
<PackageReference Include="Microsoft.ApplicationInsights.Web" Version="2.21.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
<PackageReference Include="Microsoft.AspNetCore.ApplicationInsights.HostingStartup" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="7.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="7.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.8" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.7" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog" Version="3.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
Expand Down
15 changes: 8 additions & 7 deletions KnownIssuesService.Test/KnownIssuesServiceShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using UtilityService;
using Xunit;

namespace KnownIssuesService.Test
Expand All @@ -21,18 +22,17 @@ public class KnownIssuesServiceShould
private readonly IKnownIssuesService _knownIssuesService;
private readonly WorkItemTrackingHttpClientMock _workItemTrackingHttpClientMock;
private readonly WorkItemTrackingHttpClient _workItemTrackingHttpClient;
private readonly Mock<Wiql> _wiqlTest;
private readonly Mock<Wiql> _wiqlTest = new();
private readonly IConfigurationRoot _configuration;

public KnownIssuesServiceShould()
{
_configuration = new ConfigurationBuilder()
.AddJsonFile("appsettingstest.json")
.Build();
_wiqlTest = new Mock<Wiql>();
_workItemTrackingHttpClientMock = new WorkItemTrackingHttpClientMock();
_workItemTrackingHttpClient = _workItemTrackingHttpClientMock.MockWorkItemTrackingHttpClient(_wiqlTest);
_knownIssuesService = new Services.KnownIssuesService(_configuration, wiql: _wiqlTest.Object, httpQueryClient: _workItemTrackingHttpClient);
_knownIssuesService = new Services.KnownIssuesService(_configuration, httpQueryClient: _workItemTrackingHttpClient);
}

[Fact]
Expand All @@ -42,7 +42,7 @@ public async Task GetQueryByWiql()
int expectedNoOfWorkItems = 5;

//Act
WorkItemQueryResult workItemQueryResult = await _knownIssuesService.GetQueryByWiqlAsync();
WorkItemQueryResult workItemQueryResult = await _knownIssuesService.GetQueryByWiqlAsync(_wiqlTest.Object);
int actualNoOfWorkItems = workItemQueryResult.WorkItems.ToList().Count;

//Assert
Expand All @@ -56,7 +56,7 @@ public async Task GetWorkItemsQuery()
int expectedNoOfWorkItems = 5;

//Act
WorkItemQueryResult workItemQueryResult = await _knownIssuesService.GetQueryByWiqlAsync();
WorkItemQueryResult workItemQueryResult = await _knownIssuesService.GetQueryByWiqlAsync(_wiqlTest.Object);
int[] ids = workItemQueryResult.WorkItems.Select(item => item.Id).ToArray();
List<WorkItem> items = await _knownIssuesService.GetWorkItemsQueryAsync(ids, workItemQueryResult);

Expand All @@ -77,11 +77,12 @@ public async Task QueryBugs()
WorkAround = "Test",
Link = "/foo/bar",
CreatedDateTime = DateTime.Parse("01/06/2022 00:00:00"),
LastUpdatedDateTime = DateTime.Parse("01/07/2022 00:00:00")
LastUpdatedDateTime = DateTime.Parse("01/07/2022 00:00:00"),
SubArea = "Test notifications"
};

//Act
List<KnownIssue> items = await _knownIssuesService.QueryBugsAsync();
List<KnownIssue> items = await _knownIssuesService.QueryBugsAsync(EnvironmentType.Staging, this._wiqlTest.Object);

//Assert
foreach (var item in items)
Expand Down
4 changes: 2 additions & 2 deletions KnownIssuesService/Interfaces/IKnownIssuesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace KnownIssuesService.Interfaces
/// </summary>
public interface IKnownIssuesService
{
Task<List<KnownIssue>> QueryBugsAsync();
Task<WorkItemQueryResult> GetQueryByWiqlAsync();
Task<List<KnownIssue>> QueryBugsAsync(string environment, Wiql workItemQuery);
Task<WorkItemQueryResult> GetQueryByWiqlAsync(Wiql workItemQuery);
Task<List<WorkItem>> GetWorkItemsQueryAsync(int[] ids, WorkItemQueryResult result);
}
}
37 changes: 22 additions & 15 deletions KnownIssuesService/Services/KnownIssuesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ namespace KnownIssuesService.Services
public class KnownIssuesService : IKnownIssuesService
{
private List<KnownIssue> _knownIssuesList;
private readonly Wiql _workItemQuery;
private readonly WorkItemTrackingHttpClient _httpQueryClient;
private readonly IConfiguration _configuration;
private readonly TelemetryClient _telemetryClient;
Expand All @@ -35,16 +34,13 @@ public class KnownIssuesService : IKnownIssuesService
private const string AccessTokenValue = "KnownIssues:Token";
private const string KnownIssuesPath = "KnownIssues:Uri";


public KnownIssuesService(IConfiguration configuration,
TelemetryClient telemetryClient = null,
Wiql wiql = null,
WorkItemTrackingHttpClient httpQueryClient = null)
{
UtilityFunctions.CheckArgumentNull(configuration, nameof(configuration));
_configuration = configuration;
_telemetryClient = telemetryClient;
_workItemQuery = wiql ?? QueryBuilder();
_telemetryClient = telemetryClient;
_httpQueryClient = httpQueryClient ?? GetWorkItemTrackingHttpClient();
}

Expand Down Expand Up @@ -91,9 +87,9 @@ private WorkItemTrackingHttpClient GetWorkItemTrackingHttpClient()
/// Azure DevOps Org
/// </summary>
/// <returns>WorkItem Query result</returns>
public Task<WorkItemQueryResult> GetQueryByWiqlAsync()
public Task<WorkItemQueryResult> GetQueryByWiqlAsync(Wiql workItemQuery)
{
return _httpQueryClient.QueryByWiqlAsync(_workItemQuery, null, 100, null, CancellationToken.None);
return _httpQueryClient.QueryByWiqlAsync(workItemQuery, null, 100, null, CancellationToken.None);
}

/// <summary>
Expand All @@ -116,15 +112,25 @@ public Task<List<WorkItem>> GetWorkItemsQueryAsync(int[] ids, WorkItemQueryResul
/// </summary>
/// <returns>A work item query builder containing the selection criteria</returns>
[ExcludeFromCodeCoverage]
private static Wiql QueryBuilder()
private static Wiql QueryBuilder(string environment)
{
// create a wiql object and build our query
return new Wiql()
string organization;

if (EnvironmentType.Production.Equals(environment, StringComparison.OrdinalIgnoreCase) || EnvironmentType.Preview.Equals(environment, StringComparison.OrdinalIgnoreCase))
{
organization = UtilityConstants.KnownIssuesProdOrganisation;
}
else
{
organization = UtilityConstants.KnownIssuesStagingOrganisation;
}
// create a wiql object and build our query
return new Wiql()
{
Query = "Select [Id] " +
"From WorkItems " +
"Where [Work Item Type] = 'Bug' " +
"And [System.TeamProject] = '" + UtilityConstants.KnownIssuesOrganisation + "' " +
"And [System.TeamProject] = '" + organization + "' " +
"Order By [State] Asc, [Changed Date] Desc",
};
}
Expand All @@ -133,16 +139,17 @@ private static Wiql QueryBuilder()
/// Function to Query the List of Known Issues from Azure DevOps Known Organization
/// </summary>
/// <returns>Known Issues Contract that contains json items that will be rendered on the browser</returns>
public async Task<List<KnownIssue>> QueryBugsAsync()
public async Task<List<KnownIssue>> QueryBugsAsync(string environment, Wiql workItemQuery = null)
{
_telemetryClient?.TrackTrace("Fetches a WorkItemQueryResult for fetching work item Ids and urls",
SeverityLevel.Information,
_knownIssuesTraceProperties);
workItemQuery ??= QueryBuilder(environment);

WorkItemQueryResult result = await GetQueryByWiqlAsync();
int[] ids = result.WorkItems.Select(item => item.Id).ToArray();
WorkItemQueryResult result = await GetQueryByWiqlAsync(workItemQuery);
int[] ids = result?.WorkItems.Select(static item => item.Id).ToArray();

if (ids.Length == 0)
if (ids?.Length == 0)
{
return _knownIssuesList;
}
Expand Down
11 changes: 9 additions & 2 deletions UtilityService/UtilityConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ public static class UtilityConstants
public const string CleanBetaMetadata = "https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/clean_beta_metadata/cleanMetadataWithDescriptionsbeta.xml";

/// <summary>
/// Contains the name of the Known Issues Azure DevOps Organisation
/// Contains the names of the Known Issues Azure DevOps Organisation
/// </summary>
public const string KnownIssuesOrganisation = "Known Issues (staging)";
public const string KnownIssuesStagingOrganisation = "Known Issues (Staging)";
public const string KnownIssuesProdOrganisation = "Known Issues";
}
public static class EnvironmentType
{
public const string Staging = "staging";
public const string Production = "production";
public const string Preview = "preview";
}
}

0 comments on commit c19ac50

Please sign in to comment.