Example #1
0
        public void HasReadableDescription()
        {
            string name  = "param";
            object value = new NamedObject("value");

            SetNamedParameterAction action = new SetNamedParameterAction(name, value);

            AssertDescription.IsEqual(action, "set param=<value>(NMockTests.NamedObject)");
        }
Example #2
0
        public void SetsNamedParameterOnInvocationWrong()
        {
            object         receiver   = new object();
            MethodInfoStub methodInfo = new MethodInfoStub("method",
                                                           new ParameterInfoStub("p1", ParameterAttributes.In),
                                                           new ParameterInfoStub("p2", ParameterAttributes.Out));
            string     name       = "p2_wrong";
            object     value      = new object();
            Invocation invocation = new Invocation(receiver, methodInfo, new object[] { null, null });

            SetNamedParameterAction action = new SetNamedParameterAction(name, value);

            Expect.That(() => ((IAction)action).Invoke(invocation)).Throws <ArgumentException>(new StringContainsMatcher("no such parameter\r\nParameter name: p2_wrong"));
        }
Example #3
0
        public void SetsNamedParameterOnInvocation()
        {
            object         receiver   = new object();
            MethodInfoStub methodInfo = new MethodInfoStub("method",
                                                           new ParameterInfoStub("p1", ParameterAttributes.In),
                                                           new ParameterInfoStub("p2", ParameterAttributes.Out));
            string     name       = "p2";
            object     value      = new object();
            Invocation invocation = new Invocation(receiver, methodInfo, new object[] { null, null });

            SetNamedParameterAction action = new SetNamedParameterAction(name, value);

            ((IAction)action).Invoke(invocation);

            Assert.AreSame(value, invocation.Parameters[1], "set value");
        }