SkillAgentSearch skills...

NosePlug

Sometimes you have to test code that smells.

Install / Use

/learn @Keboo/NosePlug
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

NosePlug

Sometimes you have to test code that smells. When using static methods it tightly couples two pieces of code together. When over used this can lead to code that is difficult to test since all coupled code will be invoked. Ideally the code should be refactored to eliminate this problem, however in the real world ideals are not always possible. This library serves to be a half way point to allow testing to occur during the interim before appropriate refactoring can occur.

Getting started

This library's API is heavily influenced by Moq. See the documentation for the full getting started guide.

A simple example "mocking" DateTime.Now.

var nowPlug = Nasal.Property(() => DateTime.Now)
      .Returns(() => new DateTime(1987, 4, 20));

using (await Nasal.ApplyAsync(nowPlug))
{
      Assert.Equal(new DateTime(1987, 4, 20), DateTime.Now);
}

Limitations

This library relies on Harmony to monkey patch methods. This library maintains all of the same limitations of Harmony. The most common failure comes from inlining. This is most apparent when compiling in Release configuration (optimizations enabled).

Related Skills

View on GitHub
GitHub Stars11
CategoryDevelopment
Updated1y ago
Forks4

Languages

C#

Security Score

75/100

Audited on Mar 18, 2025

No findings