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
I am getting a problem when wrting tests for some of our modified .netTiers DAL and cannot seem to figure out what is causing the problem.

I have managed to narrow this down to the following two code samples

When I run the following Test it fails

        [TestMethod]
        public void Load_Test_Problem1()
        {
            OracleVWE_STB_BOOKMARKProvider target = new OracleVWE_STB_BOOKMARKProvider("Test", true, "Test");

            VWE_STB_BOOKMARK entity = new VWE_STB_BOOKMARK();

            entity.STB_ID = Int32.MaxValue;
            entity.STB_NOTE = String.Empty;

            MockManager.Init();

            Mock MockTransactionManager = MockManager.MockObject(typeof(TransactionManager));
            TransactionManager ObjMockTransactionManager = (TransactionManager)MockTransactionManager.MockedInstance;

            Mock MockOracleCommand = MockManager.MockObject(typeof (OracleCommand));
            OracleCommand ObjMockOracleCommand = (OracleCommand)MockOracleCommand.MockedInstance;

            object STB_ID = entity.STB_ID;
            object STB_NOTE = entity.STB_NOTE;


            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {

                IDataReader reader = Utility.ExecuteReader(ObjMockTransactionManager, ObjMockOracleCommand);                

                recorder.ExpectAndReturn(reader["STB_ID"], STB_ID);
                recorder.RepeatAlways();

                recorder.ExpectAndReturn(reader["STB_NOTE"], STB_NOTE);
                recorder.RepeatAlways();

            }

            IDataReader readertemp = Utility.ExecuteReader(ObjMockTransactionManager, ObjMockOracleCommand);

            int temp2 = Convert.ToInt32(readertemp["STB_ID"]);

            MockManager.Verify();
            MockManager.ClearAll();
        }


However when I swap around a couple of the expectations it passes.

        [TestMethod]
        public void Load_Test_Problem2()
        {
            OracleVWE_STB_BOOKMARKProvider target = new OracleVWE_STB_BOOKMARKProvider("Test", true, "Test");

            VWE_STB_BOOKMARK entity = new VWE_STB_BOOKMARK();

            entity.STB_ID = Int32.MaxValue;
            entity.STB_NOTE = String.Empty;

            MockManager.Init();

            Mock MockTransactionManager = MockManager.MockObject(typeof(TransactionManager));
            TransactionManager ObjMockTransactionManager = (TransactionManager)MockTransactionManager.MockedInstance;

            Mock MockOracleCommand = MockManager.MockObject(typeof (OracleCommand));
            OracleCommand ObjMockOracleCommand = (OracleCommand)MockOracleCommand.MockedInstance;

            object STB_ID = entity.STB_ID;
            object STB_NOTE = entity.STB_NOTE;


            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {

                IDataReader reader = Utility.ExecuteReader(ObjMockTransactionManager, ObjMockOracleCommand);                

                recorder.ExpectAndReturn(reader["STB_NOTE"], STB_NOTE);
                recorder.RepeatAlways();

                recorder.ExpectAndReturn(reader["STB_ID"], STB_ID);
                recorder.RepeatAlways();
            }

            IDataReader readertemp = Utility.ExecuteReader(ObjMockTransactionManager, ObjMockOracleCommand);

            int temp2 = Convert.ToInt32(readertemp["STB_ID"]);

            MockManager.Verify();
            MockManager.ClearAll();
        }



Is anyone able to explain this to me or have I found a bug?


The Error I am recieveing is:

------ Test started: Assembly: in4tek.NetTiers.Bookmark.FullUnitTests.dll ------

TestCase 'in4tek.NetTiers.Bookmark.FullUnitTests.OracleVWE_STB_BOOKMARKProviderTests.Load_Test_Problem1'
failed: System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.Int32.Parse(String s, NumberStyles style, IFormatProvider provider)
   at System.Convert.ToInt32(String value, IFormatProvider provider)
   at System.String.System.IConvertible.ToInt32(IFormatProvider provider)
   at System.Convert.ToInt32(Object value)
   C:CareSuiteCare Foundation Data TiersBookmarkin4tek.NetTiers.Bookmark.FullUnitTestsVWE_STB_BOOKMARKProviderTests.cs(743,0): at in4tek.NetTiers.Bookmark.FullUnitTests.OracleVWE_STB_BOOKMARKProviderTests.Load_Test_Problem1()


0 passed, 1 failed, 0 skipped, took 1.67 seconds.
asked by Cnash (2.3k points)

2 Answers

0 votes
hi
The problem is that RepeatAlways repeat the last reader[] call
The result is that IDataReader returns a string object instead of int.
This what cause Convert.ToInt32 to throw format exception.
answered by ohad (35.4k points)
0 votes
Of Course!

Looking at it this morning it seems obvious.

Thanks for your help.
answered by Cnash (2.3k points)
...