GithubHelp home page GithubHelp logo

serg046 / autofake Goto Github PK

View Code? Open in Web Editor NEW
51.0 5.0 4.0 1.34 MB

Mock any type members including static and non-virtual ones

License: MIT License

C# 100.00%
mock mocking mocking-library fake fake-data faker faker-library testing-tools monkey-patching

autofake's Introduction

Sergey's github stats

autofake's People

Contributors

dependabot[bot] avatar serg046 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

autofake's Issues

Apply a mock in scope of fake's type

Support two modes:

  1. Existing mode. Scan all referenced methods of fake's module.
  2. Add mode to scan only methods in fake's type (public/private). It should improve performance. Make it as default mode.

ExpectedCalls(int) implementation

Currently only ExpectedCalls(Func<int, bool>) is supported. Please add support for ExpectedCalls(int) too. The thing is that we cannot simply use something like this:

ExpectedCalls(int number) => ExpectedCalls(x => x == number);

Because that code works only on the client side and cannot be placed inside the library as is.

Setting return value based on runtime method arguments or mock instance

Imagine you have the following type:

class SomeType
{
    public SomeType(int someProp) => SomeProp = someProp;
    public int SomeProp { get; }
    public int GetSomeProp(int arg) => SomeProp + arg;
    public SomeMethod(int arg) => Console.WriteLine(GetSomeProp(arg));
}

You might want to do something like this:

var fake = new Fake<SomeType>(5);
sut.Replace(f => f.GetSomeProp(3))
       .If((SomeType instance, object[] arguments) => instance.SomeProp > 0 && arguments.Single() is uint)
       .Return(-1);
sut.Replace(f => f.GetSomeProp(3))
       .If((SomeType instance, object[] arguments) => instance.SomeProp == 2 && !(arguments.Single() is uint))
       .Return(0);

Types from different assemblies should work correctly

  1. Create Type1 in assembly1 and Type2 in assembly2 as dependency of Type1.
  2. Make fake for Type1 and mock anything of Type2
  3. Check that FakeGenerator have access to assembly2 and correctly replace mocked member of Type2.
  4. Modify Type2 as internal and add InternalsVisibleToAttribute to assembly1.
  5. Check step 3. again.

Add Regenerate() method

Since 'Execute()' method runs regeneration of the fake type, it should be indicated.
It needs to introduce a new method and force to use it before the second execution of 'Execute'.

Mock of type constructor

Add ability to mock type constructor because it can run some undesirable actions like database access and so on.

Improve IsAsyncMethod

Try to create AsyncStateMachineAttribute right in the project with the proper namespace

Get rid of GetMonoCecilTypeName/GetClrName

  • Extensions.EquivalentTo
public TypeReference GetType(string fullName, bool runtimeName)
    {
      return !runtimeName ? (TypeReference) this.GetType(fullName) : TypeParser.ParseType(this, fullName);
    }

Force a separate AppDomain when there is a Dispose() call

We use the same AppDomain by defaut. It doesn't allow to unload the generated lib so that we cannot unload it. Please generate an exception if the fake is configured so that it is impossible to place the lib to a seaprate AppDomain.

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.