chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
Hi

I want to mock the following when index is used together with sqlReader in the code below. How can I do this?

        private static int ExtractAndConvertToInt(SqlDataReader reader, string indexName)
        {
            int outputValue = 0;
            try
            {
                if (reader[indexName] != DBNull.Value)
                {
                    outputValue = Convert.ToInt32(reader[indexName]);
                }
            }
            catch (Exception exception)
            {
                Log.Warning("Failed to extract : " + indexName, exception);
            }

            return outputValue;
        
        }
asked by eal (600 points)

2 Answers

0 votes
try something in the spirit of this:

      SqlDataReader mockIndex = RecorderManager.CreateMockedObject(typeof(SqlDataReader));
      using (RecordExpectation rec = new RecordExpectation())
      {
         rec.ExpectAndReturn(reader[indexName],<FakeValue>);
         rec.RepeatAlways();
      }
answered by lior (13.2k points)
0 votes
Hi,

And you can watch the training video on this exact subject here (on mocking database calls) - https://www.typemock.com/Multimedia.html
answered by gilz (14.5k points)
...