# Automocking and the Dependency Inversion Principle

DevFeed: [Automocking and the Dependency Inversion Principle](<https://devfeed.tech/articles/automocking-and-the-dependency-inversion-principle-20775.md>)

Original publisher: [Read original article](<https://conductofcode.io/post/automocking-and-the-dependency-inversion-principle/>)

Author: {"twitter"=\>"hlaueriksson"}

Published: 2017-02-28T20:00:00Z

Content type: tutorial

Language: en

Sources: [Henrik Lau Eriksson](<https://devfeed.tech/sources/henrik-lau-eriksson.md>)

Topics: [Dependency Inversion](<https://devfeed.tech/topics/dependency-inversion.md>), [Testing](<https://devfeed.tech/topics/testing.md>), [C#](<https://devfeed.tech/topics/csharp.md>), [IoC (Disambiguation)](<https://devfeed.tech/topics/ioc.md>), [configuration](<https://devfeed.tech/topics/configuration.md>), [client](<https://devfeed.tech/topics/client.md>)

Tags: [c-sharp](<https://devfeed.tech/tags/c-sharp.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [dependency-inversion](<https://devfeed.tech/tags/dependency-inversion.md>), [framework](<https://devfeed.tech/tags/framework.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [testing](<https://devfeed.tech/tags/testing.md>), [xunit](<https://devfeed.tech/tags/xunit.md>)

## AI overview

This tutorial explains how to adapt an automocking base class for C# code that uses internal classes. It shows how friend assemblies, public interfaces, an IoC container, and injected real or fake dependencies can support unit testing while preserving dependency inversion.

## Source excerpt

I had reason to revisit the automocked base class from a previous blog post. I am working with another code base and have new opportunities for automocking. We have a lot of internal classes. Approximately 30% of the classes are marked as internal. The old approach did not work anymore.