Пример #1
0
        public void InvokeCountTooLowFails()
        {
            var mock = FluentMock <IMyTestInterface> .With()
                       .WhereMethod(x => x.Foo).IsCalled(3).Times()
                       .Returns("hi");

            var instance = mock.Instance;

            var foo = instance.Foo;

            foo = instance.Foo;

            Exception error = null;

            try
            {
                mock.OnScenarioEnd();
            }
            catch (Exception e)
            {
                error = e;
            }
            Assert.NotNull(error, "expected failure on too few invokes");
            Assert.IsTrue(error.Message.Contains("unexpectedly performed 2 times"));
            Assert.IsTrue(error.Message.Contains("expected 3 times"));
        }
Пример #2
0
        public void InvokeCountTooHighFails()
        {
            var mock = FluentMock <IMyTestInterface> .With()
                       .WhereMethod(x => x.Foo()).IsCalled(3).Times()
                       .Returns("hi");

            var instance = mock.Instance;

            instance.Foo();
            instance.Foo();
            instance.Foo();

            Exception error = null;

            try
            {
                instance.Foo();
            }
            catch (Exception e)
            {
                error = e;
            }
            Assert.NotNull(error, "expected failure on too many method calls");
            Assert.IsTrue(error.Message.Contains("unexpectedly performed 4 times"));
            Assert.IsTrue(error.Message.Contains("expected 3 times"));
        }
Пример #3
0
        /// <summary>
        /// Use to create a mock that implements multiple types.
        /// </summary>
        /// <typeparam name="TAnother">Another type implemented by the mock</typeparam>
        /// <returns></returns>
        public FluentMock <TAnother> AndMocks <TAnother>() where TAnother : class
        {
            var methodMock = new FluentMock <TAnother>(m_mock.As <TAnother>());

            RunOnVerify(methodMock);
            return(methodMock);
        }
Пример #4
0
        internal FluentMethodReturns(FluentMock <T> mock, ISetup <T, TResult> setup, Expression <Func <T, TResult> > expression)
        {
            var call = expression.Body as MethodCallExpression;

            m_mock       = mock;
            m_setup      = setup;
            m_numArgs    = call == null ? 0 : call.Arguments.Count;
            m_expression = expression;
        }
Пример #5
0
        /// <summary>
        /// Create a mock for the given type, ensuring the mock is verified at scenario completion. That is,
        /// Moq's Mock.VerifAll will be called on the underlying mock at the end of the scenario
        ///
        /// </summary>
        /// <typeparam name="T">the type to create the mock for</typeparam>
        /// <returns>a fluent mock</returns>
        protected FluentMock <T> AMock <T>() where T : class
        {
            AssertInScenario();
            var mock = new FluentMock <T>();

            //ensure mock is verified at senario completion
            InjectDependencies(mock);
            m_mocksDefined = true;
            return(mock);
        }
Пример #6
0
        public void InvokeCountOkPasses()
        {
            var mock = FluentMock <IMyTestInterface> .With().WhereMethod(x => x.Foo()).IsCalled(3).Times();

            var instance = mock.Instance;

            instance.Foo();
            instance.Foo();
            instance.Foo();

            mock.OnScenarioEnd();
        }
Пример #7
0
 //for internal use only to allow chaining
 internal FluentMock(FluentMock <T> fluentMock)
 {
     this.m_mock = fluentMock.m_mock;
 }
 internal FluentPropertyGet(FluentMock<T> mock, ISetupGetter<T, TProperty> setup, Expression<Func<T, TProperty>> expression)
 {
     m_mock = mock;
     m_setup = setup;
     m_expression = expression;
 }
Пример #9
0
 internal FluentMethodVoid(FluentMock <T> mock, ISetup <T> setup, Expression <Action <T> > expression) : base(mock)
 {
     m_setup      = setup;
     m_expression = expression;
 }