Setup on Mock not returning expected value

前端 未结 1 1836
天命终不由人
天命终不由人 2020-12-21 09:33

Here is a simplified version of a problem I encountered:

public interface IService
{
    IProvider Provider { get; }
}

public interface IProvider
{
    Lis         


        
相关标签:
1条回答
  • 2020-12-21 10:17

    This is clearly intentional when looking at the source:

    https://github.com/moq/moq4/blob/master/Source/Mock.cs

    https://github.com/moq/moq4/blob/master/Source/Interceptor.cs

    Setup creates a "call" by using AddCall on Interceptor. This contains the following block of code which, as long as we're creating a non-conditional setup, removes all previous setups. It's even commented.

    if (!call.IsConditional)
                {
                    lock (calls)
                    {
                        // if it's not a conditional call, we do
                        // all the override setups.
                        // TODO maybe add the conditionals to other
                        // record like calls to be user friendly and display
                        // somethig like: non of this calls were performed.
                        if (calls.ContainsKey(key))
                        {
                            // Remove previous from ordered calls
                            InterceptionContext.RemoveOrderedCall(calls[key]);
                        }
    
                        calls[key] = call;
    }
    
    0 讨论(0)
提交回复
热议问题