Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One options is to test each call apart and all of them together. If you test A&amp;B&amp;C, you can limit yourself to testing A,B,C apart and A&amp;B&amp;C together. One option is the next code(made some assumptions):</p> <pre><code> [TestFixture] public class ToTestFixture { [SetUp] public void SetUp() { _instance = new ToTest(); _instance.InputDataStore(1, "1"); _instance.InputDataStore(2, "2"); _instance.InputDataStore(3, "3"); _instance.InputDataStore(4, "4"); } private ToTest _instance; [TestCase("{DS1}","1")] [TestCase("{DS2}", "2")] [TestCase("{DS3}", "3")] [TestCase("{DS4}", "4")] [TestCase("{DS1}{DS2}{DS3}{DS4}", "1234")] [Test] public void TestPrefixReplacements(string input, string expectedResult) { _instance.Prefix = input; //Call the input method which will raise the Output event which we can test _instance.Input("Any string goes here as we test only prefix." ); Assert.AreEqual(expectedResult, _instance.Prefix); } } internal enum OutputsEnum { OutputBeforeModified, OutputModified, OutputAfterModified } public class ToTest { public event Action&lt;int, string&gt; Output = (x, result) =&gt; Console.WriteLine(x.ToString() + result); public string Prefix { get; set; } public string Postfix { get; set; } private List&lt;string&gt; DataStoreContents = new List&lt;string&gt;() {"1", "2", "3", "4"}; public void Input(string Data) { if (Output != null) { if (!String.IsNullOrEmpty(Prefix)) { Prefix = Prefix.Replace("{DS1}", DataStoreContents[0]); Prefix = Prefix.Replace("{DS2}", DataStoreContents[1]); Prefix = Prefix.Replace("{DS3}", DataStoreContents[2]); Prefix = Prefix.Replace("{DS4}", DataStoreContents[3]); } if (!String.IsNullOrEmpty(Postfix)) { Postfix = Postfix.Replace("{DS1}", DataStoreContents[0]); Postfix = Postfix.Replace("{DS2}", DataStoreContents[1]); Postfix = Postfix.Replace("{DS3}", DataStoreContents[2]); Postfix = Postfix.Replace("{DS4}", DataStoreContents[3]); } Output((int) OutputsEnum.OutputBeforeModified, Data); Output((int) OutputsEnum.OutputModified, Prefix + Data + Postfix); Output((int) OutputsEnum.OutputAfterModified, Data); } } public void InputDataStore(int DataStore, string Data) { if (DataStore &lt; 1 || DataStore &gt; 4) throw new ArgumentOutOfRangeException("Datastore number out of range"); DataStoreContents[DataStore - 1] = Data; } } </code></pre> <p>Anyhow I feel there is a bond between "DS1" and the index of the array. (1-0, 2-1). This means next refactoring is possible:</p> <pre><code>Prefix = Prefix.Replace("{DS"+index+"}", DataStoreContents[index-1]); </code></pre> <p>More than that I guess output action decision is strange and two if-s are duplicate code. This is what I mean: </p> <pre><code> public void Input(string Data) { if (Output != null) { Prefix = ApplyReplaceRules(Prefix); Postfix = ApplyReplaceRules(Postfix); Output((int) OutputsEnum.OutputBeforeModified, Data); Output((int) OutputsEnum.OutputModified, Prefix + Data + Postfix); Output((int) OutputsEnum.OutputAfterModified, Data); } } private string ApplyReplaceRules(string patternString) { if (!String.IsNullOrEmpty(Postfix)) { patternString = patternString.Replace("{DS1}", DataStoreContents[0]); patternString = patternString.Replace("{DS2}", DataStoreContents[1]); patternString = patternString.Replace("{DS3}", DataStoreContents[2]); patternString = patternString.Replace("{DS4}", DataStoreContents[3]); } return patternString; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload