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?

+1 vote
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 8.6.0.0

Thanks!
asked Dec 1 by meansala (190 points)
Hi Alan,

Could you post a code example?

1 Answer

0 votes
        [TestMethod,Isolated]
        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

            target.RunExecutable();
            Isolate.Invoke.Event(() => fakeProcess.OutputDataReceived += null, this, outputHandle);
            Thread.Sleep(500);

            //ASSERT
            Assert.IsTrue(m_responseStrings.Count>0);
        }

 

answered 16 hours ago by Raphy (2,440 points)
...