Giter VIP home page Giter VIP logo

mockattributes's Introduction

MockAttributes

Build Status NuGet

Mockito-like annotations for .NET

See MovieFinderTest for a usage example

Installation

Visual Studio Package Manager Console:

Install-Package MockAttributes

Nuget:

nuget install MockAttributes

dotnet core:

dotnet add package MockAttributes

Usage

By default, MockAttributes assumes you're using Moq, so that it can extract the proxy object generated by Castle DynamicProxy and inject it into the class-under-test.

If you're using hand-rolled mocks or your mocking library doesn't wrap a class around the proxy object in the way that Moq does, you can pass an instance of DefaultProxyObjectExtractor into MockInjector.Inject.

For any other cases, you can implement IProxyObjectExtractor.

WIP

  • inject mocks into test class
  • inject mocked objects into class-under-test (for Moq initially, although could be made more general)
  • stand-up class-under-test with mocked objects
  • suppress CS0649 ("Field is never assigned to, and will always have its default value null")
  • support properties
  • unit tests
  • handle classes with multiple dependencies of the same type
  • fallback to property injection if no suitable constructors are found

mockattributes's People

Contributors

alexashley avatar

Watchers

 avatar  avatar

mockattributes's Issues

Compiler warning CS0649 for annotated fields

[MockThis]
private Mock<MovieRepository> movieRepo; // CS0649

Since the compiler doesn't the field is set at runtime, it warns that the field is used before being assigned.

There are some ways around this, but nothing MockAttributes can do:

  • Wrap the fields for test classes in #pragma warning disable CS0649 and #pragma warning restore CS0649
  • Disable the warning for test projects
  • Use the annotations on properties instead of fields

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.