Created
July 19, 2017 12:55
-
-
Save justinyoo/8a35161ee5c82a232a03fccbc07e345a to your computer and use it in GitHub Desktop.
Testing Serverless Applications - Part 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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