How to throw SoapException using Moq to unit test error handling

I inherited a small console application that makes calls to the SOAP web service. This is a tragic mess of nested trap attempts that break exceptions in different ways, and I would like to wrap some test coverage around how it behaves when a SoapException is thrown.

Question: How can I make fun of a class, such as SoapException, using Moq, when I canโ€™t mock the interface and I canโ€™t make the properties or methods โ€œvirtualโ€?

A bit more explanation:

To test this error handling, I need to manage the property Actorof the SoapException object as well as the property Detailto check the error handling.

Excerpt from my unit test code:

[TestMethod]
public void MyTestMethod()
{
    Mock<SoapException> soapMock = new Mock<SoapException>(MockBehavior.Strict);

    soapMock.SetupGet<string>(ex => ex.Actor).Returns("Test Actor");

, Actor "Virtual", Moq SetupGet(...) :

System.NotSupportedException: ( VB) : ex = > ex.Actor

, . , .NET framework, Actor .

SoapException ?

, SoapException XML , XML. , , , .

+4
2

Moq. Shim Microsoft Fakes Framework. , , , ( ).

. Shim msdn.

, , , . , , .NET.

http://msdn.microsoft.com/en-us/library/hh549175.aspx

: Fakes Visual Studio Ultimate Premium.

+1

, SoapException. SoapException Detail, Actor .. Rhino Mocks.

//Build your xmlDocument 
    SoapException mockSoapException = MockRepository.GenerateMock<SoapException>("Mock SoapException", new XmlQualifiedName(), "TEST", xmlDocument); 
+1

Source: https://habr.com/ru/post/1523391/


All Articles