c# - 将指南传递给测试方法

标签 c# guid xunit.net

[InlineData(Guid.Empty)]
[InlineData("00000000-0000-0000-0000-000000000000")]
[Theory]
public async Task Get_ValidateInput(Guid Id) 
{ ... }

[InlineData(Guid.Empty)] 给出编译时错误:

CS0182 - An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type.

[InlineData("00000000-0000-0000-0000-000000000000")] 给出运行时错误:

Specified method not supported.

最佳答案

解决方法!

    [InlineData(null)]                                    //null
    [InlineData("00000000-0000-0000-0000-000000000000")]  //Empty Guid
    [InlineData("")]                                      //Empty string
    [Theory]
    public async Task Get_ValidateInput(object Id)
    {
        //test
    }

关于c# - 将指南传递给测试方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56259752/

相关文章:

c# - 将 Guid 与字符串进行比较

visual-studio-2015 - 使用 "xUnit.net Test Support for ReSharper 10"在带有 ReSharper Ultimate 10 的 Visual Studio 2015 中运行 xUnit 测试时出错

c# - 如何在 .net (c#) 中为可安全存储在数据库中的字符串创建 HashCode?

c# - 什么代表sql server中的double?

c# - 在 Windows UWP 应用程序中使用 Python 和 C#

c# - 有没有更合适的方法来测试构造函数是否抛出异常?

c# - 使用 xUnit 和 Moq 验证方法是否基于条件执行

c# - Emgu Opencv C# ConvertTo 不同的结果

c# - 如何创建确定性指南

c++ - 在 Windows 中,UuidFromString 和 CLSIDFromString 之间有区别吗?