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
+2 votes
I would like to mock out the "Process" class used to call another exe. I have everything mocked out except for the stdout and stderrout. The output is piped to standard out  by hooking up a listener to outputDataReceived event. Is there any way to mock this so that the mock can send data to std out/raise that event?

Using VS2015 and typemock

asked by meansala (2.1k points)
Hi Alan,

Could you post a code example?

1 Answer

0 votes
        public void Ctor()
            // ARRANGE

            var fakeProcess = Isolate.Fake.NextInstance<Process>();
            var outputHandle = Isolate.Fake.AllInstances<DataReceivedEventArgs>(Members.CallOriginal);
            // var outputHandle = Isolate.Fake.Instance<DataReceivedEventArgs>(Members.CallOriginal);
            Isolate.WhenCalled(() => fakeProcess.Start()).WillReturn(true);
            Isolate.WhenCalled(() => outputHandle.Data).WillReturn("test");
            var target = new SystemProcessController("cmd", "ver", stdOutHandler, null);

            // ACT

            Isolate.Invoke.Event(() => fakeProcess.OutputDataReceived += null, this, outputHandle);



answered by Raphy (4k points)