Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Testing Serverless Applications - Part 1
[Theory]
[InlineData(HttpStatusCode.OK)]
public async void Given_Instance_Run_ShouldReturn_Response(HttpStatusCode statusCode)
{
var models = new[] { new ContentModel() }.ToList();
var service = new Mock<IGitHubService>();
service.Setup(p => p.GetArmTemplateDirectoriesAsync(It.IsAny<string>())).ReturnsAsync(models);
// Create a mocked IServiceLocator instance.
var locator = new Mock<IServiceLocator>();
locator.Setup(p => p.GetInstance<IGitHubService>()).Returns(service.Object);
// Inject the mocked IServiceLocator instance.
GetArmTemplateDirectoriesHttpTriggerWithServiceLocator.ServiceLocator = locator.Object;
var config = new HttpConfiguration() { Formatters = { new JsonMediaTypeFormatter() } };
var context = new HttpRequestContext() { Configuration = config };
var req = new HttpRequestMessage() { Properties = { { HttpPropertyKeys.RequestContextKey, context } } };
var log = new Mock<ILogger>();
// Run the test.
var res = await GetArmTemplateDirectoriesHttpTriggerWithServiceLocator.Run(req, log.Object).ConfigureAwait(false);
res.StatusCode.Should().Be(statusCode);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment