示例#1
0
        private void DoTest(bool expectedResult)
        {
            string pipeId            = Guid.NewGuid().ToString();
            int    debuggeeProcessId = 2017;

            // ReSharper disable once UnusedVariable
            var host = new DebuggerAttacherServiceHost(pipeId, MockDebuggerAttacher.Object, MockLogger.Object);

            try
            {
                host.Open();

                var client = new MessageBasedDebuggerAttacher(pipeId, Timeout, MockLogger.Object);

                client.AttachDebugger(debuggeeProcessId, DebuggerEngine.Native).Should().Be(expectedResult);

                MockDebuggerAttacher.Verify(a => a.AttachDebugger(It.Is <int>(processId => processId == debuggeeProcessId), It.IsAny <DebuggerEngine>()),
                                            Times.Once);

                host.Close();
            }
            catch (CommunicationException)
            {
                host.Abort();
                throw;
            }
        }
        private void DoTest(string expectedErrorMessagePart)
        {
            string pipeId            = Guid.NewGuid().ToString();
            int    debuggeeProcessId = 2017;

            // ReSharper disable once UnusedVariable
            var host = new DebuggerAttacherServiceHost(pipeId, MockDebuggerAttacher.Object, MockLogger.Object);

            try
            {
                host.Open();

                var proxy = DebuggerAttacherServiceConfiguration.CreateProxy(pipeId, WaitingTime);
                using (var client = new DebuggerAttacherServiceProxyWrapper(proxy))
                {
                    client.Should().NotBeNull();
                    client.Service.Should().NotBeNull();

                    Action attaching = () => client.Service.AttachDebugger(debuggeeProcessId);
                    if (expectedErrorMessagePart == null)
                    {
                        attaching.ShouldNotThrow();
                    }
                    else
                    {
                        attaching.ShouldThrow <FaultException <DebuggerAttacherServiceFault> >().Where(
                            (FaultException <DebuggerAttacherServiceFault> ex) => ex.Detail.Message.Contains(expectedErrorMessagePart));
                    }
                }

                host.Close();
            }
            catch (CommunicationException)
            {
                host.Abort();
                throw;
            }
        }