Created
January 19, 2017 06:52
-
-
Save justinyoo/c561dc0f25762d5605938842b267b996 to your computer and use it in GitHub Desktop.
Testing Precompiled Azure Functions
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
public class MyHttpTriggerWithDependenciesTest | |
{ | |
[Theory] | |
[InlineData("Azure", "Functions")] | |
[InlineData("Dependency", "Test")] | |
public async void Given_NameWithDependency_HttpTrigger_ShouldReturn_Result(string name, string value) | |
{ | |
// Arrange | |
Mock<IDependency> mocked = new Mock<IDependency>(); // Create a mocked object | |
mocked.SetupGet(p => p.SomeValue).Returns(value); | |
// Inject the mocked object created into the service locator field | |
MyHttpTriggerWithDependencies.Locator.Dependency = mocked.Object; | |
var req = new HttpRequestMessage() | |
{ | |
Content = new StringContent(string.Empty), | |
RequestUri = new Uri($"http://localhost?name={name}") | |
}; | |
var log = new TraceMonitor(); | |
// Act | |
var result = await MyHttpTriggerWithDependencies.Run(req, log).ConfigureAwait(false); | |
// Assert | |
var content = await result.Content.ReadAsStringAsync().ConfigureAwait(false); | |
content.Should().ContainEquivalentOf($"Hello {name}, here's the dependency value of **{value}**"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment