Parameterized Data with ClassData
Parameterizing our tests helps us keeping our tests clean, easy to use and of course we can pass object into our test scenarios!
public class BookListTheoryData : TheoryData<List<Book>>
{
public BookListTheoryData()
{
Add([
new()
{
Id = Guid.NewGuid(),
Title = "test",
Description = "test",
Author = "test",
Published = DateTimeOffset.UtcNow,
Edition = 999,
Copies = 999,
Isbn = "test",
Price = 9.99,
IsAvailable = true
},
new()
{
Id = Guid.NewGuid(),
Title = "test1",
Description = "test1",
Author = "test1",
Published = DateTimeOffset.UtcNow,
Edition = 111,
Copies = 111,
Isbn = "test1",
Price = 1.11,
IsAvailable = true
},
new()
{
Id = Guid.NewGuid(),
Title = "test2",
Description = "test2",
Author = "test2",
Published = DateTimeOffset.UtcNow,
Edition = 222,
Copies = 222,
Isbn = "test2",
Price = 2.22,
IsAvailable = true
}
]);
}
}
Use it like this:
[Theory]
[ClassData(typeof(BookListTheoryData))]
public async Task BatchInsert_TheoryData(List<Book> books){ // .....}
No files yet, migration hasn't completed yet!