Skip to content

Commit

Permalink
Provide IsolatedFunction test sample.
Browse files Browse the repository at this point in the history
  • Loading branch information
chullybun committed Aug 27, 2024
1 parent 5818212 commit 21df65e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
15 changes: 5 additions & 10 deletions tests/UnitTestEx.IsolatedFunction/HttpFunction.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Net;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;

namespace UnitTestEx.IsolatedFunction
Expand All @@ -15,16 +15,11 @@ public HttpFunction(ILoggerFactory loggerFactory)
}

[Function("HttpFunction")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req)
public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");

var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");

response.WriteString("Welcome to Azure Functions!");

return response;
await Task.CompletedTask;
return new OkObjectResult("Welcome to Azure Functions!");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.18.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.22.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.3.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.20.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.3.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.4" />
Expand Down
21 changes: 21 additions & 0 deletions tests/UnitTestEx.NUnit.Test/IsolatedFunctionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using NUnit.Framework;
using System.Net.Http;
using UnitTestEx.Expectations;
using UnitTestEx.IsolatedFunction;

namespace UnitTestEx.NUnit.Test
{
[TestFixture]
public class IsolatedFunctionTest
{
[Test]
public void HttpTrigger()
{
using var test = FunctionTester.Create<Startup>();
test.HttpTrigger<HttpFunction>()
.ExpectLogContains("C# HTTP trigger function processed a request.")
.Run(f => f.Run(test.CreateHttpRequest(HttpMethod.Get, "hello")))
.AssertSuccess();
}
}
}
1 change: 1 addition & 0 deletions tests/UnitTestEx.NUnit.Test/UnitTestEx.NUnit.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<ProjectReference Include="..\..\src\UnitTestEx.NUnit\UnitTestEx.NUnit.csproj" />
<ProjectReference Include="..\UnitTestEx.Api\UnitTestEx.Api.csproj" />
<ProjectReference Include="..\UnitTestEx.Function\UnitTestEx.Function.csproj" />
<ProjectReference Include="..\UnitTestEx.IsolatedFunction\UnitTestEx.IsolatedFunction.csproj" />
</ItemGroup>

</Project>

0 comments on commit 21df65e

Please sign in to comment.