locked
How to test method using Pex and Moles RRS feed

  • Question

  •  public Tablekeywordmodel ExtractDetails(string[] strArray, string strUseCase)
            {
                Contract.Requires(strArray != null);
                Contract.Requires(!string.IsNullOrEmpty(strUseCase));
                Contract.Requires(Contract.ForAll<string>(strArray, s => !string.IsNullOrEmpty(s)),"Array should not contain null or blank");

                Tablekeywordmodel model = new Tablekeywordmodel();
                for (var j = 0; j < strArray.Length; j++)
                {
                    var strData = strArray[j].Trim();

                    if (string.Compare(strData, "Test1", true) == 0)
                    {
                        model.Test1= j == strArray.Length - 1 ? Getlastindexstring(strUseCase, strData)
                        : GetStringInBetween(Convert.ToString(strArray[j].Trim()), Convert.ToString(strArray[j + 1].Trim()), strUseCase, false, false)[0];
                    }
                    if (string.Compare(strData, "test2", true) == 0)
                    {
                        model.Tes2= j == strArray.Length - 1 ? Getlastindexstring(strUseCase, strData)
                                         : GetStringInBetween(Convert.ToString(strArray[j].Trim()), Convert.ToString(strArray[j + 1].Trim()), strUseCase, false, false)[0];

                    }
                              }
                return model;
            }

     public class Tablekeywordmodel
        {
            public string  Test1{ get; set; }
            public string Test2{ get; set; }
               }

    GetStringInBetween is actually retrieve text between two string.

    how to test ExtractDetails method using Pex and Moles?

     

    Monday, December 12, 2011 11:23 AM

All replies