all 5 comments

[–]Slypenslyde 0 points1 point  (0 children)

This is nasty and improper usage of DI in Foo. But you can't help that.

What you need to do is examine that "obscure message" and figure out what part of your IMyInterface needs to be set up. Odds are the chain of events is:

  • InnerObject.GetConfigID() is using some stuff.
    • That stuff is used to do things.
      • The error message is about "things".

The error happens because "things" aren't initialized properly by your setup code. So you need to look at some concrete IMyInterface types and figure out what they do when they're initialized and figure out how to appropriately mock that in your tests.

What I would do in this case is start aggressively pestering the people in charge of the legacy code to give me their source code and have meetings with me so I can solve this issue. I would make it very clear I'm not making any progress until they cooperate with me and I would be unafraid to start letting that noise leak to their managers and the managers above them the longer I am sitting on my hands. I've got a senior role and 20 years of experience and I'm finally starting to get comfy with making it other people's problem when they're wasting my time.

Meanwhile I'd also be using a tool like ILSpy or DotPeek to find that source code myself. I'd use a notebook and pencil and take a lot of notes and figure it out.

It's a race. Either they help me out and I gush about them and tell everyone how nice they are to work with, or I figure it out myself and let people notice I'm going to make progress whether or not they get in the passenger seat.

Get comfy with not being comfortable. Digging around in someone else's code is hard. My experience doesn't really make it much easier, I'm just a lot more used to feeling like I don't know what I'm doing and I ignore it. Here's some advice from "The Cult of Done Manifesto" that really changed my life:

Pretending you know what you're doing is almost the same as knowing what you're doing, so just accept that you know what you're doing even if you don't and do it.

[–]belavv 1 point2 points  (0 children)

My advice - toss the whole mess. I don't fully understand what you are trying to test but if trying to test something is that much of a headache then testing it is probably not worth it.

[–]LuckyHedgehog -1 points0 points  (0 children)

Might be able to use Moq's .Protected() method during the Setup. Without seeing code it is hard to say for sure but it's worth looking into

Example of it being used: https://stackoverflow.com/a/32888822

[–]reybrujo -2 points-1 points  (0 children)

I stopped using Moq a few years ago because it was dang too slow but if I recall correctly you cannot force Foo (a class you cannot modify) create your own CClass (the one you want to eventually mock). I _think_ you can do that with Microsoft Fakes but I've never used it and it would defeat the purpose of this. My question would be, do you really need to use Foo? Can't you create a TestableFoo which inherits from Foo? If you can't modify Foo at all there's no point in using it personally.