Skip to content

Commit

Permalink
Merge pull request #34 from graphql-dotnet/test-runner
Browse files Browse the repository at this point in the history
Make tests runnable from Visual Studio
  • Loading branch information
tlil authored Mar 13, 2017
2 parents a7da961 + 8d6b466 commit 404660c
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/GraphQL.Conventions/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
[assembly: AssemblyProduct("GraphQL.Conventions")]
[assembly: AssemblyCopyright("Copyright 2016-2017 Tommy Lillehagen. All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("1.1.10.0")]
[assembly: AssemblyFileVersion("1.1.10.0")]
[assembly: AssemblyInformationalVersion("1.1.10.0")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.2.0")]
[assembly: AssemblyInformationalVersion("1.2.0")]
[assembly: CLSCompliant(false)]

[assembly: InternalsVisibleTo("GraphQL.Conventions.Tests")]
3 changes: 2 additions & 1 deletion src/GraphQL.Conventions/GraphQL.Conventions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>GraphQL Conventions for .NET</Description>
<VersionPrefix>1.1.5</VersionPrefix>
<VersionPrefix>1.2.0</VersionPrefix>
<Authors>Tommy Lillehagen</Authors>
<TargetFrameworks>netstandard1.5;net45</TargetFrameworks>
<DebugType>portable</DebugType>
Expand All @@ -22,6 +22,7 @@
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/GraphQL.Conventions/project.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"version": "1.1.10-*",
"version": "1.2.0-*",
"description": "GraphQL Conventions for .NET",
"authors": [
"Tommy Lillehagen"
],
"packOptions": {
"id": "GraphQL.Conventions",
"authors": [ "Tommy Lillehagen" ],
"summary": "GraphQL Conventions for .NET",
"copyright": "Tommy Lillehagen, 2016-2017",
Expand Down
3 changes: 2 additions & 1 deletion test/Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.TestHost" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="dotnet-test-xunit" Version="2.2-preview2-*" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand Down
18 changes: 9 additions & 9 deletions test/Tests/Types/IdTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ namespace GraphQL.Conventions.Tests.Types
{
public class IdTests : TestBase
{
[Xunit.Fact]
[Test]
public void Can_Instantiate_Identifier_From_Encoded_String()
{
var id = Id("VGVzdDoxMjM0NQ==");
id.IdentifierForType<Test>().ShouldEqual("12345");
}

[Xunit.Fact]
[Test]
public void Cannot_Instantiate_Identifier_From_Encoded_String_Of_Wrong_Type()
{
var id = Id("VGVzdDoxMjM0NQ==");
Assert.ThrowsException<ArgumentException>(() => id.IdentifierForType<AnotherTest>());
}

[Xunit.Fact]
[Test]
public void Cannot_Instantiate_Identifier_From_Empty_String()
{
Assert.ThrowsException<ArgumentException>(() => Id(null));
Expand All @@ -31,13 +31,13 @@ public void Cannot_Instantiate_Identifier_From_Empty_String()
nullableId.HasValue.ShouldEqual(false);
}

[Xunit.Fact]
[Test]
public void Cannot_Instantiate_Identifier_From_Invalid_Base64_String()
{
Assert.ThrowsException<ArgumentException>(() => Id("abcdef"));
}

[Xunit.Fact]
[Test]
public void Can_Sort_Identifiers_Serialized_Using_Colon_Separators()
{
var id0 = Id<IdTests>("12345", true);
Expand All @@ -62,7 +62,7 @@ public void Can_Sort_Identifiers_Serialized_Using_Colon_Separators()
Assert.IsTrue(id3 != id4);
}

[Xunit.Fact]
[Test]
public void Can_Sort_Identifiers_Serialized_Without_Using_Colon_Separators()
{
var id0 = Id<IdTests>("12345", false);
Expand All @@ -87,7 +87,7 @@ public void Can_Sort_Identifiers_Serialized_Without_Using_Colon_Separators()
Assert.IsTrue(id3 != id4);
}

[Xunit.Fact]
[Test]
public void Can_Decode_Identifiers_Unambiguously_When_Serialized_With_Colon()
{
Id<TestItem>("12345").IsIdentifierForType<Test>()
Expand All @@ -96,7 +96,7 @@ public void Can_Decode_Identifiers_Unambiguously_When_Serialized_With_Colon()
.ShouldBeFalse("Identifier for type 'Test' thought to be an identifier for type 'TestItem'.");
}

[Xunit.Fact]
[Test]
public void Can_Decode_Identifiers_Unambiguously_When_Serialized_Without_Colon()
{
Id<TestItem>("12345", false).IsIdentifierForType<Test>()
Expand All @@ -105,7 +105,7 @@ public void Can_Decode_Identifiers_Unambiguously_When_Serialized_Without_Colon()
.ShouldBeFalse("Identifier for type 'Test' thought to be an identifier for type 'TestItem'.");
}

[Xunit.Fact]
[Test]
public void Cannot_Decode_Empty_Identifiers()
{
Assert.ThrowsException<ArgumentException>(() => Id<Test>("", true).IdentifierForType<Test>());
Expand Down
48 changes: 48 additions & 0 deletions test/Tests/Web/RequestHandlerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Threading.Tasks;
using GraphQL.Conventions.Tests.Templates;
using GraphQL.Conventions.Tests.Templates.Extensions;
using GraphQL.Conventions.Web;

namespace GraphQL.Conventions.Tests.Web
{
public class RequestHandlerTests : TestBase
{
[Test]
public async Task Can_Run_Query()
{
var request = Request.New("{ \"query\": \"{ hello }\" }");
var response = await RequestHandler
.New()
.WithQuery<TestQuery>()
.Generate()
.ProcessRequest(request, null);

response.ExecutionResult.Data.ShouldHaveFieldWithValue("hello", "World");
response.Body.ShouldEqual("{\"data\":{\"hello\":\"World\"}}");
response.Errors.Count.ShouldEqual(0);
response.Warnings.Count.ShouldEqual(0);
}

[Test]
public async Task Can_Run_Query_And_Report_Validation_Violations_As_Warnings()
{
var request = Request.New("{ \"query\": \"query test($foo: String) { a: hello b: hello }\" }");
var response = await RequestHandler
.New()
.WithQuery<TestQuery>()
.WithoutValidation(true)
.Generate()
.ProcessRequest(request, null);

response.Body.ShouldEqual("{\"data\":{\"a\":\"World\",\"b\":\"World\"}}");
response.Errors.Count.ShouldEqual(0);
response.Warnings.Count.ShouldEqual(1);
response.Warnings[0].ToString().ShouldEqual("GraphQL.Validation.ValidationError: Variable \"$foo\" is never used in operation \"$test\".");
}

class TestQuery
{
public string Hello => "World";
}
}
}
33 changes: 33 additions & 0 deletions test/Tests/Web/RequestTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using GraphQL.Conventions.Tests.Templates;
using GraphQL.Conventions.Tests.Templates.Extensions;
using GraphQL.Conventions.Web;

namespace GraphQL.Conventions.Tests.Web
{
public class RequestTests : TestBase
{
[Test]
public void Can_Instantiate_Request_Object_From_String()
{
var request = Request.New("{\"query\":\"{}\"}");
request.IsValid.ShouldEqual(true);
request.QueryString.ShouldEqual("{}");
request.Variables.ShouldEqual(null);
}

[Test]
public void Cannot_Instantiate_Request_Object_From_Invalid_String()
{
var request = Request.New("\"invalid_query\":\"{}\"");
request.IsValid.ShouldEqual(false);
}

[Test]
public void Cannot_Derive_Query_From_Invalid_String()
{
var request = Request.New("{\"invalid_query\":\"{}\"}");
request.IsValid.ShouldEqual(true);
request.QueryString.ShouldEqual(string.Empty);
}
}
}
32 changes: 32 additions & 0 deletions test/Tests/Web/ResponseTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Collections.Generic;
using GraphQL.Conventions.Tests.Templates;
using GraphQL.Conventions.Tests.Templates.Extensions;
using GraphQL.Conventions.Web;
using GraphQL.Validation;

namespace GraphQL.Conventions.Tests.Web
{
public class ResponseTests : TestBase
{
[Test]
public void Can_Instantiate_Response_Object_From_Execution_Result()
{
var request = Request.New("{\"query\":\"{}\"}");
var result = new ExecutionResult();
result.Data = new Dictionary<string, object>();
var response = new Response(request, result);
response.HasData.ShouldEqual(true);
response.HasErrors.ShouldEqual(false);
}

[Test]
public void Can_Instantiate_Response_Object_From_Validation_Result()
{
var request = Request.New("{\"query\":\"{}\"}");
var result = new ValidationResult();
result.Errors.Add(new ExecutionError("Test"));
var response = new Response(request, result);
response.ValidationResult.Errors.Count.ShouldEqual(1);
}
}
}
3 changes: 2 additions & 1 deletion test/Tests/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
},
"dependencies": {
"GraphQL.Conventions": { "target": "project" },
"Microsoft.TestPlatform.TestHost": "15.0.0",
"xunit": "2.2.0",
"dotnet-test-xunit": "2.2-preview2-*"
"xunit.runner.visualstudio": "2.2.0"
},
"frameworks": {
"net451": {
Expand Down

0 comments on commit 404660c

Please sign in to comment.