Giter Site home page Giter Site logo

moqtonsubstituteconverter's Introduction

MoqToNSubstituteConverter

A console application to convert Moq in unit tests to NSubstitute

Quality Gate Status

This project only has replacement code for the following:

Mock<ClassToMock> = ClassToMock
new Mock<ClassToMock>() = Substitute.For<ClassToMock>()
new Mock<ClassToMock>() { CallBase = true } = Substitute.ForPartsOf
It.IsAny = Arg.Any
It.Is = Arg.Is
.Object will be removed
.Verifiable will be removed
.Result will be removed
.Setup(name => name will be removed
.Verify(name => name = Received()
.Returns, .ReturnsAsync = .Returns
.Throws, .ThrowsAsync = .Throws
Times.Once = .Received(1)
Times.Exactly(3) = .Received(3)
Times.Never = .DidNotReceive()

Limitations:

  • This will work best on well formatted code
  • There is no replacment for .VerifyAll or .Protected
  • It.IsAnyType does not currently have a replacement
  • Some of the replaced statements no longer have the correct indentation, they are left justified, this could be fixed in Visual Studio by reformatting the document
  • The replacement for Mock<ClassToMock> = new() is not technically correct, it will replace it with ClassToMock = new() but it should be ClassToMock = Substitute.For<ClassToMock>()
  • Once the replacement is complete using NSubstitute; will need to be added to each modified file or global using NSubstitute; in the Usings.cs file
  • If the method you are setting up to "mock" is asynchronous, you may need to add await to the call
  • If there are Null Conditional Operators ?. in the code, these get left behind and will need to be removed

How to Run the code (PowerShell)

By default the executable will run in the current directory and sub directories, it perfoms analysis only and logs the results of the analysis in the log file.

.\MoqToNSubstitute.exe

To perform analysis on a specific directory:

.\MoqToNSubstitute.exe C:\Users\user\Documents\Projects\Vts.Api\Vts.Api.Tests\

To perform transformation on a specific directory:

.\MoqToNSubstitute.exe C:\Users\user\Documents\Projects\Vts.Api\Vts.Api.Tests\ true

How to Debug the code (Visual Studio)

If you place the folder for the code to be analyzed in the bin folder of the main project \MoqToNSubstitute\MoqToNSubstitute\bin\Debug\net6.0\ you can set breakpoints and step through the code, it will analyze by default. The log file will be located in the logs folder in that same location \MoqToNSubstitute\MoqToNSubstitute\bin\Debug\net6.0\logs.

moqtonsubstituteconverter's People

Contributors

lmalenfant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

moqtonsubstituteconverter's Issues

Add command line arguments

Add command line arguments that allow to run transformation in a specific folder.

The default is to run in the current folder and perform analysis only.

Remove redundant Null Conditional Operators

Is your feature request related to a problem? Please describe.
If there are Null Conditional Operators ?. in the code, these get left behind, add a regular expression to check for ?.Object prior to removing .Object so these no longer get left behind.

Add support for CallBase = true

Is your feature request related to a problem? Please describe.
Add replacement for new Mock<ClassToMock>() { CallBase = true }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.