Reputation: 27
I have a program that runs calculations off of a SqlServer database. I want to test that those calculations are done correctly. Currently the only way I can do this is using answer ints with theory and verify that the function gives the answer int for the corresponding database row.
This is sub-optimal because I have two ints for every test, the answer and the index of the row that I want to test.
[Theory]
[InlineData(db.movieTable.Take(1).Select(p => p))]
public void Test1(IQueryable<movieTable> value)
{
var result = db.movieTable.Take(1).Select(p => p).ToList().ElementAt(0).Price;
Assert.True(value.ToList().ElementAt(0).Price == 10);
}
Is there a way to do this. If I run this code I get the following error: UnitTest1.cs(19,21): error CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type [C:\Users\co-op7\Documents\GeorgeCode\MovieSite\MovieManage.Tests\MovieManage.Tests.csproj]
Upvotes: 0
Views: 250
Reputation: 156654
Usually the point of InlineData is to use the same test logic, but isolate the differences in expected inputs and outputs.
[Theory]
[InlineData(1, 10.00m)]
[InlineData(2, 14.50m)]
public void Test1(int movieId, decimal expectedPrice)
{
var result = db.movieTable.Single(p => p.Id == movieId);
Assert.True(result.Price == expectedPrice);
}
Upvotes: 2