I am trying to make a test project using N Unit. I have everything working and now but i was wondering if it is possible to split the test cases into a completely separate class or would the only feasible way would be to push the data to a file or a partial class? basically I would like the data in a separate file instead of having all the data and the tests in one file. Or maybe that more of the standard and create different classes for each rule test.
[Test, TestCaseSource("TenantsRules")]
public void CheckDNQTenantsRules(DNQTenantData testData)
{
CoreServicesBroker.DNQCoreServiceBroker broker = new CoreServicesBroker.DNQCoreServiceBroker();
string actualDNQReason = string.Empty;
int actualReturnCode = broker.CheckDNQTenants(testData.FormCode, testData.StateCode, testData.EffectiveDate, testData.NumberOfTenants, ref actualDNQReason);
Assert.AreEqual(testData.ExpectedDNQReturnCode, actualReturnCode);
Assert.AreEqual(testData.ExpectedDNQReason, actualDNQReason);
}
public static IEnumerable<DNQTenantData> TenantsRules()
{
yield return new DNQTenantData() { FormCode = 9, StateCode = "OH", EffectiveDate = DateTime.Now, NumberOfTenants = 7, ExpectedDNQReturnCode = 1, ExpectedDNQReason = "Number of Tenants exceeded." };
yield return new DNQTenantData() { FormCode = 9, StateCode = "OH", EffectiveDate = DateTime.Now, NumberOfTenants = 5, ExpectedDNQReturnCode = 0, ExpectedDNQReason = "" };
}
I believe NUnits TestCaseData will solve your problem:
[TestFixture]
public class YourTest
{
[Test, TestCaseSource(typeof(YourTestCaseProvider), nameof(YourTestCaseProvider.TenantsRules)]
public void CheckDNQTenantsRules(DNQTenantData testData)
{
CoreServicesBroker.DNQCoreServiceBroker broker = new CoreServicesBroker.DNQCoreServiceBroker();
string actualDNQReason = string.Empty;
int actualReturnCode = broker.CheckDNQTenants(testData.FormCode, testData.StateCode, testData.EffectiveDate, testData.NumberOfTenants, ref actualDNQReason);
Assert.AreEqual(testData.ExpectedDNQReturnCode, actualReturnCode);
Assert.AreEqual(testData.ExpectedDNQReason, actualDNQReason);
}
}
public class YourTestCaseProvider
{
public static IEnumerable TenantsRules()
{
yield return new TestCaseData(new DNQTenantData() { FormCode = 9, StateCode = "OH", EffectiveDate = DateTime.Now, NumberOfTenants = 7, ExpectedDNQReturnCode = 1, ExpectedDNQReason = "Number of Tenants exceeded." })
yield return new TestCaseData(new DNQTenantData() { FormCode = 9, StateCode = "OH", EffectiveDate = DateTime.Now, NumberOfTenants = 5, ExpectedDNQReturnCode = 0, ExpectedDNQReason = "" });
}
}
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