Skip to content

Commit dd71fbb

Browse files
committed
Format and add dedicated EF tests
1 parent 0eaff92 commit dd71fbb

250 files changed

Lines changed: 7020 additions & 5896 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.csharpierrc‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"printWidth": 200,
3+
"useTabs": false,
4+
"tabWidth": 4,
5+
"endOfLine": "auto"
6+
}

‎EntityGraphQL.sln‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "subscriptions", "src\exampl
2525
EndProject
2626
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureFunctionApp", "src\examples\AzureFunctionApp\AzureFunctionApp.csproj", "{37B1BF94-489C-4C7E-9A1C-C1A9FC9CC9A4}"
2727
EndProject
28+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EntityGraphQL.EF.Tests", "src\tests\EntityGraphQL.EF.Tests\EntityGraphQL.EF.Tests.csproj", "{D5087AB2-C96F-42F4-9F34-5C8747846908}"
29+
EndProject
2830
Global
2931
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3032
Debug|Any CPU = Debug|Any CPU
@@ -131,6 +133,18 @@ Global
131133
{37B1BF94-489C-4C7E-9A1C-C1A9FC9CC9A4}.Release|x64.Build.0 = Release|Any CPU
132134
{37B1BF94-489C-4C7E-9A1C-C1A9FC9CC9A4}.Release|x86.ActiveCfg = Release|Any CPU
133135
{37B1BF94-489C-4C7E-9A1C-C1A9FC9CC9A4}.Release|x86.Build.0 = Release|Any CPU
136+
{D5087AB2-C96F-42F4-9F34-5C8747846908}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
137+
{D5087AB2-C96F-42F4-9F34-5C8747846908}.Debug|Any CPU.Build.0 = Debug|Any CPU
138+
{D5087AB2-C96F-42F4-9F34-5C8747846908}.Debug|x64.ActiveCfg = Debug|Any CPU
139+
{D5087AB2-C96F-42F4-9F34-5C8747846908}.Debug|x64.Build.0 = Debug|Any CPU
140+
{D5087AB2-C96F-42F4-9F34-5C8747846908}.Debug|x86.ActiveCfg = Debug|Any CPU
141+
{D5087AB2-C96F-42F4-9F34-5C8747846908}.Debug|x86.Build.0 = Debug|Any CPU
142+
{D5087AB2-C96F-42F4-9F34-5C8747846908}.Release|Any CPU.ActiveCfg = Release|Any CPU
143+
{D5087AB2-C96F-42F4-9F34-5C8747846908}.Release|Any CPU.Build.0 = Release|Any CPU
144+
{D5087AB2-C96F-42F4-9F34-5C8747846908}.Release|x64.ActiveCfg = Release|Any CPU
145+
{D5087AB2-C96F-42F4-9F34-5C8747846908}.Release|x64.Build.0 = Release|Any CPU
146+
{D5087AB2-C96F-42F4-9F34-5C8747846908}.Release|x86.ActiveCfg = Release|Any CPU
147+
{D5087AB2-C96F-42F4-9F34-5C8747846908}.Release|x86.Build.0 = Release|Any CPU
134148
EndGlobalSection
135149
GlobalSection(SolutionProperties) = preSolution
136150
HideSolutionNode = FALSE
@@ -146,6 +160,7 @@ Global
146160
{D8AA6BD5-5945-4997-887E-491A25378303} = {7214E34E-E71C-4604-9FD4-7ADDDFA09F26}
147161
{55645B0C-88D1-4060-AB5A-C444B36E815A} = {D8AA6BD5-5945-4997-887E-491A25378303}
148162
{37B1BF94-489C-4C7E-9A1C-C1A9FC9CC9A4} = {D8AA6BD5-5945-4997-887E-491A25378303}
163+
{D5087AB2-C96F-42F4-9F34-5C8747846908} = {5F132C01-AA1F-4241-B90F-BE4B2275B34E}
149164
EndGlobalSection
150165
GlobalSection(ExtensibilityGlobals) = postSolution
151166
SolutionGuid = {74156BCF-DABB-4919-A8AC-90629FB4565E}

‎src/Benchmarks/ArgumentsBenchmarks.cs‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Benchmarks
77
{
88
/// <summary>
99
/// Was testing the performance of using reflection to build the correct types from variables or using System.Text.Json
10-
///
10+
///
1111
/// Reflection wins
1212
/// | Method | Job | Toolchain | IterationCount | LaunchCount | WarmupCount | Mean | Error | StdDev |
1313
/// |---------------------------- |----------- |----------------------- |--------------- |------------ |------------ |------------:|-------------:|-----------:|
@@ -51,9 +51,7 @@ public class ArgumentsBenchmarks
5151
[Benchmark]
5252
public static void ObjectWithReflection()
5353
{
54-
var variables = new QueryVariables {
55-
{ "names", new { Name = "Lisa", LastName = "Simpson" } }
56-
};
54+
var variables = new QueryVariables { { "names", new { Name = "Lisa", LastName = "Simpson" } } };
5755

5856
for (int i = 0; i < 10000; i++)
5957
{
@@ -64,8 +62,15 @@ public static void ObjectWithReflection()
6462
[Benchmark]
6563
public static void ListWithReflection()
6664
{
67-
var variables = new QueryVariables {
68-
{ "names", new List<InputType2>{new InputType2{ Name = "Lisa", LastName = "Simpson" } }}
65+
var variables = new QueryVariables
66+
{
67+
{
68+
"names",
69+
new List<InputType2>
70+
{
71+
new InputType2 { Name = "Lisa", LastName = "Simpson" }
72+
}
73+
}
6974
};
7075

7176
for (int i = 0; i < 10000; i++)
@@ -88,4 +93,4 @@ internal class InputType2
8893
public string Name = string.Empty;
8994
public string LastName = string.Empty;
9095
}
91-
}
96+
}

‎src/Benchmarks/BaseBenchmark.cs‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ protected virtual SchemaProvider<BenchmarkContext> BuildSchema()
3333

3434
private void ConfigureServices(IServiceCollection services)
3535
{
36-
services
37-
.AddDbContext<BenchmarkContext>()
38-
.AddSingleton(BuildSchema());
36+
services.AddDbContext<BenchmarkContext>().AddSingleton(BuildSchema());
3937
}
4038

4139
protected BenchmarkContext GetContext()
@@ -57,4 +55,4 @@ protected void RunQuery(BenchmarkContext context, QueryRequest query, ExecutionO
5755
throw new InvalidOperationException("query failed: " + string.Join("\n", result.Errors.Select(m => m.Message)));
5856
}
5957
}
60-
}
58+
}

‎src/Benchmarks/CacheBenchmarks.cs‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ namespace Benchmarks
77
{
88
/// <summary>
99
/// Was testing the difference between always doing the first stage compile vs. a hash and look up for caching purposes
10-
///
10+
///
1111
/// Hash and look up is quicker of course
1212
/// </summary>
1313
[ShortRunJob]
1414
public class CacheBenchmarks : BaseBenchmark
1515
{
16-
private readonly string query = @"{
16+
private readonly string query =
17+
@"{
1718
movie(id: ""077b3041-307a-42ba-9ffe-1121fcfc918b"") {
1819
id name released
1920
director {
@@ -31,10 +32,7 @@ id name dob
3132
public CacheBenchmarks()
3233
{
3334
graphQLCompiler = new GraphQLCompiler(Schema);
34-
gql = new QueryRequest
35-
{
36-
Query = query
37-
};
35+
gql = new QueryRequest { Query = query };
3836

3937
queryCache = new QueryCache();
4038
queryCache.AddCompiledQuery(query, new GraphQLDocument(Schema));
@@ -52,4 +50,4 @@ public void HashAndLookup()
5250
queryCache.GetCompiledQuery(query, null);
5351
}
5452
}
55-
}
53+
}

‎src/Benchmarks/DataLoader/DataLoader.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ private static MovieGenre GetOrMakeGenre(BenchmarkContext db, string name)
6868
return person;
6969
}
7070
}
71-
}
71+
}

‎src/Benchmarks/DataLoader/MovieData.cs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,17 @@ public MoveInfo(List<string> directors, DateTime releaseDate, float rating, List
3434
}
3535

3636
public List<string> Directors { get; set; }
37+
3738
[JsonPropertyName("release_date")]
3839
public DateTime ReleaseDate { get; set; }
3940
public float Rating { get; set; }
4041
public List<string> Genres { get; set; }
4142
public string ImageUrl { get; set; }
4243
public string Plot { get; set; }
4344
public int Rank { get; set; }
45+
4446
[JsonPropertyName("running_time_secs")]
4547
public int RunningTimeSecs { get; set; }
4648
public List<string> Actors { get; set; }
4749
}
48-
}
50+
}

‎src/Benchmarks/EqlBenchmarks.cs‎

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,7 @@ public class EqlBenchmarks : BaseBenchmark
3030
public void SimpleExpression()
3131
{
3232
var expressionStr = "name == \"foo\"";
33-
var data = new Movie(
34-
Guid.NewGuid(),
35-
"foo",
36-
3,
37-
new DateTime(2021, 1, 1),
38-
new Person(Guid.NewGuid(), "Jimmy", "Rum", new DateTime(1978, 2, 4), []),
39-
[],
40-
new MovieGenre("Action")
41-
);
33+
var data = new Movie(Guid.NewGuid(), "foo", 3, new DateTime(2021, 1, 1), new Person(Guid.NewGuid(), "Jimmy", "Rum", new DateTime(1978, 2, 4), []), [], new MovieGenre("Action"));
4234
var context = Expression.Parameter(data.GetType(), "m");
4335
var expression = EntityQueryCompiler.CompileWith(expressionStr, context, Schema, new QueryRequestContext(null, null), new ExecutionOptions());
4436
}
@@ -47,15 +39,7 @@ public void SimpleExpression()
4739
public void ComplexExpression()
4840
{
4941
var expressionStr = "name == \"foo\" && director.name == \"Jimmy\" && director.dob > \"1978-02-04\" && genre.name == \"Action\" && rating > 3";
50-
var data = new Movie(
51-
Guid.NewGuid(),
52-
"foo",
53-
3,
54-
new DateTime(2021, 1, 1),
55-
new Person(Guid.NewGuid(), "Jimmy", "Rum", new DateTime(1978, 2, 4), []),
56-
[],
57-
new MovieGenre("Action")
58-
);
42+
var data = new Movie(Guid.NewGuid(), "foo", 3, new DateTime(2021, 1, 1), new Person(Guid.NewGuid(), "Jimmy", "Rum", new DateTime(1978, 2, 4), []), [], new MovieGenre("Action"));
5943
var context = Expression.Parameter(data.GetType(), "m");
6044
var expression = EntityQueryCompiler.CompileWith(expressionStr, context, Schema, new QueryRequestContext(null, null), new ExecutionOptions());
6145
}
@@ -65,15 +49,7 @@ public void ComplexWithMethodCallExpression()
6549
{
6650
var expressionStr =
6751
"name.contains(\"fo\") && director.name.toLower().startsWith(\"ji\") && director.dob > \"1978-01-01\" && actors.orderBy(name).first().name.startsWith(\"bob\") && rating > 3";
68-
var data = new Movie(
69-
Guid.NewGuid(),
70-
"foo",
71-
3,
72-
new DateTime(2021, 1, 1),
73-
new Person(Guid.NewGuid(), "Jimmy", "Rum", new DateTime(1978, 2, 4), []),
74-
[],
75-
new MovieGenre("Action")
76-
);
52+
var data = new Movie(Guid.NewGuid(), "foo", 3, new DateTime(2021, 1, 1), new Person(Guid.NewGuid(), "Jimmy", "Rum", new DateTime(1978, 2, 4), []), [], new MovieGenre("Action"));
7753
var context = Expression.Parameter(data.GetType(), "m");
7854
var expression = EntityQueryCompiler.CompileWith(expressionStr, context, Schema, new QueryRequestContext(null, null), new ExecutionOptions());
7955
}

‎src/Benchmarks/Migrations/20210823055744_init.cs‎

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ protected override void Up(MigrationBuilder migrationBuilder)
99
{
1010
migrationBuilder.CreateTable(
1111
name: "Genres",
12-
columns: table => new
13-
{
14-
Name = table.Column<string>(type: "TEXT", nullable: false)
15-
},
12+
columns: table => new { Name = table.Column<string>(type: "TEXT", nullable: false) },
1613
constraints: table =>
1714
{
1815
table.PrimaryKey("PK_Genres", x => x.Name);
19-
});
16+
}
17+
);
2018

2119
migrationBuilder.CreateTable(
2220
name: "Movies",
@@ -32,13 +30,9 @@ protected override void Up(MigrationBuilder migrationBuilder)
3230
constraints: table =>
3331
{
3432
table.PrimaryKey("PK_Movies", x => x.Id);
35-
table.ForeignKey(
36-
name: "FK_Movies_Genres_GenreName",
37-
column: x => x.GenreName,
38-
principalTable: "Genres",
39-
principalColumn: "Name",
40-
onDelete: ReferentialAction.Restrict);
41-
});
33+
table.ForeignKey(name: "FK_Movies_Genres_GenreName", column: x => x.GenreName, principalTable: "Genres", principalColumn: "Name", onDelete: ReferentialAction.Restrict);
34+
}
35+
);
4236

4337
migrationBuilder.CreateTable(
4438
name: "People",
@@ -53,56 +47,37 @@ protected override void Up(MigrationBuilder migrationBuilder)
5347
constraints: table =>
5448
{
5549
table.PrimaryKey("PK_People", x => x.Id);
56-
table.ForeignKey(
57-
name: "FK_People_Movies_MovieId",
58-
column: x => x.MovieId,
59-
principalTable: "Movies",
60-
principalColumn: "Id",
61-
onDelete: ReferentialAction.Restrict);
62-
});
50+
table.ForeignKey(name: "FK_People_Movies_MovieId", column: x => x.MovieId, principalTable: "Movies", principalColumn: "Id", onDelete: ReferentialAction.Restrict);
51+
}
52+
);
6353

64-
migrationBuilder.CreateIndex(
65-
name: "IX_Movies_DirectorId",
66-
table: "Movies",
67-
column: "DirectorId");
54+
migrationBuilder.CreateIndex(name: "IX_Movies_DirectorId", table: "Movies", column: "DirectorId");
6855

69-
migrationBuilder.CreateIndex(
70-
name: "IX_Movies_GenreName",
71-
table: "Movies",
72-
column: "GenreName");
56+
migrationBuilder.CreateIndex(name: "IX_Movies_GenreName", table: "Movies", column: "GenreName");
7357

74-
migrationBuilder.CreateIndex(
75-
name: "IX_People_MovieId",
76-
table: "People",
77-
column: "MovieId");
58+
migrationBuilder.CreateIndex(name: "IX_People_MovieId", table: "People", column: "MovieId");
7859

7960
migrationBuilder.AddForeignKey(
8061
name: "FK_Movies_People_DirectorId",
8162
table: "Movies",
8263
column: "DirectorId",
8364
principalTable: "People",
8465
principalColumn: "Id",
85-
onDelete: ReferentialAction.Restrict);
66+
onDelete: ReferentialAction.Restrict
67+
);
8668
}
8769

8870
protected override void Down(MigrationBuilder migrationBuilder)
8971
{
90-
migrationBuilder.DropForeignKey(
91-
name: "FK_Movies_Genres_GenreName",
92-
table: "Movies");
72+
migrationBuilder.DropForeignKey(name: "FK_Movies_Genres_GenreName", table: "Movies");
9373

94-
migrationBuilder.DropForeignKey(
95-
name: "FK_Movies_People_DirectorId",
96-
table: "Movies");
74+
migrationBuilder.DropForeignKey(name: "FK_Movies_People_DirectorId", table: "Movies");
9775

98-
migrationBuilder.DropTable(
99-
name: "Genres");
76+
migrationBuilder.DropTable(name: "Genres");
10077

101-
migrationBuilder.DropTable(
102-
name: "People");
78+
migrationBuilder.DropTable(name: "People");
10379

104-
migrationBuilder.DropTable(
105-
name: "Movies");
80+
migrationBuilder.DropTable(name: "Movies");
10681
}
10782
}
10883
}

‎src/Benchmarks/Model/BenchmarkContext.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
1414
optionsBuilder.UseSqlite("Data Source=movies.db");
1515
}
1616

17-
1817
protected override void OnModelCreating(ModelBuilder builder)
1918
{
2019
builder.Entity<Person>().HasKey(d => d.Id);
@@ -24,4 +23,4 @@ protected override void OnModelCreating(ModelBuilder builder)
2423
builder.Entity<Person>().HasMany(d => d.DirectorOf);
2524
}
2625
}
27-
}
26+
}

0 commit comments

Comments
 (0)