GithubHelp home page GithubHelp logo

Comments (5)

douglasramos avatar douglasramos commented on May 16, 2024 2

I'd like to help. Can you tell more about what we're trying to solve here?
We could customize the WebApplicationFactory for changing database setup during tests. More specifically, on integration tests. (This link tell us more about it: https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-3.1). Particularly, the way that it is now, what we're calling integration tests are actually a unit test of the repository with some fake dbContext. And, what we're calling component test is actually the integration test (at least for asp net core context)

from clean-architecture-manga.

ivanpaulovich avatar ivanpaulovich commented on May 16, 2024 1

Hey again @douglasramos πŸ˜„

The WebApplicationFactory would make the Component/Integration Tests easier to setup. It's a good idea to see it implemented here.

My initial thoughts was to design the dependency injection of "Real Implementations" like Entity Framework fallback into "In Memory" if it is running on test mode.

Also, features like Swagger, Authentication, API Versioning need some love segregating them.

from clean-architecture-manga.

douglasramos avatar douglasramos commented on May 16, 2024

Hi, @ivanpaulovich

Hmm, interesting. I can't think of a way to build this "switcher" inside of the WebAPI project, though. At least not an elegant way. How would the server itself have the knowledge that it is under test?

The way I see, the approach would be the WebApplicationFactory act as the switcher, changing EF Core implementation to in-memory fake ones. Unfortunately, that doesn’t cover unit test cases.

Let me know if you have any more thoughts on this :)

from clean-architecture-manga.

ivanpaulovich avatar ivanpaulovich commented on May 16, 2024

Hi @douglasramos,

Sorry for the delay in answering this topic.

Did you see the new CustomWebApplicationFactory.cs? The current implementation tells the WebAPI to UseFake and it loads the in-memory implementation.

public sealed class CustomWebApplicationFactory : WebApplicationFactory<Startup>
{
    protected override void ConfigureWebHost(IWebHostBuilder builder) => builder.ConfigureAppConfiguration(
        (context, config) =>
        {
            config.AddInMemoryCollection(
                new Dictionary<string, string> {["PersistenceModule:UseFake"] = "true"});
        }).ConfigureServices(services =>
    {
        services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = "Test";
                x.DefaultChallengeScheme = "Test";
            })
            .AddScheme<AuthenticationSchemeOptions, TestAuthenticationHandler>(
                "Test", options => { });
    });
}

from clean-architecture-manga.

ivanpaulovich avatar ivanpaulovich commented on May 16, 2024

Closing as topic is too old.

from clean-architecture-manga.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.