Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit Testing: How to bypass RunPage Deserializer? #296

Open
SlyckLizzie opened this issue Jun 22, 2023 · 1 comment
Open

Unit Testing: How to bypass RunPage Deserializer? #296

SlyckLizzie opened this issue Jun 22, 2023 · 1 comment
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Up for grabs Issues that are ready to be worked on by anyone Type: Support Any questions, information, or general needs around the SDK or GitHub APIs

Comments

@SlyckLizzie
Copy link

SlyckLizzie commented Jun 22, 2023

Describe the need

I am unable to unit test when working with the Run< T > IConnection extension. I am injecting a custom HTTPClient into the connection class but it seems the deserialization process called from IRunner.RunPage in the SimpleQuery class, expects a specific format that is outside of the purposes of testing as I only want the result set obtained from the RunPage task.

The hard coded value in the httpclient is what the deserialize expects, not what it will output after deseralization.

How can I bypass this step?
or
What can I do to input custom data that will match the result?

var queryVariables = new Dictionary<string, object>
{
	{ "organization", "Whatever" },
	{ "count", 2 },
	{ "after", null }
};

var searchQuery = new Query()
	.Organization(login: Var("organization"))
	.Repositories(first: Var("count"), after: Var("after"))
	.Select(conn => new
	{
		conn.TotalCount,
		conn.PageInfo.EndCursor,
		conn.PageInfo.HasNextPage,
		Objects = conn.Nodes
			.OfType<GraphQLModel.Repository>()
			.Select(r => new
				{
					r.Name,
					r.Description
				}).ToList()
		})
	.Compile();

var httpClient = new Moq.Mock<HttpClient>().Object;
// client returns hard-coded value of  "{\"data\":{\"organization\":{\"repositories\":{\"totalCount\":10,\"endCursor\":{\"endCursor\":\"Y3Vyc29yOnYyOpHOHa9HHQ==\"},\"hasNextPage\":{\"hasNextPage\":true},\"nodes\":[{\"__typename\":\"Repository\",\"name\":\"my-repo-name\",\"description\":\"No matter\"}]}}}}" 

var graphQLProductHeader = new Octokit.GraphQL.ProductHeaderValue("UnitTests", "1.0.0");
var graphQLCredentialStore = new Octokit.GraphQL.Internal.InMemoryCredentialStore("yourToken");
var graphQLConnection = new Octokit.GraphQL.Connection(graphQLProductHeader, graphQLCredentialStore, httpClient);

// Invokes IConnection extension class Run<T> which invokes SimpleQuery.Runner.RunPage
var queryResults = await graphQLConnection.Run(searchQuery, queryVariables);

public async Task RunPage(CancellationToken cancellationToken = default)
{
var deserializer = new ResponseDeserializer();
var data = await connection.Run(parent.GetPayload(variables), cancellationToken).ConfigureAwait(false);
Result = deserializer.Deserialize(parent.ResultBuilder, data); //<---- BYPASS THIS
return false;
}

@SlyckLizzie SlyckLizzie added Status: Triage This is being looked at and prioritized Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR labels Jun 22, 2023
@SlyckLizzie SlyckLizzie changed the title [MAINT]: How to unit test when using IConnection Run<T> extension method? How to unit test when using IConnection Run<T> extension method? Jun 22, 2023
@SlyckLizzie SlyckLizzie changed the title How to unit test when using IConnection Run<T> extension method? Unit Testing: How to bypass RunPage Deserializer? Jun 22, 2023
@kfcampbell kfcampbell added Priority: Normal Status: Up for grabs Issues that are ready to be worked on by anyone Type: Support Any questions, information, or general needs around the SDK or GitHub APIs and removed Status: Triage This is being looked at and prioritized Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR labels Jun 22, 2023
@nickfloyd nickfloyd added the hacktoberfest Issues for participation in Hacktoberfest label Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Up for grabs Issues that are ready to be worked on by anyone Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects
Status: 🔥 Backlog
Development

No branches or pull requests

4 participants
@nickfloyd @kfcampbell @SlyckLizzie and others