Skip to content

The package is an extension to C# objects that generates a unit tests depending on an onject internal state and public methods

License

Notifications You must be signed in to change notification settings

DenisZhukovski/ObjectToTest

Repository files navigation

ObjectToTest

NuGet Stars License Hits-of-Code Lines of Code EO principles respected here PDD status

The main idea is to implement an extension method for C# objects that generates initialization piece of code depending on an object internal state and public constructors methods and properties. It should let the developer easily recreate an object state and continue using it in unit test environment.

public class Foo
{
  public Foo(IPrice price, IUser user)
  {
    _price = price;
    _user = user;
  }
  
  public void DoSomething(int argument)
  {
    // Some logic
  }
}

Let's say there is a class Foo in a project. It would be really nice to have an extension method which will generate a piece of code that will allow to recreate the same object with the same internal state.

public void SomeMethod(Foo foo)
{
  /*
   * The result of ToUnit method should be a string that contains the peice of code to recreate
   * foo object from the scatch.
   * new Foo(new Price(10), new User("userName"));
   */
   var tests = foo.ToTest();
}

This generated code can be easily insterted into Unit Test.

Object state recreation diagram

The diagram shows an algorithm that an object uses uses to recreate itself with initiated internal state. The interesting thing is that an object can have arguments which are reused in other objects. Such objects are called Shared Arguments.

Alt text

More details about project architecture can be found on wiki page

IL Decompilator

IL Spy nuget package is used to support c# code decompilation

Quality status

Quality Gate Status Coverage Duplicated Lines (%) Maintainability Rating

About

The package is an extension to C# objects that generates a unit tests depending on an onject internal state and public methods

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages