Skip to content

Commit

Permalink
tests: Added a test for the string case. Test fails but unrelated to
Browse files Browse the repository at this point in the history
changes
  • Loading branch information
Blackclaws authored and jeremydmiller committed Jan 26, 2024
1 parent c82c624 commit d8567d0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/Http/Wolverine.Http.Tests/Marten/compiled_query_writer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 19 additions & 0 deletions src/Http/WolverineWebApi/Marten/Documents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}

0 comments on commit d8567d0

Please sign in to comment.