Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Dependency Injections on Azure Functions V2
public class CoreGitHubRepositoriesHttpTriggerTests
public async Task Given_TypeAndName_Run_Should_Return_Result()
// Arrange
var github = new GitHub() { BaseUrl = "https://localhost", Endpoints = new Endpoints() { Repositories = "repositories" } };
var httpclient = new HttpClient(handler);
var container = new Mock<IServiceProvider>();
container.Setup(p => p.GetService(typeof(GitHub))).Returns(github);
container.Setup(p => p.GetService(typeof(HttpClient))).Returns(httpclient);
// Inject the mocked IServiceProvider instance.
CoreGitHubRepositoriesHttpTrigger.Container = container.Object;
var query = new FakeQueryCollection();
var req = new Mock<HttpRequest>();
req.SetupGet(p => p.Query).Returns(query);
var log = new Mock<ILogger>();
// Action
// Inject the mocked parameters
var response = await CoreGitHubRepositoriesHttpTrigger.Run(req.Object, log.Object).ConfigureAwait(false);
// Assert
(response as OkObjectResult).Value.Should().Be(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.