Ejemplo n.º 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);
        }
Ejemplo n.º 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 }));
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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 }));
        }
Ejemplo n.º 5
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 }));
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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 }));
        }