Skip to Content
C# and .NET Core Test-Driven Development
book

C# and .NET Core Test-Driven Development

by Ayobami Adewole
May 2018
Intermediate to advanced content levelIntermediate to advanced
300 pages
7h 35m
English
Packt Publishing
Content preview from C# and .NET Core Test-Driven Development

Mocking internal types

Depending on your project requirements, you might need to create mock objects for internal types. Internal types or members in C# are accessible only within files in the same assembly. Mocking internal types can be done by adding custom attributes to the AssemblyInfo.cs file of the concerned projects.

If the assembly containing the internal types does not already have the AssemblyInfo.cs file, you can add it. Also, when the assembly is not strongly-named, you can add the InternalsVisibleTo attribute, which has the public key excluded. You have to specify the name of the project to share visibility with, which in this case should be the test project.

If you change the LoanService access modifier to internal, you will ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Design Patterns with C# and .NET Core

Hands-On Design Patterns with C# and .NET Core

Gaurav Aroraa, Jeffrey Chilberto
.NET Core in Action

.NET Core in Action

Dustin Metzgar

Publisher Resources

ISBN: 9781788292481Supplemental Content