OData / odata.net

ODataLib: Open Data Protocol - .NET Libraries and Frameworks
https://docs.microsoft.com/odata
Other
686 stars 349 forks source link

E2E test framework #3002

Closed ElizabethOkerio closed 3 months ago

ElizabethOkerio commented 3 months ago

Issues

This pull request fixes #2878

Description

This PR adds a framework that we will use to transition the E2E tests from using WCF services to create OData services to using to using Microsoft.AspNetCore.OData. One of the reasons for this is: WCF services are not supported in .net 8.0.

I've leveraged the Microsoft.AspNetCore.Mvc.Testing package to create an in-memory test server to enable tests to communicate with OData endpoints:

Some of the classes added:

  1. TestStartupBase - This class provides a bae class for configuring startup behavior in a .NET core or ASP.NET Core application. The methods in this class are virtual to allow developers to override them to customize the start-up behavior by for example adding some services to the pipeline etc.
  2. TestWebApplicationFactory<TStartup> - This class sets up a server for integration testing of ASP.NET Core applications. It derives from WebApplicationFactory<TStartup> a class in Microsoft.AspNetCore.Mvc.Testing which creates an instance of an application for testing purposes. An HttpClient is also automatically created when you derive from this class which is used to communicate with the test server. Since this server is in-memory and is not accessible from the browser for example, I've added a custom implementation of IHttpClientFactory that returns this instance of HttpClient. The IHttpClientFactory will set when creating a DataServiceContext. This will allow the requests to be made using the test server's HttpClient.
  3. EndToEndTestBase<T> - This class provides a convenient way to set up and manage resources needed for end-to-end testing, including HTTP client management and customization of data service context creation. Test will be deriving from this class. In the test classes, if users want to add custom services to the request pipeline, they can create a class that overrides the TestStartupBase class and use that class as the startup class to pass to WebApplicationFactory for example.
  4. I've added a samples folder that shows how to set-up the server folder- which will contain the ODataControllers with the OData APIs, the model classes, the data source, the EdmModel and the client folder- This will contain the generated code (This is code that is generated using OData Connected Service or code gen). This generated code will be used to set-up the DataServiceContext.

This Project has some of the common classes that will be shared by other test classes. We'll need to create another project to contain the server-client-test structure in the samples folder for all the tests to be rewritten.

I borrowed some of the code for structuring the in-memory test server from Microsoft.AspNetCore.OData repo tests.

Checklist (Uncheck if it is not completed).

Additional work necessary

If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.