-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
344 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Nitrolize.Tests.Integration.Schema | ||
{ | ||
public class EntityA | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public List<EntityB> Entities { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace Nitrolize.Tests.Integration.Schema | ||
{ | ||
public class EntityB | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public double Value { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Nitrolize.Types.Base; | ||
|
||
namespace Nitrolize.Tests.Integration.Schema | ||
{ | ||
public class Mutation : MutationBase | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using GraphQL.Types; | ||
using Nitrolize.Extensions; | ||
|
||
namespace Nitrolize.Tests.Integration.Schema | ||
{ | ||
public class Query : ObjectGraphType | ||
{ | ||
public Query() | ||
{ | ||
this.Field<ViewerType>("viewer", resolve: context => new Viewer()) | ||
.RequiresAuthentication(false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Nitrolize.Tests.Integration.Schema | ||
{ | ||
public class Schema : GraphQL.Types.Schema | ||
{ | ||
public Schema() | ||
{ | ||
this.Query = new Query(); | ||
this.Mutation = new Mutation(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Nitrolize.Identification; | ||
using System; | ||
|
||
namespace Nitrolize.Tests.Integration.Schema | ||
{ | ||
public class Viewer | ||
{ | ||
public string Id { get; set; } | ||
|
||
public Viewer() | ||
{ | ||
this.Id = GlobalId.ToGlobalId("Viewer", Guid.NewGuid().ToString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Nitrolize.Convenience.Attributes; | ||
using Nitrolize.Convenience.Delegates; | ||
using Nitrolize.Models; | ||
using Nitrolize.Types.Base; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Nitrolize.Tests.Integration.Schema | ||
{ | ||
public class ViewerType : ViewerTypeBase | ||
{ | ||
[Field(IsAuthenticationRequired = false)] | ||
public Field<EntityA, Guid> EntityA => (context, id) => | ||
{ | ||
var entity = new EntityA | ||
{ | ||
Id = new Guid(), | ||
Name = "The Entity A", | ||
Entities = new List<EntityB>() | ||
{ | ||
new EntityB { Id = new Guid(), Value = 1.1 }, | ||
new EntityB { Id = new Guid(), Value = 2.2 } | ||
} | ||
}; | ||
return entity; | ||
}; | ||
|
||
[List(IsAuthenticationRequired = false)] | ||
public ListField<EntityA> EntityList => (context) => | ||
{ | ||
var list = new List<EntityA>() | ||
{ | ||
new EntityA { Id = new Guid(), Name = "No1" }, | ||
new EntityA { Id = new Guid(), Name = "No2" } | ||
}; | ||
|
||
return list; | ||
}; | ||
|
||
[Connection(IsAuthenticationRequired = false)] | ||
public ConnectionField<EntityA> EntityConnection => (context, parameters) => | ||
{ | ||
var list = new List<EntityA>() | ||
{ | ||
new EntityA { Id = new Guid(), Name = "No1" }, | ||
new EntityA { Id = new Guid(), Name = "No2" } | ||
}; | ||
var connection = new Connection<EntityA, Guid>(list); | ||
|
||
connection.PageInfo.HasPreviousPage = false; | ||
connection.PageInfo.HasNextPage = true; | ||
|
||
return connection; | ||
}; | ||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
src/Nitrolize.Tests/Integration/ViewerTypeSpecification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
using FluentAssertions; | ||
using GraphQL; | ||
using GraphQL.Http; | ||
using GraphQL.Instrumentation; | ||
using GraphQL.Validation.Complexity; | ||
using Machine.Fakes; | ||
using Machine.Specifications; | ||
using Nitrolize.Types.Base; | ||
using TestSchema = Nitrolize.Tests.Integration.Schema; | ||
|
||
namespace Nitrolize.Tests.Schema | ||
{ | ||
[Subject(typeof(ViewerTypeBase))] | ||
public class ViewerTypeSpecification : WithSubject<TestSchema.ViewerType> | ||
{ | ||
protected static IDocumentExecuter DocumentExecuter = new DocumentExecuter(); | ||
protected static IDocumentWriter DocumentWriter = new DocumentWriter(true); | ||
protected static dynamic Result; | ||
|
||
protected static object Execute(string query) | ||
{ | ||
var result = DocumentExecuter.ExecuteAsync(_ => | ||
{ | ||
_.Schema = new TestSchema.Schema(); | ||
_.Query = query; | ||
_.OperationName = null; | ||
_.Inputs = new Inputs(); | ||
|
||
_.ComplexityConfiguration = new ComplexityConfiguration { MaxDepth = 15 }; | ||
_.FieldMiddleware.Use<InstrumentFieldsMiddleware>(); | ||
_.UserContext = null; | ||
_.ValidationRules = null; | ||
}).Await().AsTask.Result; | ||
|
||
return result.Data; | ||
} | ||
} | ||
|
||
public class When_querying_a_field : ViewerTypeSpecification | ||
{ | ||
protected static string Query = @" | ||
{ | ||
viewer { | ||
entityA(id: ""VXNlciNmOTM2OGNlNC0wNjhkLTQxN2ItYmZiZi0wMDdkMzEyYTA4ZmM="") { | ||
id | ||
name | ||
} | ||
} | ||
}"; | ||
|
||
Because of = () => Result = Execute(Query); | ||
|
||
It should_return_a_property = () => { | ||
var name = (string)Result["viewer"]["entityA"]["name"]; | ||
name.Should().Be("The Entity A"); | ||
}; | ||
} | ||
|
||
public class When_querying_a_list : ViewerTypeSpecification | ||
{ | ||
protected static string Query = @" | ||
{ | ||
viewer { | ||
entityList { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
"; | ||
|
||
Because of = () => Result = Execute(Query); | ||
|
||
It should_return_items = () => ((object)Result["viewer"]["entityList"]).Should().NotBeNull(); | ||
|
||
It should_return_first_item_name = () => ((object)Result["viewer"]["entityList"][0]["name"]).Should().Be("No1"); | ||
|
||
It should_return_second_item_name = () => ((object)Result["viewer"]["entityList"][1]["name"]).Should().Be("No2"); | ||
} | ||
|
||
public class When_querying_a_connection : ViewerTypeSpecification | ||
{ | ||
protected static string Query = @" | ||
{ | ||
viewer { | ||
entityConnection(first: 100) { | ||
edges { | ||
cursor | ||
node { | ||
id | ||
name | ||
} | ||
} | ||
pageInfo { | ||
startCursor | ||
endCursor | ||
hasPreviousPage | ||
hasNextPage | ||
} | ||
} | ||
} | ||
} | ||
"; | ||
|
||
Because of = () => Result = Execute(Query); | ||
|
||
It should_return_page_info = () => ((object)Result["viewer"]["entityConnection"]["pageInfo"]).Should().NotBeNull(); | ||
|
||
It should_return_page_info_start_cursor = () => ((object)Result["viewer"]["entityConnection"]["pageInfo"]["startCursor"]).Should().NotBeNull(); | ||
|
||
It should_return_page_info_end_cursor = () => ((object)Result["viewer"]["entityConnection"]["pageInfo"]["endCursor"]).Should().NotBeNull(); | ||
|
||
It should_return_page_info_hasPreviousPage = () => ((object)Result["viewer"]["entityConnection"]["pageInfo"]["hasPreviousPage"]).Should().Be(false); | ||
|
||
It should_return_page_info_hasNextPage = () => ((object)Result["viewer"]["entityConnection"]["pageInfo"]["hasNextPage"]).Should().Be(true); | ||
|
||
It should_return_edges = () => ((object)Result["viewer"]["entityConnection"]["edges"]).Should().NotBeNull(); | ||
|
||
It should_return_first_edge_cursor = () => ((object)Result["viewer"]["entityConnection"]["edges"][0]["cursor"]).Should().NotBeNull(); | ||
|
||
It should_return_first_edge_node_name = () => ((object)Result["viewer"]["entityConnection"]["edges"][0]["node"]["name"]).Should().Be("No1"); | ||
|
||
It should_return_second_edge_cursor = () => ((object)Result["viewer"]["entityConnection"]["edges"][1]["cursor"]).Should().NotBeNull(); | ||
|
||
It should_return_second_edge_node_name = () => ((object)Result["viewer"]["entityConnection"]["edges"][1]["node"]["name"]).Should().Be("No2"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
|
||
namespace Nitrolize.Convenience.Attributes | ||
{ | ||
/// <summary> | ||
/// Speficies that the following property is a relay compatible connection. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Property)] | ||
public class ListAttribute : AuthenticationRequiredAttributeBase | ||
{ | ||
public ListAttribute() | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using GraphQL.Types; | ||
|
||
namespace Nitrolize.Convenience.Delegates | ||
{ | ||
/// <summary> | ||
/// Delegate for list fields. | ||
/// </summary> | ||
/// <typeparam name="TEntity">The type of the entity.</typeparam> | ||
/// <param name="context">The ResolveFieldContext.</param> | ||
public delegate object ListField<TEntity>(ResolveFieldContext<object> context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.