Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# mock ref parameter

public interface IGobbler
{
    bool Gobble(ref int amount);
}

delegate void GobbleCallback(ref int amount);     // needed for Callback
delegate bool GobbleReturns(ref int amount);      // needed for Returns

var mock = new Mock<IGobbler>();
mock.Setup(m => m.Gobble(ref It.Ref<int>.IsAny))  // match any value passed by-ref
    .Callback(new GobbleCallback((ref int amount) =>
     {
         if (amount > 0)
         {
             Console.WriteLine("Gobbling...");
             amount -= 1;
         }
     }))
    .Returns(new GobbleReturns((ref int amount) => amount > 0));

int a = 5;
bool gobbleSomeMore = true;
while (gobbleSomeMore)
{
    gobbleSomeMore = mock.Object.Gobble(ref a);
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: stroke dash array wpf 
Csharp :: c# get executing file name 
Csharp :: c# recorrer una lista 
Csharp :: c# multiple inheritance 
Csharp :: browser folder in wpf 
Csharp :: 405 - HTTP verb used to access this page is not allowed 
Csharp :: how to use monitor from system.threading in c# 
Csharp :: write last line txt file c# 
Csharp :: unity error log 
Csharp :: HtmlToPdfConverter 
Csharp :: c# list get last element 
Csharp :: unity script template folder 
Csharp :: string.insert c# 
Csharp :: gql query with parameters 
Csharp :: c# sbyte 
Csharp :: unity GetNestedComponentsInChildren 
Csharp :: c# get all id of list object 
Csharp :: dotnet create web api 
Csharp :: generic interface c# 
Csharp :: strong email validation regex c# 
Csharp :: 2d explosion unity 
Csharp :: sqlite execute 
Csharp :: add rotation 
Csharp :: AuthenticationTicket authenticationProperties C# .net 
Csharp :: iserviceprovider vs iservicecollection 
Csharp :: convert string to float win forms 
Csharp :: c# windows forms rtc 
Csharp :: Photon Register Callbacks 
Csharp :: c# panel to graphics 
Csharp :: .net core 3 entity framework constraint code first image field 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =