1

I'm trying to cover my business logic with unit tests using NUnit and fakeiteasy. But I suddenly stuck with faking calls to Soap client using fakeiteasy. I trying to do next thing

var myFakedSoapClient = A.Fake<SomeSoapClient>();
var myCustomServiceWhichUsesThatSoapClient = new MyService(myFakedSoapClient);
myCustomServiceWhichUsesThatSoapClient.CallDoSomething();   
myFakedSoapClient.CallsTo(e=>e.DoSomething(A<string>.Ignored)).MustHaveHappened();

But in the first row in which I'm trying to fake SoapClient it just get stuck and start to eat more and more memory. It doesn't show any exception, it just run that line until timeout.

What I miss?

Thx for any advance.

Maris
  • 4,608
  • 6
  • 39
  • 68
  • What is `SomeSoapClient`? I'm not familiar with the class. – Blair Conrad Jul 23 '15 at 10:11
  • It is some soapclient which was auto generated by wsdl. – Maris Jul 23 '15 at 10:27
  • I'm not sure how to help. FakeItEasy can fake many classes (although I'd recommend faking interfaces whenever possible—there are fewer surprises), so without knowing more about the class that's being faked, there's no way to reproduce the problem, and reasoning about it becomes quite difficult. – Blair Conrad Jul 23 '15 at 13:59
  • 2
    I find it difficult to believe that `SoapClient` has anything to do with your business logic. I would ensure that you are isolating your business logic components from your integration components. Something that is calling a SOAP webservice is an integration component and you can apply an appropriate testing strategy to it. Indeed, if you isolate the SOAP client usage as far as possible to thinnest possible wrapper, there is little value in unit testing this, so the need to fake SoapClient will fall away. – Adam Ralph Jul 23 '15 at 16:00

1 Answers1

1

Include the fake call

myFakedSoapClient.CallsTo(e=>e.DoSomething(A<string>.Ignored)).WithAnyArgumemen().Returns(expectedfakeobject);

before the actual function call

var myCustomServiceWhichUsesThatSoapClient = new MyService(myFakedSoapClient);

Something like this

var myFakedSoapClient = A.Fake<SomeSoapClient>();
var myCustomServiceWhichUsesThatSoapClient = new MyService(myFakedSoapClient);
myFakedSoapClient.CallsTo(e=>e.DoSomething(A<string>.Ignored)).WithAnyArgumemen().Returns(expectedfakeobject);
myCustomServiceWhichUsesThatSoapClient.CallDoSomething();   
myFakedSoapClient.CallsTo(e=>e.DoSomething(A<string>.Ignored)).MustHaveHappened();
Sudipto Sarkar
  • 346
  • 2
  • 11