Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions GraphQL-Core.Tests/GraphQL-Core.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RootNamespace>GraphQL_Core.Tests</RootNamespace>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GraphQL-Core\GraphQL-Core.csproj" />
</ItemGroup>

</Project>
33 changes: 33 additions & 0 deletions GraphQL-Core.Tests/Initialize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using GraphQL;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;

namespace GraphQL_Core.Tests
{
[TestClass]
public class Initializer
{
public IServiceCollection services { get; set; }
public ServiceProvider provider { get; set; }
public IDependencyResolver resolver { get; set; }

[TestInitialize()]
public void Init()
{
services = new ServiceCollection();
provider = services.BuildServiceProvider();
resolver = new FuncDependencyResolver(type =>
{
var service = services.Where(svc => svc.ServiceType == type).FirstOrDefault();
if (service is null || service.ImplementationInstance is null)
{
return provider.GetService(type);
}

return service.ImplementationInstance;
});
}
}
}
18 changes: 18 additions & 0 deletions GraphQL-Core.Tests/Models/Enum/AuthorType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace GraphQL_Core.Tests.Models.Enum
{
public enum AuthorType
{
INTERNATIONAL,
BESTSELLING,
REGIONAL,
LOCAL,
POLITICAL,
NEWS,
BLOGGER,
PROFESSOR
}
}
22 changes: 22 additions & 0 deletions GraphQL-Core.Tests/Models/Enum/BookType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace GraphQL_Core.Tests.Models.Enum
{
public enum BookType
{
HORROR,
COMEDY,
DRAMA,
ROMANCE,
ADVENTURE,
MYSTERY,
ACTION,
FANTASY,
GRAPHIC,
CHILDREN,
YOUNGADULT,
ADULT
}
}
10 changes: 10 additions & 0 deletions GraphQL-Core.Tests/Models/Interfaces/ICommonInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace GraphQL_Core.Tests.Models.Interfaces
{
public interface ICommonInterface
{
}
}
76 changes: 76 additions & 0 deletions GraphQL-Core.Tests/Models/UserType/Author.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using GraphQL_Core.Tests.Models.Enum;
using GraphQL_Core.Tests.Models.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GraphQL_Core.Tests.Models
{
/// <summary>
/// Contains data types supported by GraphQL-dotnet
/// </summary>
public class Author
{
public long AuthorId { get; set; }
public string Name { get; set; }
public int PhoneNumber { get; set; }
public bool IsAlive { get; set; }
public float Rating { get; set; }
public double NetWorth { get; set; }
}

public struct AuthorDescription
{
public string History { get; set; }
}

/// <summary>
/// Extends the Author class by adding all C# value types
/// <para>
/// <see cref="!:https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/value-types"></see>
/// </para>
/// </summary>
public class Author_WithValueTypes : Author
{
public Guid Identifier { get; set; }
public char Gender { get; set; }
public decimal Dewey { get; set; }
public byte BooksWritten { get; set; }
public sbyte Modifier { get; set; }
public short ChildrenCount { get; set; }
public uint Age { get; set; }
public ulong PagesWritten { get; set; }
public ushort ParentCount { get; set; }
}

public class Author_WithValueTypesAndStruct : Author_WithValueTypes
{
public AuthorDescription Info { get; set; }
}

public class Author_WithEnumTypes : Author
{
public AuthorType Type { get; set; }
}

public class Author_WithBooks : Author
{
public Book Book { get; set; }
}

public class Author_WithEnumerableBooks : Author
{
public IEnumerable<Book> Books { get; set; }
}

public class Author_WithManyManyBooks : Author
{
public IEnumerable<IQueryable<IList<Book>>> ManyBooks { get; set; }
}

public class Author_WithCommonInterface : Author, ICommonInterface
{
public int DumbField { get; set; }
}
}
126 changes: 126 additions & 0 deletions GraphQL-Core.Tests/Models/UserType/Book.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using GraphQL_Core.Tests.Models.Enum;
using GraphQL_Core.Tests.Models.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GraphQL_Core.Tests.Models
{
/// <summary>
/// Contains data types supported by GraphQL-dotnet
/// </summary>
public class Book
{
public long BookId { get; set; }
public string Name { get; set; }
public int Number { get; set; }
public bool IsAvailable { get; set; }
public float Rating { get; set; }
public double Cost { get; set; }
}

public struct BookDescription
{
public string Blurb { get; set; }
}

/// <summary>
/// Extends the Book class by adding all C# value types
/// <para>
/// <see cref="!:https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/value-types"></see>
/// </para>
/// </summary>
public class Book_WithValueTypes : Book
{
public Guid Identifier { get; set; }
public char Category { get; set; }
public decimal Dewey { get; set; }
public byte OwnerCount { get; set; }
public sbyte Modifier { get; set; }
public short Value { get; set; }
public uint Copies { get; set; }
public ulong Pages { get; set; }
public ushort AuthorCount { get; set; }
}

public class Book_WithValueTypesAndStruct : Book_WithValueTypes
{
public BookDescription Info { get; set; }
}

public class Book_WithDateTime : Book
{
public DateTime PublishDate { get; set; }
}

public class Book_WithEnumerables : Book
{
public List<int> OwnerIds { get; set; }
public IList<float> SiteRatings { get; set; }
public IQueryable<double> AvgSalesPerMonth { get; set; }
public IEnumerable<bool> AreFavorited { get; set; }
}

public class Book_WithAdvancedEnumerables : Book_WithEnumerables
{
public List<IEnumerable<IQueryable<int>>> Fans { get; set; }
}

public class Book_WithEnumTypes : Book
{
public BookType Type { get; set; }
}

public class Book_WithAuthor : Book
{
public Author Author { get; set; }
}

public class Book_WithVirtualAuthor : Book
{
public virtual Author Author { get; set; }
}

public class Book_WithVirtualAuthorAndId : Book
{
public long AuthorId { get; set; }
public virtual Author Author { get; set; }
}

public class Book_WithTwoAuthors : Book
{
public virtual Author AuthorA { get; set; }
public virtual Author AuthorB { get; set; }
}

public class Book_WithDuplicateBaseTypes : Book
{
public long Duplicate_BookId { get; set; }
public string Duplicate_Name { get; set; }
public int Duplicate_Number { get; set; }
public bool Duplicate_IsAvailable { get; set; }
public float Duplicate_Rating { get; set; }
public double Duplicate_Cost { get; set; }
}

public class Book_WithCommonInterface : Book, ICommonInterface
{
public int DumbField { get; set; }
}

public class Book_WithSameInterfaceAsProperty : Book, ICommonInterface
{
public Author_WithCommonInterface Author { get; set; }
}

public class Book_WithSameInterfaceAsProperty_WithVirtualProperty : Book, ICommonInterface
{
public virtual Author_WithCommonInterface Author { get; set; }
}

public class Book_WithConstructor : Book
{
public Book_WithConstructor() { }
}
}
22 changes: 22 additions & 0 deletions GraphQL-Core.Tests/StitchTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using GraphQLCore;
using GraphQL_Core.Tests.Models;

namespace GraphQL_Core.Tests
{
[TestClass]
public class StitchTests
{
public Initializer initializer { get; set; } = new Initializer();

[TestMethod]
[TestCategory("Stitch")]
public void Test_StitchUserModels_ParseField()
{
initializer.Init();
initializer.services.AddGraphQL()
.Type<Book>()
.Build();
}
}
}
Loading