Skip to content

Commit

Permalink
Auto-Merge Schema - Part 1 (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Feb 22, 2019
1 parent 4b22f09 commit 393bb84
Show file tree
Hide file tree
Showing 368 changed files with 31,156 additions and 2,073 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ jobs:
- image: chillicream/dotnet-build:3.0
steps:
- checkout
- run:
name: Check that Templates Compile
command: dotnet cake -target=TemplatesCompile
- run:
name: Pull Request Build
command: dotnet cake -target=CoreTests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,4 @@ tools/**

testoutput/
artifacts/
__mismatch__
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ branches:
- master
script:
- dotnet tool install -g Cake.Tool
- dotnet cake -target=CoreTests
- dotnet cake -target=TemplatesCompile
- dotnet cake -target=CoreTests
17 changes: 15 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ Task("PublishTemplates")
OutputDirectory = "src/Templates"
};

ReplaceTextInFiles("src/Templates/StarWars/content/StarWars/StarWars.csproj", "0.7.0-preview.34", packageVersion);
ReplaceTextInFiles("src/Templates/Server/content/HotChocolate.Server.csproj", "0.7.0-preview.34", packageVersion);
ReplaceTextInFiles("src/Templates/StarWars/content/StarWars/StarWars.csproj", "0.7.0", packageVersion);
ReplaceTextInFiles("src/Templates/Server/content/HotChocolate.Server.csproj", "0.7.0", packageVersion);
NuGetPack("src/Templates/StarWars/HotChocolate.Templates.StarWars.nuspec", nuGetPackSettings);
NuGetPack("src/Templates/Server/HotChocolate.Templates.Server.nuspec", nuGetPackSettings);
});
Expand Down Expand Up @@ -166,6 +166,19 @@ Task("Tests")
}
});

Task("TemplatesCompile")
.IsDependentOn("EnvironmentSetup")
.Does(() =>
{
var buildSettings = new DotNetCoreBuildSettings
{
Configuration = "Debug"
};

DotNetCoreBuild("./src/Templates/Server/content", buildSettings);
DotNetCoreBuild("./src/Templates/StarWars/content", buildSettings);
});

Task("CoreTests")
.IsDependentOn("EnvironmentSetup")
.Does(() =>
Expand Down
2 changes: 1 addition & 1 deletion examples/AspNetCore.StarWars/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ passes the configured authorization rule.
app.UseGraphQL(new GraphQLMiddlewareOptions
{
Path = "/graphql",
OnCreateRequest = (c, r, p, ct) =>
OnCreateRequest = (ctx, builder, ct) =>
{
var identity = new ClaimsIdentity();
identity.AddClaim(new Claim(ClaimTypes.Country, "us"));
Expand Down
1 change: 1 addition & 0 deletions src/Core/Abstractions.Tests/Abstractions.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="ChilliCream.Testing.Utilities" Version="0.2.0" />
<PackageReference Include="Snapshooter.Xunit" Version="0.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.4.0-beta.1.build3958" />
</ItemGroup>

Expand Down
253 changes: 253 additions & 0 deletions src/Core/Abstractions.Tests/Execution/QueryRequestBuilderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
using System;
using System.Collections.Generic;
using HotChocolate.Utilities;
using Snapshooter.Xunit;
using Xunit;

namespace HotChocolate.Execution.Tests
{
public class QueryRequestBuilderTests
{
[Fact]
public void BuildRequest_OnlyQueryIsSet_RequestHasOnlyQuery()
{
// arrange
// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.Create();

// assert
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_Empty_QueryRequestBuilderException()
{
// arrange
// act
Action action = () =>
QueryRequestBuilder.New()
.Create();

// assert
Assert.Throws<QueryRequestBuilderException>(action)
.Message.MatchSnapshot();
}

[InlineData("")]
[InlineData(null)]
[Theory]
public void SetQuery_NullOrEmpty_ArgumentException(string query)
{
// arrange
// act
Action action = () =>
QueryRequestBuilder.New()
.SetQuery(query)
.Create();

// assert
Assert.Equal("query",
Assert.Throws<ArgumentException>(action).ParamName);
}

[Fact]
public void BuildRequest_QueryAndAddVariables_RequestIsCreated()
{
// arrange
// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.AddVariableValue("one", "foo")
.AddVariableValue("two", "bar")
.Create();

// assert
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_QueryAndSetVariables_RequestIsCreated()
{
// arrange
// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.AddVariableValue("one", "foo")
.AddVariableValue("two", "bar")
.SetVariableValues(new Dictionary<string, object>
{
{ "three", "baz" }
})
.Create();

// assert
// only three should be in the request
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_QueryAndResetVariables_RequestIsCreated()
{
// arrange
// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.AddVariableValue("one", "foo")
.AddVariableValue("two", "bar")
.SetVariableValues(null)
.Create();

// assert
// no variable should be in the request
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_QueryAndAddProperties_RequestIsCreated()
{
// arrange
// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.AddProperty("one", "foo")
.AddProperty("two", "bar")
.Create();

// assert
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_QueryAndSetProperties_RequestIsCreated()
{
// arrange
// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.AddProperty("one", "foo")
.AddProperty("two", "bar")
.SetProperties(new Dictionary<string, object>
{
{ "three", "baz" }
})
.Create();

// assert
// only three should be in the request
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_QueryAndResetProperties_RequestIsCreated()
{
// arrange
// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.AddProperty("one", "foo")
.AddProperty("two", "bar")
.SetProperties(null)
.Create();

// assert
// no property should be in the request
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_QueryAndInitialValue_RequestIsCreated()
{
// arrange
// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.SetInitialValue(new { a = "123" })
.Create();

// assert
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_QueryAndOperation_RequestIsCreated()
{
// arrange
// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.SetOperation("bar")
.Create();

// assert
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_QueryAndResetOperation_RequestIsCreated()
{
// arrange
// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.SetOperation("bar")
.SetOperation(null)
.Create();

// assert
// the operation should be null
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_QueryAndServices_RequestIsCreated()
{
// arrange
var service = new { a = "123" };

// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.SetServices(new DictionaryServiceProvider(
service.GetType(), service))
.Create();

// assert
request.MatchSnapshot();
}

[Fact]
public void BuildRequest_SetAll_RequestIsCreated()
{
// arrange
var service = new { a = "123" };

// act
IReadOnlyQueryRequest request =
QueryRequestBuilder.New()
.SetQuery("{ foo }")
.SetOperation("bar")
.SetInitialValue(new { a = "456" })
.AddProperty("one", "foo")
.AddVariableValue("two", "bar")
.SetServices(new DictionaryServiceProvider(
service.GetType(), service))
.Create();

// assert
request.MatchSnapshot();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
You must specify a query before creating a query request.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Query": "{ foo }",
"OperationName": null,
"VariableValues": null,
"InitialValue": null,
"Properties": null,
"Services": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Query": "{ foo }",
"OperationName": null,
"VariableValues": null,
"InitialValue": null,
"Properties": {
"one": "foo",
"two": "bar"
},
"Services": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Query": "{ foo }",
"OperationName": null,
"VariableValues": {
"one": "foo",
"two": "bar"
},
"InitialValue": null,
"Properties": null,
"Services": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Query": "{ foo }",
"OperationName": null,
"VariableValues": null,
"InitialValue": {
"a": "123"
},
"Properties": null,
"Services": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Query": "{ foo }",
"OperationName": "bar",
"VariableValues": null,
"InitialValue": null,
"Properties": null,
"Services": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Query": "{ foo }",
"OperationName": null,
"VariableValues": null,
"InitialValue": null,
"Properties": null,
"Services": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Query": "{ foo }",
"OperationName": null,
"VariableValues": null,
"InitialValue": null,
"Properties": null,
"Services": null
}
Loading

0 comments on commit 393bb84

Please sign in to comment.