Skip to content

Commit cc13754

Browse files
committed
Merge branch 'dev-apilayer3' into upgrade_mud
2 parents 928507a + 1831cbd commit cc13754

File tree

50 files changed

+2434
-1333
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2434
-1333
lines changed

.github/workflows/github-monitor-build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Setup dotnet
1717
uses: actions/setup-dotnet@v1
1818
with:
19-
dotnet-version: "6.0.x"
19+
dotnet-version: "8.0.x"
2020

2121
- name: "Run dotnet build"
2222
working-directory: github-monitor
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Grade Management New - build
2+
3+
on:
4+
push:
5+
paths:
6+
- "grade-management-new/**"
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 1
17+
18+
- name: Setup dotnet
19+
uses: actions/setup-dotnet@v1
20+
with:
21+
dotnet-version: "8.0.x"
22+
23+
- name: "Run dotnet build"
24+
working-directory: grade-management-new
25+
run: |
26+
dotnet build
27+
dotnet test

github-monitor/Ahk.GitHub.Monitor.Tests/Ahk.GitHub.Monitor.Tests.csproj

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,37 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<None Remove="SampleCallbacks\branch_create.json" />
11-
<None Remove="SampleCallbacks\comment_command.json" />
12-
<None Remove="SampleCallbacks\comment_delete.json" />
13-
<None Remove="SampleCallbacks\comment_edit.json" />
14-
<None Remove="SampleCallbacks\pr_open.json" />
15-
<None Remove="SampleCallbacks\pr_reviewcomment.json" />
16-
<None Remove="SampleCallbacks\pr_reviewrequested.json" />
17-
<None Remove="SampleCallbacks\workflow_run.json" />
10+
<None Remove="SampleCallbacks\branch_create.json"/>
11+
<None Remove="SampleCallbacks\comment_command.json"/>
12+
<None Remove="SampleCallbacks\comment_delete.json"/>
13+
<None Remove="SampleCallbacks\comment_edit.json"/>
14+
<None Remove="SampleCallbacks\pr_open.json"/>
15+
<None Remove="SampleCallbacks\pr_reviewcomment.json"/>
16+
<None Remove="SampleCallbacks\pr_reviewrequested.json"/>
17+
<None Remove="SampleCallbacks\workflow_run.json"/>
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<EmbeddedResource Include="SampleCallbacks\workflow_run.json" />
22-
<EmbeddedResource Include="SampleCallbacks\branch_create.json" />
23-
<EmbeddedResource Include="SampleCallbacks\comment_delete.json" />
24-
<EmbeddedResource Include="SampleCallbacks\comment_command.json" />
25-
<EmbeddedResource Include="SampleCallbacks\comment_edit.json" />
26-
<EmbeddedResource Include="SampleCallbacks\pr_reviewcomment.json" />
27-
<EmbeddedResource Include="SampleCallbacks\pr_reviewrequested.json" />
28-
<EmbeddedResource Include="SampleCallbacks\pr_open.json" />
21+
<EmbeddedResource Include="SampleCallbacks\workflow_run.json"/>
22+
<EmbeddedResource Include="SampleCallbacks\branch_create.json"/>
23+
<EmbeddedResource Include="SampleCallbacks\comment_delete.json"/>
24+
<EmbeddedResource Include="SampleCallbacks\comment_command.json"/>
25+
<EmbeddedResource Include="SampleCallbacks\comment_edit.json"/>
26+
<EmbeddedResource Include="SampleCallbacks\pr_reviewcomment.json"/>
27+
<EmbeddedResource Include="SampleCallbacks\pr_reviewrequested.json"/>
28+
<EmbeddedResource Include="SampleCallbacks\pr_open.json"/>
2929
</ItemGroup>
3030

3131
<ItemGroup>
32-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
33-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
34-
<PackageReference Include="Moq" Version="4.16.1" />
35-
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
36-
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
32+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0"/>
33+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0"/>
34+
<PackageReference Include="Moq" Version="4.16.1"/>
35+
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8"/>
36+
<PackageReference Include="MSTest.TestFramework" Version="2.2.8"/>
3737
</ItemGroup>
3838

3939
<ItemGroup>
40-
<ProjectReference Include="..\Ahk.GitHub.Monitor\Ahk.GitHub.Monitor.csproj" />
40+
<ProjectReference Include="..\Ahk.GitHub.Monitor\Ahk.GitHub.Monitor.csproj"/>
4141
</ItemGroup>
4242

4343
</Project>

github-monitor/Ahk.GitHub.Monitor.Tests/IntegrationTests/AppStartupTest.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,23 @@
55
using Microsoft.Azure.Functions.Worker;
66
using Microsoft.Extensions.DependencyInjection;
77

8-
namespace Ahk.GitHub.Monitor.Tests.IntegrationTests
8+
namespace Ahk.GitHub.Monitor.Tests.IntegrationTests;
9+
10+
[TestClass]
11+
public class AppStartupTest
912
{
10-
[TestClass]
11-
public class AppStartupTest
13+
[TestMethod]
14+
public async Task AppStartupSucceeds()
1215
{
13-
[TestMethod]
14-
public async Task AppStartupSucceeds()
15-
{
16-
var host = new HostBuilder()
17-
.ConfigureServices(services =>
18-
{
19-
services.AddSingleton<Services.IGitHubClientFactory, GitHubClientFactory>();
20-
})
21-
.Build();
16+
IHost host = new HostBuilder()
17+
.ConfigureServices(services =>
18+
{
19+
services.AddSingleton<Services.IGitHubClientFactory, GitHubClientFactory>();
20+
})
21+
.Build();
2222

23-
await host.StartAsync();
23+
await host.StartAsync();
2424

25-
await host.StopAsync();
26-
}
25+
await host.StopAsync();
2726
}
2827
}

github-monitor/Ahk.GitHub.Monitor.Tests/IntegrationTests/FunctionInvokeTest.cs

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,53 @@
88
using Microsoft.VisualStudio.TestTools.UnitTesting;
99
using Moq;
1010

11-
namespace Ahk.GitHub.Monitor.Tests.IntegrationTests
11+
namespace Ahk.GitHub.Monitor.Tests.IntegrationTests;
12+
13+
[TestClass]
14+
public class FunctionInvokeTest
1215
{
13-
[TestClass]
14-
public class FunctionInvokeTest
16+
[TestMethod]
17+
public async Task NoAppConfigsReturnsError()
1518
{
16-
[TestMethod]
17-
public async Task NoAppConfigsReturnsError()
18-
{
19-
var log = new Mock<ILogger<GitHubMonitorFunction>>();
20-
var eds = new Mock<IEventDispatchService>();
21-
var func = new GitHubMonitorFunction(eds.Object, Options.Create(new GitHubMonitorConfig()), log.Object);
22-
23-
var resp = await func.InvokeAndGetResponseAs<ObjectResult>(req => { });
24-
25-
Assert.AreEqual(StatusCodes.Status500InternalServerError, resp.StatusCode);
26-
eds.Verify(s => s.Process(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<WebhookResult>(), NullLogger.Instance), Times.Never());
27-
}
28-
29-
[TestMethod]
30-
public async Task MissingGitHubEventHeaderReturnsError()
31-
{
32-
var eds = new Mock<IEventDispatchService>();
33-
var func = FunctionBuilder.Create(eds.Object);
34-
35-
var resp = await func.InvokeAndGetResponseAs<ObjectResult>(req => req.Headers.Add("X-Hub-Signature-256", "dummy"));
36-
37-
Assert.AreEqual(StatusCodes.Status400BadRequest, resp.StatusCode);
38-
eds.Verify(s => s.Process(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<WebhookResult>(), NullLogger.Instance), Times.Never());
39-
}
40-
41-
[TestMethod]
42-
public async Task MissingGitHubSignatureHeaderReturnsError()
43-
{
44-
var eds = new Mock<IEventDispatchService>();
45-
var func = FunctionBuilder.Create(eds.Object);
46-
47-
var resp = await func.InvokeAndGetResponseAs<ObjectResult>(req => req.Headers.Add("X-GitHub-Event", "dummy"));
48-
49-
Assert.AreEqual(StatusCodes.Status400BadRequest, resp.StatusCode);
50-
eds.Verify(s => s.Process(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<WebhookResult>(), NullLogger.Instance), Times.Never());
51-
}
19+
var log = new Mock<ILogger<GitHubMonitorFunction>>();
20+
var eds = new Mock<IEventDispatchService>();
21+
var func = new GitHubMonitorFunction(eds.Object, Options.Create(new GitHubMonitorConfig()), log.Object);
22+
23+
ObjectResult resp = await func.InvokeAndGetResponseAs<ObjectResult>(req => { });
24+
25+
Assert.AreEqual(StatusCodes.Status500InternalServerError, resp.StatusCode);
26+
eds.Verify(
27+
s => s.Process(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<WebhookResult>(), NullLogger.Instance),
28+
Times.Never());
29+
}
30+
31+
[TestMethod]
32+
public async Task MissingGitHubEventHeaderReturnsError()
33+
{
34+
var eds = new Mock<IEventDispatchService>();
35+
GitHubMonitorFunction func = FunctionBuilder.Create(eds.Object);
36+
37+
ObjectResult resp =
38+
await func.InvokeAndGetResponseAs<ObjectResult>(req => req.Headers.Add("X-Hub-Signature-256", "dummy"));
39+
40+
Assert.AreEqual(StatusCodes.Status400BadRequest, resp.StatusCode);
41+
eds.Verify(
42+
s => s.Process(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<WebhookResult>(), NullLogger.Instance),
43+
Times.Never());
44+
}
45+
46+
[TestMethod]
47+
public async Task MissingGitHubSignatureHeaderReturnsError()
48+
{
49+
var eds = new Mock<IEventDispatchService>();
50+
GitHubMonitorFunction func = FunctionBuilder.Create(eds.Object);
51+
52+
ObjectResult resp =
53+
await func.InvokeAndGetResponseAs<ObjectResult>(req => req.Headers.Add("X-GitHub-Event", "dummy"));
54+
55+
Assert.AreEqual(StatusCodes.Status400BadRequest, resp.StatusCode);
56+
eds.Verify(
57+
s => s.Process(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<WebhookResult>(), NullLogger.Instance),
58+
Times.Never());
5259
}
5360
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
using Ahk.GitHub.Monitor.Services.EventDispatch;
2+
using Microsoft.Extensions.Logging;
23
using Microsoft.Extensions.Options;
34
using Moq;
45

5-
namespace Ahk.GitHub.Monitor.Tests.IntegrationTests
6+
namespace Ahk.GitHub.Monitor.Tests.IntegrationTests;
7+
8+
internal static class FunctionBuilder
69
{
7-
internal static class FunctionBuilder
10+
public static readonly GitHubMonitorConfig AppConfig = new()
811
{
9-
public static readonly GitHubMonitorConfig AppConfig = new GitHubMonitorConfig()
10-
{
11-
GitHubAppId = "appid",
12-
GitHubAppPrivateKey = "appprivatekey",
13-
GitHubWebhookSecret = "webhooksecret",
14-
};
12+
GitHubAppId = "appid", GitHubAppPrivateKey = "appprivatekey", GitHubWebhookSecret = "webhooksecret"
13+
};
1514

16-
public static GitHubMonitorFunction Create(IEventDispatchService dispatchService = null)
17-
=> new GitHubMonitorFunction(dispatchService ?? new Mock<IEventDispatchService>().Object, Options.Create(AppConfig), new Mock<Microsoft.Extensions.Logging.ILogger<GitHubMonitorFunction>>().Object);
18-
}
15+
public static GitHubMonitorFunction Create(IEventDispatchService dispatchService = null)
16+
=> new(dispatchService ?? new Mock<IEventDispatchService>().Object,
17+
Options.Create(AppConfig),
18+
new Mock<ILogger<GitHubMonitorFunction>>().Object);
1919
}

github-monitor/Ahk.GitHub.Monitor.Tests/IntegrationTests/Helpers/FunctionCallAssert.cs

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,68 +8,69 @@
88
using Microsoft.VisualStudio.TestTools.UnitTesting;
99
using Moq;
1010

11-
namespace Ahk.GitHub.Monitor.Tests.IntegrationTests
11+
namespace Ahk.GitHub.Monitor.Tests.IntegrationTests;
12+
13+
internal static class FunctionCallAssert
1214
{
13-
internal static class FunctionCallAssert
15+
public static Task<IActionResult> Invoke(this GitHubMonitorFunction function,
16+
Action<MockHttpRequestData> configureRequest)
1417
{
15-
public static Task<IActionResult> Invoke(this GitHubMonitorFunction function, Action<MockHttpRequestData> configureRequest)
16-
{
17-
// Create a mock function context (you might need to implement this based on your test framework)
18-
var functionContext = new Mock<FunctionContext>(); // You may need to create or use a mocking framework
19-
var request = new MockHttpRequestData(functionContext.Object, new MemoryStream());
20-
21-
// Configure the request (e.g., add headers, set body, etc.)
22-
configureRequest(request);
18+
// Create a mock function context (you might need to implement this based on your test framework)
19+
var functionContext = new Mock<FunctionContext>(); // You may need to create or use a mocking framework
20+
var request = new MockHttpRequestData(functionContext.Object, new MemoryStream());
2321

24-
// Invoke the function with the configured request and a null logger
25-
return function.Run(request);
26-
}
22+
// Configure the request (e.g., add headers, set body, etc.)
23+
configureRequest(request);
2724

28-
public static Task<IActionResult> Invoke2(this GitHubMonitorFunction function, SampleCallbackData data)
29-
{
30-
// Create a mock function context (you might need to implement this based on your test framework)
31-
var functionContext = new Mock<FunctionContext>(); // You may need to create or use a mocking framework
32-
var request = new MockHttpRequestData(functionContext.Object, new MemoryStream());
25+
// Invoke the function with the configured request and a null logger
26+
return function.Run(request);
27+
}
3328

34-
// Configure the request (e.g., add headers, set body, etc.)
35-
request = configureRequest(request, data);
29+
public static Task<IActionResult> Invoke2(this GitHubMonitorFunction function, SampleCallbackData data)
30+
{
31+
// Create a mock function context (you might need to implement this based on your test framework)
32+
var functionContext = new Mock<FunctionContext>(); // You may need to create or use a mocking framework
33+
var request = new MockHttpRequestData(functionContext.Object, new MemoryStream());
3634

37-
// Invoke the function with the configured request and a null logger
38-
return function.Run(request);
39-
}
35+
// Configure the request (e.g., add headers, set body, etc.)
36+
request = configureRequest(request, data);
4037

41-
public static async Task<TResponse> InvokeAndGetResponseAs<TResponse>(this GitHubMonitorFunction function, Action<MockHttpRequestData> configureRequest)
42-
where TResponse : IActionResult
43-
{
44-
var result = await function.Invoke(configureRequest);
45-
Assert.IsInstanceOfType(result, typeof(TResponse));
46-
return (TResponse)result;
47-
}
38+
// Invoke the function with the configured request and a null logger
39+
return function.Run(request);
40+
}
4841

49-
public static async Task<TResponse> InvokeWithContentAndGetResponseAs<TResponse>(this GitHubMonitorFunction function, SampleCallbackData data)
50-
where TResponse : IActionResult
51-
{
52-
var result = await function.Invoke2(data);
53-
Assert.IsInstanceOfType(result, typeof(TResponse));
54-
return (TResponse)result;
55-
}
42+
public static async Task<TResponse> InvokeAndGetResponseAs<TResponse>(this GitHubMonitorFunction function,
43+
Action<MockHttpRequestData> configureRequest)
44+
where TResponse : IActionResult
45+
{
46+
IActionResult result = await function.Invoke(configureRequest);
47+
Assert.IsInstanceOfType(result, typeof(TResponse));
48+
return (TResponse)result;
49+
}
5650

57-
private static MockHttpRequestData configureRequest(MockHttpRequestData req, SampleCallbackData data)
58-
{
59-
// Write the body to the request stream
60-
var memStream = new MemoryStream();
61-
using var writer = new StreamWriter(memStream, leaveOpen: true);
62-
writer.Write(data.Body);
63-
writer.Flush();
51+
public static async Task<TResponse> InvokeWithContentAndGetResponseAs<TResponse>(
52+
this GitHubMonitorFunction function, SampleCallbackData data)
53+
where TResponse : IActionResult
54+
{
55+
IActionResult result = await function.Invoke2(data);
56+
Assert.IsInstanceOfType(result, typeof(TResponse));
57+
return (TResponse)result;
58+
}
6459

65-
memStream.Position = 0;
66-
req = new MockHttpRequestData(req.FunctionContext, memStream);
60+
private static MockHttpRequestData configureRequest(MockHttpRequestData req, SampleCallbackData data)
61+
{
62+
// Write the body to the request stream
63+
var memStream = new MemoryStream();
64+
using var writer = new StreamWriter(memStream, leaveOpen: true);
65+
writer.Write(data.Body);
66+
writer.Flush();
6767

68-
// Add headers
69-
req.Headers.Add("X-GitHub-Event", data.EventName);
70-
req.Headers.Add("X-Hub-Signature-256", data.Signature);
71-
return req;
72-
}
68+
memStream.Position = 0;
69+
req = new MockHttpRequestData(req.FunctionContext, memStream);
7370

71+
// Add headers
72+
req.Headers.Add("X-GitHub-Event", data.EventName);
73+
req.Headers.Add("X-Hub-Signature-256", data.Signature);
74+
return req;
7475
}
7576
}

0 commit comments

Comments
 (0)