Add tests for invalid functions warnings

This commit is contained in:
Cédric Luthi 2017-11-13 18:32:02 +01:00 коммит произвёл Ahmed ElSayed
Родитель 691c67aee1
Коммит ea6d0cbb0e
2 изменённых файлов: 29 добавлений и 3 удалений

Просмотреть файл

@ -139,11 +139,11 @@ namespace MakeFunctionJson
}
else if (method.HasFunctionNameAttribute())
{
_logger.LogWarning($"Method {method.Name} is missing a trigger attribute. Both a trigger attribute and FunctionName attribute are required for an Azure function definition.");
_logger.LogWarning($"Method {method.ReflectedType?.FullName}.{method.Name} is missing a trigger attribute. Both a trigger attribute and FunctionName attribute are required for an Azure function definition.");
}
else if (method.HasWebJobSdkAttribute())
{
_logger.LogWarning($"Method {method.Name} is missing the 'FunctionName' attribute. Both a trigger attribute and 'FunctionName' are required for an Azure function definition.");
_logger.LogWarning($"Method {method.ReflectedType?.FullName}.{method.Name} is missing the 'FunctionName' attribute. Both a trigger attribute and 'FunctionName' are required for an Azure function definition.");
}
}
}

Просмотреть файл

@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using FluentAssertions;
@ -61,5 +62,30 @@ namespace Microsoft.NET.Sdk.Functions.Test
logger.Errors.Should().BeEmpty();
logger.Warnings.Should().BeEmpty();
}
public class InvalidFunctionBecauseOfMissingTrigger
{
[FunctionName("MyServiceBusTrigger")]
public static void Run(string message) { }
}
public class InvalidFunctionBecauseOfMissingFunctionName
{
public static void Run([ServiceBusTrigger("queue")] string message) { }
}
[Theory]
[InlineData(typeof(InvalidFunctionBecauseOfMissingTrigger), "Method Microsoft.NET.Sdk.Functions.Test.FunctionJsonConverterTests+InvalidFunctionBecauseOfMissingTrigger.Run is missing a trigger attribute. Both a trigger attribute and FunctionName attribute are required for an Azure function definition.")]
[InlineData(typeof(InvalidFunctionBecauseOfMissingFunctionName), "Method Microsoft.NET.Sdk.Functions.Test.FunctionJsonConverterTests+InvalidFunctionBecauseOfMissingFunctionName.Run is missing the 'FunctionName' attribute. Both a trigger attribute and 'FunctionName' are required for an Azure function definition.")]
public void InvalidFunctionMethodProducesWarning(Type type, string warningMessage)
{
var logger = new RecorderLogger();
var converter = new FunctionJsonConverter(logger, ".", ".");
var functions = converter.GenerateFunctions(new [] {type});
functions.Should().BeEmpty();
logger.Errors.Should().BeEmpty();
logger.Warnings.Should().ContainSingle();
logger.Warnings.Single().Should().Be(warningMessage);
}
}
}