I'm trying to send a List<DataStatusItem>
as a input parameter to my unit test method using DataRow
attribute as below,
[TestClass]
public class UpdateProcessingTestController
{
private List<DataStatusItem> DataStatusItemsTestSetup = new List<DataStatusItem>() {
new DataStatusItem { DataItemID = 1, DataItemCurrentStatusID = 1, DataItemStatusID = 1, DateEffective = DateTime.Now }
};
private readonly Mock<IEmployee> moqEmployee;
public UpdateProcessingTestController()
{
moqEmployee = new Mock<IEmployee>();
}
[TestMethod]
[DataRow(DataStatusItemsTestSetup, 1, 8, 1)] // **This is where it is throwing me compilation error**
public void SetDataItems(List<DataStatusItem> DataStatusItems,int brand, int dataType, int processingStatus)
}
Please let me know how to send the List as a input parameter to my test method.
The TestClass attribute denotes a class that contains unit tests. The TestMethod attribute indicates a method is a test method.
MSTest is one type of framework that provides the facility to test the code without using any third-party tool. It helps in writing effective unit tests using MSTest framework to test software applications. MSTest is a number-one open-source test framework that is shipped along with the Visual Studio IDE.
MSTest utility. To access the MSTest tool, add the Visual Studio install directory to the path or open the Visual Studio Group from the Start menu, and then open the Tools section to access the Visual Studio command prompt. Use the command MSTest from the command prompt.
Use DynamicData Attribute, Here is an example:
public class DataStatusItem
{
public int DataItemID { get; set; }
public int DataItemCurrentStatusID { get; set; }
public int DataItemStatusID { get; set; }
public DateTime DateEffective { get; set; }
}
[TestClass]
public class UpdateProcessingTestController
{
static IEnumerable<object[]> DataStatusItemsTestSetup
{
get
{
return new[]
{
new object[]
{
new List<DataStatusItem>
{
new DataStatusItem { DataItemID = 1, DataItemCurrentStatusID = 1, DataItemStatusID = 1, DateEffective = DateTime.Now },
new DataStatusItem { DataItemID = 2, DataItemCurrentStatusID = 2, DataItemStatusID = 2, DateEffective = DateTime.Now },
},
1, // brand
2, // dataType
3 // processingStatus
}
};
}
}
[TestMethod]
[DynamicData(nameof(DataStatusItemsTestSetup))]
public void SetDataItems(List<DataStatusItem> dataStatusItems, int brand, int dataType, int processingStatus)
{
Assert.AreEqual(2, dataStatusItems.Count);
Assert.AreEqual(1, brand);
Assert.AreEqual(2, dataType);
Assert.AreEqual(3, processingStatus);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With