Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Created January 19, 2017 06:52
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/c561dc0f25762d5605938842b267b996 to your computer and use it in GitHub Desktop.
Save justinyoo/c561dc0f25762d5605938842b267b996 to your computer and use it in GitHub Desktop.
Testing Precompiled Azure Functions
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