Skip to content

Remove MockHttp logic from library #56

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

Closed
egil opened this issue Feb 12, 2020 · 0 comments · Fixed by #59
Closed

Remove MockHttp logic from library #56

egil opened this issue Feb 12, 2020 · 0 comments · Fixed by #59
Labels
enhancement New feature or request

Comments

@egil
Copy link
Member

egil commented Feb 12, 2020

I have decided to completely remove MockHttp support in the library, and instead add a page on the Wiki describing how to do this. I do not want a dependency on a particular 3. party mocking library, just as we do not include Moq or similar.

The simple test example that adds http mocking to the TestServiceProvider looks like this:

        public async Task AddMockToLibraryExample()
        {
            using var provider = new TestServiceProvider();
            provider.AddSingleton<MockHttpMessageHandler>();
            provider.AddSingleton<HttpMessageHandler>(srv => srv.GetRequiredService<MockHttpMessageHandler>());
            provider.AddTransient<HttpClient>(srv => new HttpClient(srv.GetRequiredService<HttpMessageHandler>()));
            var mockHttp = provider.GetService<MockHttpMessageHandler>();
            var httpClient = provider.GetService<HttpClient>();

            mockHttp.When("http://localhost/api/user/*")
                .Respond("application/json", "{'name' : 'Test McGee'}"); // Respond with JSON

            var response = await httpClient.GetAsync("http://localhost/api/user/1234");
            var json = await response.Content.ReadAsStringAsync();
            
            json.ShouldBe("{'name' : 'Test McGee'}");
        }
@egil egil added the enhancement New feature or request label Feb 12, 2020
@egil egil changed the title Move MockHttp and MockJsRuntime into separate libraries Remove MockHttp logic from library Feb 24, 2020
@egil egil linked a pull request Feb 24, 2020 that will close this issue
14 tasks
@egil egil closed this as completed Feb 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant