mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2026-05-18 17:26:35 +00:00
Checkpoint (still hacking about)
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
namespace EntityFrameworkCore.Projections.FunctionalTests.ExtensionMethods
|
||||
{
|
||||
|
||||
public partial class ExtensionMethodTests
|
||||
{
|
||||
public class Entity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
namespace EntityFrameworkCore.Projections.FunctionalTests.ExtensionMethods
|
||||
{
|
||||
public static class EntityExtensions
|
||||
{
|
||||
[Projectable]
|
||||
public static int Foo(this ExtensionMethodTests.Entity entity) => entity.Id + 1;
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using EntityFrameworkCore.Projections.FunctionalTests.Helpers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ScenarioTests;
|
||||
using Xunit;
|
||||
|
||||
namespace EntityFrameworkCore.Projections.FunctionalTests.ExtensionMethods
|
||||
{
|
||||
|
||||
public partial class ExtensionMethodTests
|
||||
{
|
||||
[Scenario(NamingPolicy = ScenarioTestMethodNamingPolicy.Test)]
|
||||
public void PlayScenario(ScenarioContext scenario)
|
||||
{
|
||||
using var dbContext = new SampleDbContext<Entity>();
|
||||
|
||||
scenario.Fact("We can select on a projectable extension method", () => {
|
||||
const string expectedQueryString = "SELECT [e].[Id]\r\nFROM [Entity] AS [e]";
|
||||
|
||||
var query = dbContext.Set<Entity>()
|
||||
.Select(x => x.Foo());
|
||||
|
||||
Assert.Equal(expectedQueryString, query.ToQueryString());
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlTypes;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using EntityFrameworkCore.Projections.FunctionalTests.Helpers;
|
||||
using EntityFrameworkCore.Projections.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ScenarioTests;
|
||||
using Xunit;
|
||||
|
||||
namespace EntityFrameworkCore.Projections.FunctionalTests
|
||||
{
|
||||
public partial class StatefullComplexFunctionTests
|
||||
{
|
||||
public record Entity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Projectable]
|
||||
public int Computed(int argument) => Id + argument;
|
||||
}
|
||||
|
||||
[Scenario(NamingPolicy = ScenarioTestMethodNamingPolicy.Test)]
|
||||
public void PlayScenario(ScenarioContext scenario)
|
||||
{
|
||||
// Setup
|
||||
using var dbContext = new SampleDbContext<Entity>();
|
||||
|
||||
scenario.Fact("We can filter on a projectable property", () => {
|
||||
const string expectedQueryString =
|
||||
@"DECLARE @__argument_0 int = 1;
|
||||
|
||||
SELECT [e].[Id]
|
||||
FROM [Entity] AS [e]
|
||||
WHERE ([e].[Id] + @__argument_0) = 2";
|
||||
|
||||
var query = dbContext.Set<Entity>().AsQueryable()
|
||||
.Where(x => x.Computed(1) == 2);
|
||||
|
||||
Assert.Equal(expectedQueryString, query.ToQueryString());
|
||||
});
|
||||
|
||||
scenario.Fact("We can select on a projectable property", () => {
|
||||
const string expectedQueryString =
|
||||
@"DECLARE @__argument_0 int = 1;
|
||||
|
||||
SELECT [e].[Id] + @__argument_0
|
||||
FROM [Entity] AS [e]";
|
||||
|
||||
var query = dbContext.Set<Entity>()
|
||||
.AsQueryable()
|
||||
.Select(x => x.Computed(1));
|
||||
|
||||
Assert.Equal(expectedQueryString, query.ToQueryString());
|
||||
});
|
||||
|
||||
scenario.Fact("We can pass in variables", () => {
|
||||
const string expectedQueryString =
|
||||
@"DECLARE @__argument_0 int = 1;
|
||||
|
||||
SELECT [e].[Id] + @__argument_0
|
||||
FROM [Entity] AS [e]";
|
||||
|
||||
var argument = 1;
|
||||
var query = dbContext.Set<Entity>()
|
||||
.Select(x => x.Computed(argument));
|
||||
|
||||
Assert.Equal(expectedQueryString, query.ToQueryString());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
-5
@@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using EntityFrameworkCore.Projections.FunctionalTests.Helpers;
|
||||
using EntityFrameworkCore.Projections.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ScenarioTests;
|
||||
using Xunit;
|
||||
@@ -28,25 +29,39 @@ namespace EntityFrameworkCore.Projections.FunctionalTests
|
||||
using var dbContext = new SampleDbContext<Entity>();
|
||||
|
||||
scenario.Fact("We can filter on a projectable property", () => {
|
||||
const string expectedQueryString = "SELECT [e].[Id]\r\nFROM [Entity] AS [e]\r\nWHERE 0 = 1";
|
||||
const string expectedQueryString =
|
||||
@"DECLARE @__p_0 bit = CAST(0 AS bit);
|
||||
|
||||
var query = dbContext.Set<Entity>()
|
||||
SELECT [e].[Id]
|
||||
FROM [Entity] AS [e]
|
||||
WHERE @__p_0 = CAST(1 AS bit)";
|
||||
|
||||
var query = dbContext.Set<Entity>().AsQueryable()
|
||||
.Where(x => x.Computed(0) == 1);
|
||||
|
||||
Assert.Equal(expectedQueryString, query.ToQueryString());
|
||||
});
|
||||
|
||||
scenario.Fact("We can select on a projectable property", () => {
|
||||
const string expectedQueryString = "SELECT 0\r\nFROM [Entity] AS [e]";
|
||||
const string expectedQueryString =
|
||||
@"DECLARE @__argument1_0 int = 0;
|
||||
|
||||
SELECT @__argument1_0
|
||||
FROM [Entity] AS [e]";
|
||||
|
||||
var query = dbContext.Set<Entity>()
|
||||
.AsQueryable()
|
||||
.Select(x => x.Computed(0));
|
||||
|
||||
Assert.Equal(expectedQueryString, query.ToQueryString());
|
||||
Assert.Equal(expectedQueryString, query.ToQueryString());
|
||||
});
|
||||
|
||||
scenario.Fact("We can pass in variables", () => {
|
||||
const string expectedQueryString = "SELECT 0\r\nFROM [Entity] AS [e]";
|
||||
const string expectedQueryString =
|
||||
@"DECLARE @__argument1_0 int = 0;
|
||||
|
||||
SELECT @__argument1_0
|
||||
FROM [Entity] AS [e]";
|
||||
|
||||
var argument = 0;
|
||||
var query = dbContext.Set<Entity>()
|
||||
|
||||
Reference in New Issue
Block a user