From d8567d0665ac6bc9c167c0a39a663feea768135b Mon Sep 17 00:00:00 2001 From: Felix Winterhalter <felix.winterhalter@fau.de> Date: Thu, 25 Jan 2024 20:34:05 +0100 Subject: [PATCH] tests: Added a test for the string case. Test fails but unrelated to changes --- .../Marten/compiled_query_writer.cs | 30 +++++++++++++++++-- src/Http/WolverineWebApi/Marten/Documents.cs | 19 ++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/Http/Wolverine.Http.Tests/Marten/compiled_query_writer.cs b/src/Http/Wolverine.Http.Tests/Marten/compiled_query_writer.cs index d4e624aa2..115fcfd7f 100644 --- a/src/Http/Wolverine.Http.Tests/Marten/compiled_query_writer.cs +++ b/src/Http/Wolverine.Http.Tests/Marten/compiled_query_writer.cs @@ -60,11 +60,35 @@ public async Task endpoint_returning_compiled_primitive_query_should_return_quer await session.SaveChangesAsync(); - var approvedInvoiceList = await Host.GetAsText("/invoices/compiled/count"); - approvedInvoiceList.ShouldNotBeNull(); - int.TryParse(approvedInvoiceList, out var result).ShouldBeTrue(); + var invoiceCountString = await Host.GetAsText("/invoices/compiled/count"); + invoiceCountString.ShouldNotBeNull(); + int.TryParse(invoiceCountString, out var result).ShouldBeTrue(); result.ShouldBe(invoicesCount); } + + [Fact] + public async Task endpoint_returning_compiled_primitive_query_should_return_query_result_for_string() + { + await using var session = Store.LightweightSession(); + int invoicesCount = 5; + Guid id = Guid.Empty; + for (int i = 0; i < invoicesCount; i++) + { + var invoice = + new Invoice() + { + }; + session.Store(invoice); + id = invoice.Id; + } + id.ShouldNotBe(Guid.Empty); + + await session.SaveChangesAsync(); + + var invoiceId = await Host.GetAsText($"/invoices/compiled/string/{id}"); + invoiceId.ShouldNotBeNull(); + invoiceId.ShouldBe(id.ToString()); + } [Fact] public async Task endpoint_returning_compiled_query_should_return_query_result() diff --git a/src/Http/WolverineWebApi/Marten/Documents.cs b/src/Http/WolverineWebApi/Marten/Documents.cs index e628654e1..b923ae5e1 100644 --- a/src/Http/WolverineWebApi/Marten/Documents.cs +++ b/src/Http/WolverineWebApi/Marten/Documents.cs @@ -76,6 +76,12 @@ public static CompiledCountQuery GetCompiledCount() { return new CompiledCountQuery(); } + + [WolverineGet("/invoices/compiled/string/{id}")] + public static CompiledStringQuery GetCompiledString(Guid id) + { + return new CompiledStringQuery(id); + } } public class Invoice @@ -119,3 +125,16 @@ public Expression<Func<IMartenQueryable<Invoice>, int>> QueryIs() return q => q.Count(); } } +public class CompiledStringQuery : ICompiledQuery<Invoice, string> +{ + public readonly Guid Id; + + public CompiledStringQuery(Guid id) + { + Id = id; + } + public Expression<Func<IMartenQueryable<Invoice>, string>> QueryIs() + { + return q => q.Where(x => x.Id == Id).Select(x => x.Id.ToString()).First(); + } +}