I'd create two new methods:
public static string GetKpiPoint(string kpiResult, string ifExceeds) { return kpiResult.Contains("Exceeds") ? ifExceeds : null; } public static string[] CalculatePoints(string kpiAResult, string kpiBResult) { return new string[] { GetKpiPoint(kpiAResult, "AHT"), GetKpiPoint(kpiBResult, "QA") }; }
then call it from your exising one:
private string[] lstStrCalculatePoints() { return CalcualtePoints(lblKPIAResult.Text, lblKPIBResult.Text); }
EDIT: The ways you can test this method depend on your test framework, but if you're using NUnit you can do something like:
[Test] [TestCase("Exceeds", "Exceeds", new string[] { "AHT", "QA" })] [TestCase("NoMatch", "NoMatch", new string[] { null, null })] [TestCase("Exceeds", "NoMatch", new string[] { "AHT", null })] [TestCase("NoMatch", "Exceeds", new string[] { null, "QA" })] public void CalculatePointsTest(string kpiA, string kpiB, string[] expected) { CollectionAssert.AreEqual(expected, CalculatePoints(kpiA, kpiB)); }
lblKPIAResultand assert your logic against it. Where did you get stuck?lblKPIAResultdefined and assigned?