I am trying to implement webserviceclass using the TDD approach, which sends a bunch of web requests and interprets the answers. I encapsulated web requests in multiple interfaces so that I can easily mock them. When requesting something through webserviceclass, the implemented method always returns a specific response object containing the error object. Using this error object, the user can determine whether the request was successful or not, and what the specific error was.
After writing a bunch of tests, I realized that I repeated a lot in the Arrange phase:
var mock = new Mock<ISomeWebservices>();
var sut = new MyWebServiceClass(mock.Object);
mock.Setup(foo=>foo.SomeRequest(someData)).Returns(@"{""user"": ""12345"",""somedata"": ""60"",""someotherdata"":""2015-09-01T12:00:00.200Z""}");
sut.SomeRequest(someData,s=> response = s);
The first two lines are always the same for all tests. There is always an installer for the layout that returns something or throws an exception. Depending on which request I'm testing, I need to configure another method. I tried to solve this problem using Autofixture so that I could write ICustomization for every web request, but the problem is that I still need layout access in order to have a test setup.
Another problem is the Assert phase. Since I always get the error object from the request, I only assert the error object if I am the outcome and the error.
Assert.That(response.Error.Type,Is.EqualTo(ErrorInfo.ErrorType.IllegalToken));
Assert.That(response.Error.Message, Is.Not.Null);
Assert.That(response.Error.AdvisedAction, Is.Not.Null);
Assert.That(response.Error.RawData, Is.Not.Null);
, , , , . (.. , ..),
, Asserts unit test , , .
[]
, , , , . Autofixture .