How to use LocalRef class of Telerik.JustMock package

Best JustMockLite code snippet using Telerik.JustMock.LocalRef

LocalRef.cs

Source:LocalRef.cs Github

copy

Full Screen

...16using Telerik.JustMock.Core;17using Telerik.JustMock.Helpers;18namespace Telerik.JustMock19{20 internal sealed class ValueHandle<TValue, TId> : LocalRefHandle<TValue>21 {22 private static class RefProvider23 {24 private static TValue value;25 public static TValue Value26 {27 set28 {29 ProfilerInterceptor.GuardInternal(() => RefProvider.value = value);30 }31 }32 public static ref TValue GetRef()33 {34 return ref ProfilerInterceptor.GuardInternal((target, args) =>35 {36 return ref RefProvider.value;37 }, null, null);38 }39 }40 public ValueHandle(TValue expected)41 : base(RefProvider.GetRef)42 {43 RefProvider.Value = expected;44 }45 }46 /// <summary>47 /// Creates handles used for mocking ref returns, used with conjunction with <see cref="Expectations.FuncExpectation{TReturn}.Returns(Delegate)"/>48 /// </summary>49 /// <example>50 /// var refHandle = LocalRef.WithValue(10);51 /// Mock.Arrange(mock, m => m.Echo(ref Arg.Ref(Arg.AnyInt).Value)).Returns(refHandle.Handle).OccursOnce();52 /// </example>53 public static class LocalRef54 {55 /// <summary>56 /// Creates ref return handle with given type and value57 /// </summary>58 /// <typeparam name="T">Ref return type</typeparam>59 /// <param name="value">Initial value</param>60 /// <returns>Ref return handle of type <see cref="LocalRefHandle{T}"/></returns>61 public static LocalRefHandle<T> WithValue<T>(T value)62 {63 return ProfilerInterceptor.GuardInternal(() =>64 {65 Type valueHandleType = typeof(ValueHandle<,>).MakeGenericType(new[] { typeof(T), DynamicTypeHelper.GetNextType<T>() });66 ConstructorInfo constructor = valueHandleType.GetConstructor(new[] { typeof(T) });67 return (LocalRefHandle<T>)constructor.Invoke(new object[] { value });68 });69 }70 }71}...

Full Screen

Full Screen

LocalRefHandle.cs

Source:LocalRefHandle.cs Github

copy

Full Screen

...15using Telerik.JustMock.Expectations;16namespace Telerik.JustMock17{18 /// <summary>19 /// Handles local refs returns used for mocking, used with conjunction with <see cref="LocalRef.WithValue{T}(T)"/>20 /// </summary>21 /// <example>22 /// var refHandle = LocalRef.WithValue(10);23 /// Mock.Arrange(mock, m => m.Echo(ref Arg.Ref(Arg.AnyInt).Value)).Returns(refHandle.Handle).OccursOnce();24 /// </example>25 public abstract class LocalRefHandle<T>26 {27 FuncExpectation<T>.RefDelegate refDelegate;28 /// <summary>29 /// Constructs local ref handle30 /// </summary>31 /// <param name="refDelegate">Mocking delegate</param>32 public LocalRefHandle(FuncExpectation<T>.RefDelegate refDelegate)33 {34 this.refDelegate = refDelegate;35 }36 /// <summary>37 /// Delegate used for mocking ref returns, see <see cref="Expectations.FuncExpectation{TReturn}.Returns(System.Delegate)"/>38 /// </summary>39 public FuncExpectation<T>.RefDelegate Handle40 {41 get { return ProfilerInterceptor.GuardInternal(() => this.refDelegate); }42 }43 /// <summary>44 /// Ref to the internal value of type <see cref="T"/>45 /// </summary>46 public ref T Ref...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run JustMockLite automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful