Created
December 22, 2017 23:22
-
-
Save paulbatum/d1da9b920421ec8906f2c7bfb81c52e1 to your computer and use it in GitHub Desktop.
Example test project for testing the default http trigger in 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
using System; | |
using System.Diagnostics; | |
using System.Net; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
using System.Web.Http; | |
using FunctionApp22_UnitTesting; | |
using Microsoft.Azure.WebJobs.Host; | |
using Xunit; | |
namespace FunctionAppUnitTesting | |
{ | |
public class Tests1 | |
{ | |
[Fact] | |
public async Task TestSomething() | |
{ | |
var configuration = new HttpConfiguration(); | |
var request = new HttpRequestMessage(HttpMethod.Get, new Uri("http://myserver.com/api/run?name=paul")); | |
request.Content = new StringContent(string.Empty); | |
request.Properties[System.Web.Http.Hosting.HttpPropertyKeys.HttpConfigurationKey] = configuration; | |
var traceWriter = new ConsoleTraceWriter(TraceLevel.Verbose); | |
var result = await Function1.Run(request, traceWriter); | |
Assert.Equal(HttpStatusCode.OK, result.StatusCode); | |
} | |
} | |
public class ConsoleTraceWriter : TraceWriter | |
{ | |
public ConsoleTraceWriter(TraceLevel traceLevel) : base(traceLevel) | |
{ | |
} | |
public override void Trace(TraceEvent traceEvent) | |
{ | |
if (Level < traceEvent.Level) | |
{ | |
return; | |
} | |
Console.WriteLine(traceEvent.Message); | |
} | |
} | |
} |
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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<TargetFramework>net461</TargetFramework> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="xunit" Version="2.3.1" /> | |
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> | |
</ItemGroup> | |
<ItemGroup> | |
<ProjectReference Include="..\FunctionApp22-UnitTesting\FunctionApp22-UnitTesting.csproj" /> | |
</ItemGroup> | |
<ItemGroup> | |
<Reference Include="Microsoft.CSharp" /> | |
</ItemGroup> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment