How to make enemies with people who use TDD...

Published On: Jul 28, 2016

So I have been working on a project that requires the use of the NEST framework for working with ElasticSearch, and I have to tell you I am absolutely maddened by the lengths that I have to go through to get good tests.

The problem is that someone in their INFINITE Wisdom decided that all of the setters on response objects should be private or internal. For example:

public interface IGetMappingResponse : IResponse, IBodyWithApiCallDetails
   Dictionary<stringIList<TypeMapping>> Mappings { get; }
   Dictionary<IndexName, IDictionary<TypeName, TypeMapping>> IndexTypeMappings { get; }
   TypeMapping Mapping { get; }
   void Accept(IMappingVisitor visitor);

Which means that in order for for me to perform a simple mock, I have to create a WHOLE NEW CLASS, further bloating my code and making the process of creating my unit tests even more complicated. In order to use the following code:

var clientResponse = new MockedGetMappingResponse();
var calledGetMapping = false;
client.GetMapping(Arg.Any<IGetMappingRequest>()).Returns(clientResponse).AndDoes(x=> { calledGetMapping = true; });

 I have to create a whole, new object that's now bloating my unit test project just so I can get the damned unit test to work:

public class MockedGetMappingResponse : IGetMappingResponse
       public IApiCallDetails CallDetails { getset; }
       public bool IsValid { getset; }
       public IApiCallDetails ApiCall { getset; }
       public ServerError ServerError { getset; }
       public Exception OriginalException { getset; }
       public string DebugInformation { getset; }
       public void Accept(IMappingVisitor visitor)
           throw new NotImplementedException();
       public Dictionary<stringIList<TypeMapping>> Mappings { getset; }
       public Dictionary<IndexNameIDictionary<TypeNameTypeMapping>> IndexTypeMappings { getset; }
       public TypeMapping Mapping { getset; }

So the next time that you get the bright idea that all return objects shouldn't be able to be set... don't do it. If it says that it's a response object and someone is dumb enough to set the value then they are the idiot, we will give you a pass on it. But remember there are LEGITIMATE reasons that we would want to use those set values, and by removing them your aren't making your code any better... your just being an asshole.