Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinyoo/8a35161ee5c82a232a03fccbc07e345a to your computer and use it in GitHub Desktop.
Save justinyoo/8a35161ee5c82a232a03fccbc07e345a to your computer and use it in GitHub Desktop.
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