vendredi 15 novembre 2019

Azure Functions unit-testing errors (TimerTrigger. HttpFunction)

I am currently following this guide (https://docs.microsoft.com/en-us/azure/azure-functions/functions-test-a-function) for adding testing to my Azure Functions application.

Currently I have built out 8 Azure Functions which all work well, I have also added a Functions.Tests project and referenced the Azure Functions project within it.

enter image description here

Here is what the Functions.Tests currently look like.

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Xunit;

namespace Functions.Tests
{
public class FunctionsTests
{
    private readonly ILogger logger = TestFactory.CreateLogger();

    [Fact]
    public async void Http_trigger_should_return_known_string()
    {
        var request = TestFactory.CreateHttpRequest("name", "Bill");
        var response = (OkObjectResult)await HttpFunction.Run(request, logger);
        Assert.Equal("Hello, Bill", response.Value);
    }

    [Theory]
    [MemberData(nameof(TestFactory.Data), MemberType = typeof(TestFactory))]
    public async void Http_trigger_should_return_known_string_from_member_data(string queryStringKey, string queryStringValue)
    {
        var request = TestFactory.CreateHttpRequest(queryStringKey, queryStringValue);
        var response = (OkObjectResult)await HttpFunction.Run(request, logger);
        Assert.Equal($"Hello, {queryStringValue}", response.Value);
    }

    [Fact]
    public void Timer_should_log_message()
    {
        var logger = (ListLogger)TestFactory.CreateLogger(LoggerTypes.List);
        TimerTrigger.Run(null, logger);
        var msg = logger.Logs[0];
        Assert.Contains("C# Timer trigger function executed at", msg);
    }
}
}

However I am getting the following errors within FunctionsTests.cs

enter image description here

I have tried all the suggested fixes from Visual Studio and checked resources online but with no luck. Perhaps I am missing a reference? I'm not sure as I have followed the guide word for word.

Aucun commentaire:

Enregistrer un commentaire