We have been using FluentAssertions on our current project for more that a half year now, and we are very pleased with the simplicity of our tests.
Currently we have the task of writing a integration test framework that tests a SqlDatabase. That is, we test the API of our database of store procedures and tables through C# code run from within TFS.
For this purpose I am tasked with extending fluent assertions to be able to add the Should() method to the DataTable object. There is not documentation on this, but I am figuring it out as I go, and it seems to work just fine.
Now, however, I am a little stuck. I want to add a Fields<Type>(string name) method on my assertion object that returns a GenericCollectionAssertions<Type> where I have extracted the column with name and put into the GenericCollectionAssertions. This I cannot do as the constructor is not part of the public API.
So I have writte the code like this:
public class DataTableAssertions : ReferenceTypeAssertions<DataTable, DataTableAssertions>public DataTableAssertions(DataTable table)
{Subject = table;}//methods removed for clarity..
internal GenericCollectionAssertions<TTableType> Fields(string name){var arr = new TTableType[Subject.Rows.Count];for (int i = 0; i < Subject.Rows.Count; i++){arr[i] = Subject.Rows[i].Field<TTableType>(name);}//return new GenericCollectionAssertions(arr);
return arr.Should();
}}
This is not as neat as I would like it to be, any suggestions?