/// <summary> /// Verifies that a specific invocation matching the given expression was performed /// on the mock. Use in conjunction with the default Moq.MockBehavior.Loose. /// </summary> /// <typeparam name="T">Type of the mock</typeparam> /// <param name="expression">Expression to verify</param> /// <param name="times">The number of times a method is allowed to be called.</param> /// <param name="failMessage">Message to show if verification fails.</param> public void Verify <T>(Expression <Func <T, object> > expression, Times times, string failMessage) where T : class { var mock = GetMock <T>(); if (CastChecker.DoesReturnPrimitive(expression)) { throw new NotSupportedException(Resources.Strings.VerifyWithValueReturn); } mock.Verify(expression, times, failMessage); }
public void Verify <T>(Expression <Func <T, object> > expression, Func <Times> times) where T : class { var mock = GetMock <T>(); if (CastChecker.DoesReturnPrimitive(expression)) { throw new NotSupportedException("Use the Verify overload that allows specifying TReturn if the setup returns a value type"); } mock.Verify(expression, times); }
/// <summary> /// Shortcut for mock.Setup(...), creating the mock when necessary. /// </summary> public ISetup <TService, object> Setup <TService>(Expression <Func <TService, object> > setup) where TService : class { Func <Mock <TService>, ISetup <TService, object> > func = m => m.Setup(setup); Expression <Func <Mock <TService>, ISetup <TService, object> > > expression = m => m.Setup(setup); //check if Func results in a cast to object (boxing). If so then the user should have used the Setup overload that //specifies TReturn for value types if (CastChecker.DoesContainCastToObject(expression)) { throw new NotSupportedException("Use the Setup overload that allows specifying TReturn if the setup returns a value type"); } return(Setup <ISetup <TService, object>, TService>(func)); }