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 have the following simple test code:

        [Isolated]
        [TestMethod]
        public void Medication_history_string_should_contain_ten_elements()
        {
            CreateTestCaseForTenElements();
            var list = CreateHistoryList(CreatePrescriptionSoap().GetPrescriptionHistory("123456"));

            Assert.IsTrue(list.Count() == 10, "There should be ten items, but there were: " + list.Count());
        }

        private void CreateTestCaseForTenElements()
        {
            var orderTextList = OrderTextList.GetOrderTextList("123456").Take(10);
            Isolate.WhenCalled(() => OrderTextList.GetOrderTextList("123456")).WillReturnCollectionValuesOf(orderTextList);
        }


This test fails because it returns the true count instead of the count of the test collection. So, I am doing something wrong?
asked by halcwb (5.5k points)

1 Answer

0 votes
Hi,

Assuming GetOrderTextList returns more than 10 elements (otherwise Take(10) will return less...), you seem to be doing it right.

Without having the code for "GetOrderTextList", and without knowing its return type, the test passes here (when it returns IEnumerable<string>).

By the way, imho, it is preferable to return a different constant collection in this test instead of a subset of the original returned collection. When faking using a subset you are testing the faked class as well...

Hope i helped, and if not, you can send a small project with the code to our support (or post here) and we will check it out.

Regards,
Yonatan,
Typemock Support
answered by yonatan (1.6k points)
...