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
Welcome to Typemock Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!

Is there a way to mock a system process standard out?

+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 Dec 1, 2017 by meansala (12,120 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 Dec 13, 2017 by Raphy (3,840 points)