-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Target .net 5.0 * Added auth header validation * Added request catcher example * Some cleanup in preparation for more unit tests * Use asp.net ApiVersion handling instead of manual checking * Added support for basic integration tests * Add a warning about serilog config when required 'using' section is missing * Upgrade Azure.Messaging.EventGrid library to 4.1.0
- Loading branch information
Showing
45 changed files
with
911 additions
and
544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 7 additions & 5 deletions
12
src/UnitTests/UnitTests.csproj → ...ests/AzureEventGridSimulator.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/AzureEventGridSimulator.Tests/Integration/BasicTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Azure.Messaging.EventGrid; | ||
using AzureEventGridSimulator.Domain; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Newtonsoft.Json; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace AzureEventGridSimulator.Tests.Integration | ||
{ | ||
public class BasicTests | ||
: IClassFixture<TestContextFixture> | ||
{ | ||
private readonly TestContextFixture _factory; | ||
|
||
public BasicTests(TestContextFixture factory) | ||
{ | ||
_factory = factory; | ||
} | ||
|
||
[Fact] | ||
public async Task GivenAValidEvent_WhenPublished_ThenItShouldBeAccepted() | ||
{ | ||
// Arrange | ||
var client = _factory.CreateClient(new WebApplicationFactoryClientOptions | ||
{ | ||
BaseAddress = new Uri("https://localhost:60101") | ||
}); | ||
|
||
client.DefaultRequestHeaders.Add(Constants.AegSasKeyHeader, "TheLocal+DevelopmentKey="); | ||
client.DefaultRequestHeaders.Add(Constants.AegEventTypeHeader, Constants.NotificationEventType); | ||
|
||
var testEvent = new EventGridEvent("subject", "eventType", "1.0", new { Blah = 1 }); | ||
var json = JsonConvert.SerializeObject(new[] { testEvent }, Formatting.Indented); | ||
|
||
// Act | ||
var jsonContent = new StringContent(json, Encoding.UTF8, "application/json"); | ||
var response = await client.PostAsync("/api/events", jsonContent); | ||
|
||
// Assert | ||
response.EnsureSuccessStatusCode(); | ||
response.StatusCode.ShouldBe(HttpStatusCode.OK); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/AzureEventGridSimulator.Tests/Integration/TestContextFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using Xunit; | ||
|
||
namespace AzureEventGridSimulator.Tests.Integration | ||
{ | ||
// ReSharper disable once ClassNeverInstantiated.Global | ||
public class TestContextFixture : WebApplicationFactory<Startup>, IAsyncLifetime | ||
{ | ||
public Task InitializeAsync() | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task DisposeAsync() | ||
{ | ||
Dispose(); | ||
return Task.CompletedTask; | ||
} | ||
|
||
protected override void ConfigureWebHost(IWebHostBuilder builder) | ||
{ | ||
builder.UseEnvironment(Environments.Development); | ||
|
||
builder.ConfigureAppConfiguration((_, configurationBuilder) => | ||
{ | ||
configurationBuilder | ||
.SetBasePath(Directory.GetCurrentDirectory()) | ||
.AddJsonFile("appsettings.tests.json", false, true); | ||
}); | ||
|
||
builder.ConfigureLogging(logging => | ||
{ | ||
logging.ClearProviders(); | ||
logging.AddConsole(); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.