-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
784b1c3
commit b0222ad
Showing
6 changed files
with
211 additions
and
1 deletion.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
src/Http/Wolverine.Http.Tests/Marten/compiled_query_writer.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,69 @@ | ||
using Alba; | ||
using Marten.Schema.Identity; | ||
using Shouldly; | ||
using WolverineWebApi.Marten; | ||
|
||
namespace Wolverine.Http.Tests.Marten; | ||
|
||
public class compiled_query_writer : IntegrationContext | ||
{ | ||
public compiled_query_writer(AppFixture fixture) : base(fixture) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task endpoint_returning_compiled_list_query_should_return_query_result() | ||
{ | ||
await using var session = Store.LightweightSession(); | ||
int notApprovedInvoices = 5; | ||
int approvedInvoices = 3; | ||
for (int i = 0; i < notApprovedInvoices; i++) | ||
{ | ||
var invoice = | ||
new Invoice() | ||
{ | ||
Approved = false | ||
}; | ||
session.Store(invoice); | ||
} | ||
|
||
for (int i = 0; i < approvedInvoices; i++) | ||
{ | ||
var invoice = | ||
new Invoice() | ||
{ | ||
Approved = true | ||
}; | ||
session.Store(invoice); | ||
} | ||
|
||
await session.SaveChangesAsync(); | ||
|
||
var approvedInvoiceList = await Host.GetAsJson<List<Invoice>>("/invoices/approved"); | ||
approvedInvoiceList.ShouldNotBeNull(); | ||
approvedInvoiceList.Count.ShouldBe(approvedInvoices); | ||
} | ||
|
||
[Fact] | ||
public async Task endpoint_returning_compiled_query_should_return_query_result() | ||
{ | ||
var invoice = new Invoice() | ||
{ | ||
Id = Guid.NewGuid() | ||
}; | ||
using var session = Store.LightweightSession(); | ||
session.Store(invoice); | ||
await session.SaveChangesAsync(); | ||
|
||
|
||
var invoiceCompiled = await Host.GetAsJson<Invoice>($"/invoices/compiled/{invoice.Id}"); | ||
invoiceCompiled.ShouldNotBeNull(); | ||
invoiceCompiled.Id.ShouldBe(invoice.Id); | ||
|
||
await Host.Scenario(x => | ||
{ | ||
x.Get.Url($"/invoices/compiled/{Guid.NewGuid()}"); | ||
x.StatusCodeShouldBe(404); | ||
}); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/Http/WolverineWebApi/Internal/Generated/WolverineHandlers/GET_invoices_approved.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,47 @@ | ||
// <auto-generated/> | ||
#pragma warning disable | ||
using Microsoft.AspNetCore.Routing; | ||
using System; | ||
using System.Linq; | ||
using Wolverine.Http; | ||
using Wolverine.Marten.Publishing; | ||
using Wolverine.Runtime; | ||
|
||
namespace Internal.Generated.WolverineHandlers | ||
{ | ||
// START: GET_invoices_approved | ||
public class GET_invoices_approved : Wolverine.Http.HttpHandler | ||
{ | ||
private readonly Wolverine.Http.WolverineHttpOptions _wolverineHttpOptions; | ||
private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; | ||
private readonly Wolverine.Runtime.IWolverineRuntime _wolverineRuntime; | ||
|
||
public GET_invoices_approved(Wolverine.Http.WolverineHttpOptions wolverineHttpOptions, Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory, Wolverine.Runtime.IWolverineRuntime wolverineRuntime) : base(wolverineHttpOptions) | ||
{ | ||
_wolverineHttpOptions = wolverineHttpOptions; | ||
_outboxedSessionFactory = outboxedSessionFactory; | ||
_wolverineRuntime = wolverineRuntime; | ||
} | ||
|
||
|
||
|
||
public override async System.Threading.Tasks.Task Handle(Microsoft.AspNetCore.Http.HttpContext httpContext) | ||
{ | ||
var messageContext = new Wolverine.Runtime.MessageContext(_wolverineRuntime); | ||
// Building the Marten session | ||
await using var documentSession = _outboxedSessionFactory.OpenSession(messageContext); | ||
|
||
// The actual HTTP request handler execution | ||
var approvedInvoicedCompiledQuery = WolverineWebApi.Marten.InvoicesEndpoint.GetApproved(); | ||
|
||
// Run the compiled query and stream the response | ||
await Marten.AspNetCore.QueryableExtensions.WriteArray(documentSession, approvedInvoicedCompiledQuery, httpContext); | ||
} | ||
|
||
} | ||
|
||
// END: GET_invoices_approved | ||
|
||
|
||
} | ||
|
54 changes: 54 additions & 0 deletions
54
src/Http/WolverineWebApi/Internal/Generated/WolverineHandlers/GET_invoices_compiled_id.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,54 @@ | ||
// <auto-generated/> | ||
#pragma warning disable | ||
using Microsoft.AspNetCore.Routing; | ||
using System; | ||
using System.Linq; | ||
using Wolverine.Http; | ||
using Wolverine.Marten.Publishing; | ||
using Wolverine.Runtime; | ||
|
||
namespace Internal.Generated.WolverineHandlers | ||
{ | ||
// START: GET_invoices_compiled_id | ||
public class GET_invoices_compiled_id : Wolverine.Http.HttpHandler | ||
{ | ||
private readonly Wolverine.Http.WolverineHttpOptions _wolverineHttpOptions; | ||
private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; | ||
private readonly Wolverine.Runtime.IWolverineRuntime _wolverineRuntime; | ||
|
||
public GET_invoices_compiled_id(Wolverine.Http.WolverineHttpOptions wolverineHttpOptions, Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory, Wolverine.Runtime.IWolverineRuntime wolverineRuntime) : base(wolverineHttpOptions) | ||
{ | ||
_wolverineHttpOptions = wolverineHttpOptions; | ||
_outboxedSessionFactory = outboxedSessionFactory; | ||
_wolverineRuntime = wolverineRuntime; | ||
} | ||
|
||
|
||
|
||
public override async System.Threading.Tasks.Task Handle(Microsoft.AspNetCore.Http.HttpContext httpContext) | ||
{ | ||
var messageContext = new Wolverine.Runtime.MessageContext(_wolverineRuntime); | ||
// Building the Marten session | ||
await using var documentSession = _outboxedSessionFactory.OpenSession(messageContext); | ||
if (!System.Guid.TryParse((string)httpContext.GetRouteValue("id"), out var id)) | ||
{ | ||
httpContext.Response.StatusCode = 404; | ||
return; | ||
} | ||
|
||
|
||
|
||
// The actual HTTP request handler execution | ||
var byIdCompiled = WolverineWebApi.Marten.InvoicesEndpoint.GetCompiled(id); | ||
|
||
// Run the compiled query and stream the response | ||
await Marten.AspNetCore.QueryableExtensions.WriteOne(documentSession, byIdCompiled, httpContext); | ||
} | ||
|
||
} | ||
|
||
// END: GET_invoices_compiled_id | ||
|
||
|
||
} | ||
|
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