Skip to content

Refactor REST API tests to use aspnet test server#706

Merged
ayush3797 merged 35 commits into
mainfrom
dev/agarwalayush/RestTestPipeline
Aug 23, 2022
Merged

Refactor REST API tests to use aspnet test server#706
ayush3797 merged 35 commits into
mainfrom
dev/agarwalayush/RestTestPipeline

Conversation

@ayush3797

@ayush3797 ayush3797 commented Aug 17, 2022

Copy link
Copy Markdown
Contributor

Why is this change required?
Currently we create objects for classes like RestController,RestService etc. to execute the RestApiTests. This is not a good approach because as our codebase gets complex, we would need to mimic the behaviour of runtime which will get complex as well. Hence this PR replaces the the use of such mocked up objects and use HttpClient to execute the tests. GraphQL already uses HttpClient for its tests. Moreover, previously the tests did not use to go through all the middlewares which are there in the runtime pipeline(like AuthorizationMiddleware). Switching to HttpClient would include those middlewares in the test pipeline as well.

What is the change?
Instead of creating objects for RestController and RestService we now use HttpClient to send requests as specified in the test to the engine. And then consequently, there are some differences as to how HttpClient deals with sending requests to the engine as compared to the previous approach we have. This PR does all those changes.

How was this validated?
All the tests like the PUT,PATCH,FIND,INSERT,DELETE which are already present in the {OperationName}ApiTestBase.cs classes, are passing after making the changes which validates the code change.

IMPORTANT NOTE
There are Rest api tests which have dependency on this fix which is yet to be merged : #690. And hence there are some temporary changes in this PR which I have included so that the test pass for the time being. I will revert back those once the above mentioned PR is merged. Please ignore the changes in the SqlQueryStructure.cs, RequestParser.cs and ODataAstVistor.cs classes for the above reason.

@ayush3797 ayush3797 linked an issue Aug 17, 2022 that may be closed by this pull request
@ayush3797

Copy link
Copy Markdown
Contributor Author

There are Rest api tests which have dependency on this fix which is yet to be merged : #690. And hence there are some temporary changes in this PR which I have included so that the test pass for the time being. I will revert back those once the above mentioned PR is merged.

Comment thread src/Service.Tests/SqlTests/RestApiTests/RestApiTestBase.cs Outdated
Comment thread src/Service/Parsers/ODataASTVisitor.cs Outdated
Comment thread src/Service/Parsers/RequestParser.cs Outdated
Comment thread src/Service/Resolvers/Sql Query Structures/SqlQueryStructure.cs Outdated
Comment thread src/Service.Tests/SqlTests/SqlTestBase.cs

@seantleonard seantleonard left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing this big refactor! Few questions to clarify before merging this in + additional details and examples requested in PR description/comments.

Comment thread src/Service.Tests/SqlTests/SqlTestBase.cs
Comment thread src/Service.Tests/SqlTests/SqlTestHelper.cs
Comment thread src/Service.Tests/SqlTests/SqlTestHelper.cs Outdated
@ayush3797 ayush3797 requested a review from seantleonard August 22, 2022 09:39
Comment thread src/Service.Tests/SqlTests/SqlTestHelper.cs

@aaronburtle aaronburtle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT! This might have some conflicts if this PR merges first: #690 so if you have any issues with that please let me know. Big refactor which should really help our test functionality, thanks for taking charge of this.

@seantleonard seantleonard left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few more changes requested and then will be in a good state.

Comment thread src/Service/dab-config.MsSql.json
Comment thread src/Service/dab-config.MsSql.json
Comment thread src/Service.Tests/SqlTests/SqlTestHelper.cs Outdated
Comment thread src/Service.Tests/SqlTests/SqlTestHelper.cs Outdated
Comment thread src/Service.Tests/SqlTests/SqlTestHelper.cs
Comment thread src/Service.Tests/SqlTests/SqlTestBase.cs Outdated
@ayush3797 ayush3797 requested a review from seantleonard August 23, 2022 05:28

@seantleonard seantleonard left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last little nit. thanks for addressing comments!

Comment thread src/Service.Tests/SqlTests/SqlTestHelper.cs Outdated
@ayush3797 ayush3797 merged commit 3327455 into main Aug 23, 2022
@ayush3797 ayush3797 deleted the dev/agarwalayush/RestTestPipeline branch August 23, 2022 06:32
@ayush3797 ayush3797 self-assigned this Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor REST API tests to use aspnet test server

3 participants