/* JustMock Lite Copyright © 2010-2015 Telerik EAD Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ using System; using System.Linq.Expressions; using Telerik.JustMock.Core; using Telerik.JustMock.Core.Context; namespace Telerik.JustMock { public partial class Mock { /// /// Asserts a specific call from expression. /// /// Target expression /// Return type for the assert expression public static void Assert(Expression> expression, string message = null) { ProfilerInterceptor.GuardInternal(() => { MockingContext.CurrentRepository.Assert(message, null, expression); }); } /// /// Asserts a specific call from expression. /// /// Target expression /// Return type for the assert expression /// Assert argument public static void Assert(Expression> expression, Args args, string message = null) { ProfilerInterceptor.GuardInternal(() => { MockingContext.CurrentRepository.Assert(message, null, expression, args, null); }); } /// /// Asserts a specific call from expression. /// /// Target expression /// Specifies how many times a call has occurred /// Return type for the target call public static void Assert(Expression> expression, Occurs occurs, string message = null) { ProfilerInterceptor.GuardInternal(() => { MockingContext.CurrentRepository.Assert(message, null, expression, null, occurs); }); } /// /// Asserts the specified call from expression. /// /// The action to verify. /// Specifies to ignore the instance and/or arguments during assertion. /// Specifies the number of times a mock call should occur. /// Return type for the target call public static void Assert(Expression> expression, Args args, Occurs occurs, string message = null) { ProfilerInterceptor.GuardInternal(() => { MockingContext.CurrentRepository.Assert(message, null, expression, args, occurs); }); } /// /// Asserts a specific call from expression. /// /// Action expression defining the action to verify. public static void Assert(Expression expression, string message = null) { ProfilerInterceptor.GuardInternal(() => { MockingContext.CurrentRepository.Assert(message, null, expression); }); } /// /// Asserts the specified call from expression. /// /// The action to verify. /// Specifies to ignore the instance and/or arguments during assertion. public static void Assert(Expression expression, Args args, string message = null) { ProfilerInterceptor.GuardInternal(() => { MockingContext.CurrentRepository.Assert(message, null, expression, args, null); }); } /// /// Asserts the specified call from expression. /// /// The action to verify. /// Specifies the number of times a mock call should occur. public static void Assert(Expression expression, Occurs occurs, string message = null) { ProfilerInterceptor.GuardInternal(() => { MockingContext.CurrentRepository.Assert(message, null, expression, null, occurs); }); } /// /// Asserts the specified call from expression. /// /// The action to verify. /// Specifies to ignore the instance and/or arguments during assertion. /// Specifies the number of times a mock call should occur. public static void Assert(Expression expression, Args args, Occurs occurs, string message = null) { ProfilerInterceptor.GuardInternal(() => { MockingContext.CurrentRepository.Assert(message, null, expression, args, occurs); }); } /// /// Asserts a specific call from expression. /// /// Target instance /// Contains the target mock call /// Target type /// The type of the return value of the method public static void Assert(T target, Func func, string message = null) { ProfilerInterceptor.GuardInternal(() => { MockingContext.CurrentRepository.AssertAction(message, () => func(target)); }); } /// /// Asserts a specific call from expression. /// /// Target instance /// Specifies how many times a call has occurred /// Contains the target mock call /// Target type /// The type of the return value of the method public static void Assert(T target, Func func, Occurs occurs, string message = null) { ProfilerInterceptor.GuardInternal(() => { MockingContext.CurrentRepository.AssertAction(message, () => func(target), null, occurs); }); } /// /// Asserts the specific property set operation. /// /// Action defining the set operation public static void AssertSet(Action action, string message = null) { ProfilerInterceptor.GuardInternal(() => { MockingContext.CurrentRepository.AssertAction(message, action); }); } /// /// Asserts the specific property set operation. /// /// Action defining the set operation /// Specifies the number of times a mock call should occur. public static void AssertSet(Action action, Occurs occurs, string message = null) { ProfilerInterceptor.GuardInternal(() => { MockingContext.CurrentRepository.AssertAction(message, action, null, occurs); }); } /// /// Asserts the specific property set operation. /// /// Action defining the set operation /// Specifies to ignore the instance and/or arguments during assertion. public static void AssertSet(Action action, Args args, string message = null) { ProfilerInterceptor.GuardInternal(() => { MockingContext.CurrentRepository.AssertAction(message, action, args, null); }); } /// /// Asserts the specific property set operation. /// /// Action defining the set operation /// Specifies to ignore the instance and/or arguments during assertion. /// Specifies the number of times a mock call should occur. public static void AssertSet(Action action, Args args, Occurs occurs, string message = null) { ProfilerInterceptor.GuardInternal(() => { MockingContext.CurrentRepository.AssertAction(message, action, args, occurs); }); } /// /// Asserts all expected calls that are marked as must or /// to be occurred a certain number of times. /// /// Target type /// Target instance public static void Assert(T mocked, string message = null) { ProfilerInterceptor.GuardInternal(() => MockingContext.CurrentRepository.Assert(message, mocked)); } /// /// Asserts all expected setups. /// /// Target type /// Target instance public static void AssertAll(T mocked, string message = null) { ProfilerInterceptor.GuardInternal(() => MockingContext.CurrentRepository.AssertAll(message, mocked)); } /// /// Asserts all expectation on the given type /// /// The type which declared the methods to assert. public static void Assert(Type type, string message = null) { ProfilerInterceptor.GuardInternal(() => MockingContext.CurrentRepository.AssertIgnoreInstance(message, type, ignoreMethodMockOccurrences: false)); } /// /// Asserts all expectation on the given type /// /// The type which declared the methods to assert. public static void Assert(string message = null) { ProfilerInterceptor.GuardInternal(() => MockingContext.CurrentRepository.AssertIgnoreInstance(message, typeof(T), ignoreMethodMockOccurrences: false)); } /// /// Returns the number of times the specified member was called. /// /// The action to inspect /// Number of calls public static int GetTimesCalled(Expression> expression) { return ProfilerInterceptor.GuardInternal(() => MockingContext.CurrentRepository.GetTimesCalled(expression, null)); } /// /// Returns the number of times the specified member was called. /// /// The action to inspect /// Specifies to ignore the instance and/or arguments during assertion. /// Number of calls public static int GetTimesCalled(Expression> expression, Args args) { return ProfilerInterceptor.GuardInternal(() => MockingContext.CurrentRepository.GetTimesCalled(expression, args)); } /// /// Returns the number of times the specified member was called. /// /// The action to inspect /// Number of calls public static int GetTimesCalled(Expression expression) { return ProfilerInterceptor.GuardInternal(() => MockingContext.CurrentRepository.GetTimesCalled(expression, null)); } /// /// Returns the number of times the specified member was called. /// /// The action to inspect /// Specifies to ignore the instance and/or arguments during assertion. /// Number of calls public static int GetTimesCalled(Expression expression, Args args) { return ProfilerInterceptor.GuardInternal(() => MockingContext.CurrentRepository.GetTimesCalled(expression, args)); } /// /// Returns the number of times the specified setter or event subscription method was called. /// /// The setter or event subscription method to inspect /// Number of calls public static int GetTimesSetCalled(Action action) { return ProfilerInterceptor.GuardInternal(() => MockingContext.CurrentRepository.GetTimesCalledFromAction(action, null)); } /// /// Returns the number of times the specified setter or event subscription method was called. /// /// The setter or event subscription method to inspect /// Specifies to ignore the instance and/or arguments during assertion. /// Number of calls public static int GetTimesSetCalled(Action action, Args args) { return ProfilerInterceptor.GuardInternal(() => MockingContext.CurrentRepository.GetTimesCalledFromAction(action, args)); } } }