Search code examples
c#mockingmicrosoft-fakes

Ms Fakes Framework, NotSupportedException


Why does this code throw ShimNotSupportedException in operator?

ShimStreamReader.AllInstances.EndOfStreamGet = ((s)=>calls < 1);

[TestMethod]
        public void GetAllLinesFromFile__()
        { 
            int calls = 0;

            using (ShimsContext.Create())
            {
                ShimStreamReader.AllInstances.EndOfStreamGet = ((s)=>calls < 1);
                ShimStreamReader.AllInstances.ReadLine = (s) =>
                                                             {
                                                                 calls++;
                                                                 return ";;;;;;;;;;";
                                                             };
                var streamFake = new ShimStreamReader();
                var obj = new MyFile(streamFake, ';');

                Assert.IsTrue(obj.GetAllLinesFromFile().Count() == 1);
            }

        }

Solution

  • Could it be that you are running the test from Resharper or some other testrunner?

    I've written a few blogposts related to this which may be helpful:

    http://blog.degree.no/2012/09/visual-studio-2012-fakes-shimnotsupportedexception-when-debugging-tests/

    http://blog.degree.no/2012/09/unit-testing-visual-studio-2012-fakes-in-team-city/