Note that there are some explanatory texts on larger screens.

plurals
  1. POUnit testing a third party API with sealed concrete classes
    primarykey
    data
    text
    <p>just started TDD and all was going well until I hit this brick wall.</p> <p>I am writing a facade around a third party API. The API is quite nice in that everything is accessed via interfaces, so is easily mockable when testing my facade. </p> <p>The whole API is accessed via a root interface and there is a deep hierarchy of interfaces you can drill down into from this. My facade takes this root interface in its constructor in standard IoC practice.</p> <p>TDD was going fine, with the slight pain that mocking was getting a bit complex when using deep interfaces, since I have to mock the entire interface tree. No biggie though, I just maintained a helper function that built the mock. It does make me wonder if I'm using the right approach though.</p> <p>Anyway, halfway down the tree I have now suddenly hit a sealed concrete type, with no public constructor, so I have no way of mocking it. This is causing my tests to fail since the mocked API always returns null for this member.</p> <p>The only way I can see around this is to create my own interface for this type, and have a virtual method on my facade for accessing it. However, this seems messy to me since I have no way of enforcing access to the type through this method, and it will be easy to forget. eg, it's natural to use:</p> <pre><code>ConcreteType c = SomeInterface.ConcreteMember; </code></pre> <p>instead of:</p> <pre><code>IConcreteType c = GetConcreteMember(SomeInterface); </code></pre> <p>Forgetting this would cause tests to fail.</p> <p>Am I missing something fundamental? As I said I am very new to unit testing.</p> <p>ps. I am using Moq.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload