Пример #1
0
        public void Call_NullExpressionPassed_NullReferenceExceptionThrown()
        {
            // Arrange
            CacheCaller cacheCallerUnderTest = new CacheCaller();

            // Act and assert
            Assert.Throws <NullReferenceException>(() => cacheCallerUnderTest.Call(null));
        }
Пример #2
0
        public void Call_ExpressionContainsVariable_ArgumentOutOfRangeThrown()
        {
            // Arrange
            int a = 5;
            Expression <Func <int> > expression = () => a;

            CacheCaller cacheCallerUnderTest = new CacheCaller();

            // Act and assert
            Assert.Throws <ArgumentOutOfRangeException>(() => cacheCallerUnderTest.Call(expression));
        }
Пример #3
0
        public void Call_CalledWithoutMethods_NoMethodsCalledAndExpressionEvaluated()
        {
            // Arrange
            Expression <Func <int> > expressionWithoutMethods = () => - 5 + 2 * 3 - 20 / 4;
            int expectedResult = expressionWithoutMethods.Compile().Invoke();

            CacheCaller callerUnderTest = new CacheCaller();

            // Act
            int actualResult = callerUnderTest.Call(expressionWithoutMethods);

            // Assert
            Assert.Equal(0, _aCalledTimes);
            Assert.Equal(0, _bCalledTimes);
            Assert.Equal(0, _cCalledTimes);

            Assert.Equal(expectedResult, actualResult);
        }
Пример #4
0
        public void Call_MethodsCalledTwoTimesWithDifferenctArgs_EachMethodExceptACalledTwice()
        {
            // Arrange
            Expression <Func <int> > expression = () => A() * A() + B(10) / B(5) - C(1, 5) + C(5, 1) + -10;
            int expectedResult = expression.Compile().Invoke();

            ResetCalledTimes();

            CacheCaller caller = new CacheCaller();

            // Act
            int actualResult = caller.Call(expression);

            // Assert
            Assert.Equal(1, _aCalledTimes);
            Assert.Equal(2, _bCalledTimes);
            Assert.Equal(2, _cCalledTimes);

            Assert.Equal(expectedResult, actualResult);
        }
Пример #5
0
        public void Call_OneCallForEachMethod_EachMethodCalledOnce()
        {
            // Arrange
            Expression <Func <int> > expression = () => C(B(A()), 5) + 4;
            int expectedResult = expression.Compile().Invoke();

            ResetCalledTimes();

            CacheCaller caller = new CacheCaller();

            // Act
            int actualResult = caller.Call(expression);

            // Assert
            Assert.Equal(1, _aCalledTimes);
            Assert.Equal(1, _bCalledTimes);
            Assert.Equal(1, _cCalledTimes);

            Assert.Equal(expectedResult, actualResult);
        }