Example #1
0
        public void CreateFromAction_ExpressionHelperReturnsNullMethod_ThrowsException()
        {
            Expression<Action> expression = ReflectionUtility.GetExpression(() => Console.WriteLine());
            _expressionHelperMock
                .Setup(helper => helper.GetMethod(expression))
                .Returns(default(MethodCallInfo));

            var subject = new SetupManager(_expressionHelperMock.Object);

            var exception = Assert.Throws<ArgumentException>(() => subject.Create(expression));
            Assert.AreEqual("expression", exception.ParamName);
        }
Example #2
0
        public void CreateFromAction_AddsToCollection()
        {
            var methodCallInfo = TestDataFactory.CreateMethodCallInfo(() => Console.WriteLine());
            Expression<Action> expression = ReflectionUtility.GetExpression(() => Console.WriteLine());

            _expressionHelperMock
                .Setup(helper => helper.GetMethod(expression))
                .Returns(methodCallInfo);

            var subject = new SetupManager(_expressionHelperMock.Object);
            ISetup setup = subject.Create(expression);

            Assert.IsTrue(subject.Cast<ISetup>().SequenceEqual(new[] { setup }));
        }
        public void CreateFromAction_ExpressionHelperReturnsNullMethod_ThrowsException()
        {
            Expression <Action> expression = ReflectionUtility.GetExpression(() => Console.WriteLine());

            _expressionHelperMock
            .Setup(helper => helper.GetMethod(expression))
            .Returns(default(MethodCallInfo));

            var subject = new SetupManager(_expressionHelperMock.Object);

            var exception = Assert.Throws <ArgumentException>(() => subject.Create(expression));

            Assert.AreEqual("expression", exception.ParamName);
        }
        public void CreateFromAction_AddsToCollection()
        {
            var methodCallInfo             = TestDataFactory.CreateMethodCallInfo(() => Console.WriteLine());
            Expression <Action> expression = ReflectionUtility.GetExpression(() => Console.WriteLine());

            _expressionHelperMock
            .Setup(helper => helper.GetMethod(expression))
            .Returns(methodCallInfo);

            var    subject = new SetupManager(_expressionHelperMock.Object);
            ISetup setup   = subject.Create(expression);

            Assert.IsTrue(subject.Cast <ISetup>().SequenceEqual(new[] { setup }));
        }
        public void CreateFromFunc_AddsToCollection()
        {
            var methodCallInfo = TestDataFactory.CreateMethodCallInfo(() => Console.ReadLine());

            var expression = ReflectionUtility.GetExpression(() => Console.ReadLine());

            _expressionHelperMock
            .Setup(helper => helper.GetMethod(expression))
            .Returns(methodCallInfo);

            var subject = new SetupManager(_expressionHelperMock.Object);
            var setup   = subject.Create(expression) as IInternalSetup;

            Assert.IsTrue(subject.SequenceEqual(new[] { setup }));
        }
        public void CreateFromAction_ReturnsSetupFromExpressionHelper()
        {
            var methodCallInfo = TestDataFactory.CreateMethodCallInfo(() => Console.WriteLine());

            Expression <Action> expression = ReflectionUtility.GetExpression(() => Console.WriteLine());

            _expressionHelperMock
            .Setup(helper => helper.GetMethod(expression))
            .Returns(methodCallInfo);

            var subject = new SetupManager(_expressionHelperMock.Object);
            var result  = subject.Create(expression) as IInternalSetup;

            Assert.AreSame(result.MethodCall, methodCallInfo);
        }
        public void CreateFromProperty_ReturnsSetupFromExpressionHelper()
        {
            // Doesn't really matter what method call we create here, it's only
            // used for comparison.
            var methodCallInfo = TestDataFactory.CreateMethodCallInfo(() => Console.WriteLine());

            var expression = ReflectionUtility.GetExpression(() => DateTime.Now);

            _expressionHelperMock
            .Setup(helper => helper.GetPropertyGetCall(expression))
            .Returns(methodCallInfo);

            var subject = new SetupManager(_expressionHelperMock.Object);
            var result  = subject.Create(expression) as IInternalSetup;

            Assert.AreSame(result.MethodCall, methodCallInfo);
        }
        public void GetSetupsForMethod_ReturnsOnlyMatchingSetups()
        {
            var methodCallInfo             = TestDataFactory.CreateMethodCallInfo(() => Console.WriteLine());
            Expression <Action> expression = ReflectionUtility.GetExpression(() => Console.WriteLine());

            _expressionHelperMock
            .Setup(helper => helper.GetMethod(expression))
            .Returns(methodCallInfo);

            var subject = new SetupManager(_expressionHelperMock.Object);

            subject.Create(expression);

            var result1 = subject.GetSetupsForMethod(ReflectionUtility.GetMethod(() => Console.WriteLine()));
            var result2 = subject.GetSetupsForMethod(ReflectionUtility.GetMethod(() => Console.ReadLine()));

            Assert.AreEqual(1, result1.Count);
            Assert.AreEqual(0, result2.Count);
        }
Example #9
0
        public void CreateFromAction_ReturnsSetupFromExpressionHelper()
        {
            var methodCallInfo = TestDataFactory.CreateMethodCallInfo(() => Console.WriteLine());

            Expression<Action> expression = ReflectionUtility.GetExpression(() => Console.WriteLine());
            _expressionHelperMock
                .Setup(helper => helper.GetMethod(expression))
                .Returns(methodCallInfo);

            var subject = new SetupManager(_expressionHelperMock.Object);
            var result = subject.Create(expression) as IInternalSetup;

            Assert.AreSame(result.MethodCall, methodCallInfo);
        }
Example #10
0
        public void GetSetupsForMethod_ReturnsOnlyMatchingSetups()
        {
            var methodCallInfo = TestDataFactory.CreateMethodCallInfo(() => Console.WriteLine());
            Expression<Action> expression = ReflectionUtility.GetExpression(() => Console.WriteLine());

            _expressionHelperMock
                .Setup(helper => helper.GetMethod(expression))
                .Returns(methodCallInfo);

            var subject = new SetupManager(_expressionHelperMock.Object);
            subject.Create(expression);

            var result1 = subject.GetSetupsForMethod(ReflectionUtility.GetMethod(() => Console.WriteLine()));
            var result2 = subject.GetSetupsForMethod(ReflectionUtility.GetMethod(() => Console.ReadLine()));

            Assert.AreEqual(1, result1.Count);
            Assert.AreEqual(0, result2.Count);
        }
Example #11
0
        public void CreateFromProperty_ReturnsSetupFromExpressionHelper()
        {
            // Doesn't really matter what method call we create here, it's only
            // used for comparison.
            var methodCallInfo = TestDataFactory.CreateMethodCallInfo(() => Console.WriteLine());

            var expression = ReflectionUtility.GetExpression(() => DateTime.Now);
            _expressionHelperMock
                .Setup(helper => helper.GetPropertyGetCall(expression))
                .Returns(methodCallInfo);

            var subject = new SetupManager(_expressionHelperMock.Object);
            var result = subject.Create(expression) as IInternalSetup;

            Assert.AreSame(result.MethodCall, methodCallInfo);
        }
Example #12
0
        public void CreateFromFunc_AddsToCollection()
        {
            var methodCallInfo = TestDataFactory.CreateMethodCallInfo(() => Console.ReadLine());

            var expression = ReflectionUtility.GetExpression(() => Console.ReadLine());
            _expressionHelperMock
                .Setup(helper => helper.GetMethod(expression))
                .Returns(methodCallInfo);

            var subject = new SetupManager(_expressionHelperMock.Object);
            var setup = subject.Create(expression) as IInternalSetup;

            Assert.IsTrue(subject.SequenceEqual(new[] { setup }));
        }