Created
April 13, 2013 16:19
-
-
Save ielcoro/5379044 to your computer and use it in GitHub Desktop.
xUnit Data Theories Post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SymbolDatabaseTheoryData | |
: IEnumerable<object[]> | |
{ | |
public IEnumerator<object[]> GetEnumerator() | |
{ | |
return (from row in dataContext.Table | |
select new { Id = row.Id, Symbol = row.Symbol }); | |
} | |
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() | |
{ | |
return this.GetEnumerator(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DynamicDatabaseTheoryData | |
: IEnumerable<dynamic> | |
{ | |
public IEnumerator<dynamic> GetEnumerator() | |
{ | |
return from symbol in dataContext.Symbols | |
select new { Description = symbol.Description }; | |
} | |
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() | |
{ | |
return this.GetEnumerator(); | |
} | |
} | |
[Theory()] | |
[TypedClassData(typeof(DynamicDatabaseTheoryData))] | |
public void TestClassData(dynamic data) | |
{ | |
//Using dynamic data | |
Assert.NotNull(data.Description); | |
} | |
[Theory()] | |
[TypedClassData(typeof(DynamicDatabaseTheoryData))] | |
public void TestClassData(string description) | |
{ | |
//Matching parameters by name even with dynamic data source | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Theory()] | |
[InlineData(1, "€")] | |
[InlineData(2, "$")] | |
public void TestInline(int id, string symbol) | |
{ | |
//This test will run until all data rows are enumerated | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Theory()] | |
[ClassData(typeof(SymbolDatabaseTheoryData))] | |
public void TestClassData(int id, string symbol) | |
{ | |
//This test will run until all data rows are enumerated | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SymbolDatabaseTheoryData | |
: IEnumerable<Symbol> | |
{ | |
public IEnumerator<Symbol> GetEnumerator() | |
{ | |
return from symbol in dataContext.Symbols | |
select symbol; | |
} | |
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() | |
{ | |
return this.GetEnumerator(); | |
} | |
} | |
[Theory()] | |
[TypedClassData(typeof(SymbolDatabaseTheoryData))] | |
public void TestClassData(Symbol symbol) | |
{ | |
//The parameter matchs the model type | |
} | |
[Theory()] | |
[TypedClassData(typeof(SymbolDatabaseTheoryData))] | |
public void TestClassData(string symbol, int id) | |
{ | |
//Matching parameters by name | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment