Search code examples
c#xunit

Cannot convert Dynamic table entity to System.threading entity in assert


I am trying to implement an Assert over my function which is called in separate project. The function called is as follows:

public async Task<List<DynamicTableEntity>> PopulateTable(
        string documentId,
        IEnumerable<string> lines,
        JsonSchema schema,
        string type,
        string subType,
        string format,
        bool upsert ){var tableEntries = new List<DynamicTableEntity>( tableData.Count );
.....
return tableEntries;  }

In Some cases it will throw an exception and I would like to test that using Xunit framework. My TDD code is like this:

 public async Task UploadAndSchemaCheckOnMissingKey()
 {      
    var table = await _tableStore.PopulateTable(null, lines, schema, "tableOutput", null, "test", false);
       
    await Assert.ThrowsAsync<ArgumentException>(table);
 }

I get the error as cannot convert System.Collection.generic.List<table.DynamicEntity> to System.Func<System.Threading.tasks.task>.

How should I handle this that My test case pass when the exception is thrown?


Solution

  • You can use it something like this:

    Func<Task> table = async() => await _tableStore.PopulateTable(null, lines, schema, "tableOutput", null, "test", false);
    var ex = await Assert.ThrowsAsync<FormatException>(table);
    Assert.Contains("expected error message", ex.Message);