示例#1
0
        public void HandlingRefParametersInStubs()
        {
            // Create a stub.
            ISampleClass stub = CreateStub();

            // If you call the method with the specified input argument, it will
            // not change the parameter to the value you specified.
            string param = "input";

            stub.MethodWithRefParameter(ref param);
            param.Should(Be.EqualTo("input"));

            // If I call the method with any other input argument, it will
            // not change the parameter to the value you specified.
            param = "some other value";
            stub.MethodWithRefParameter(ref param);
            param.Should(Be.EqualTo("some other value"));
        }
示例#2
0
        public void HandlingRefParametersInStubs()
        {
            // Create a stub.
            ISampleClass stub = CreateStub();

            // Here's how you stub an "ref" parameter.
            string refi = "input";

            stub.When(s => s.MethodWithRefParameter(ref refi)).Do(x => x[0] = "output");

            // If you call the method with the specified input argument, it will
            // change the parameter to the value you specified.
            string param = "input";

            stub.MethodWithRefParameter(ref param);
            param.Should(Be.EqualTo("output"));

            // If I call the method with any other input argument, it won't
            // change the value.
            param = "some other value";
            stub.MethodWithRefParameter(ref param);
            param.Should(Be.EqualTo("some other value"));
        }
示例#3
0
        public void HandlingRefParametersInStubs()
        {
            // Create a stub.
            ISampleClass stub = CreateStub();

            // Here's how you stub an "ref" parameter.  The "Dummy" part is
            // just to satisfy the compiler.  (Note: Is.Equal() is part of
            // the Rhino.Mocks.Contraints namespace, there is also an
            // Is.EqualTo() in NUnit... you want the Rhino Mocks one.)
            stub.Stub(s => s.MethodWithRefParameter(ref Arg <string> .Ref(Rhino.Mocks.Constraints.Is.Equal("input"), "output").Dummy));

            // If you call the method with the specified input argument, it will
            // change the parameter to the value you specified.
            string param = "input";

            stub.MethodWithRefParameter(ref param);
            param.Should(Be.EqualTo("output"));

            // If I call the method with any other input argument, it won't
            // change the value.
            param = "some other value";
            stub.MethodWithRefParameter(ref param);
            param.Should(Be.EqualTo("some other value"));
        }
示例#4
0
        public void YouCanCreateStubByCallingMockRepositoryGenerateStub()
        {
            // Create a stub.
            ISampleClass stub = CreateStub();

            // Ensure that its string property is null or empty.
            stub.Property.Should(Be.Null.Or.Empty);

            int    outparam;
            string refparam = "test";

            // Call some methods.
            stub.VoidMethod();
            stub.MethodThatReturnsInteger("test").Should(Be.EqualTo(0));
            stub.MethodThatReturnsObject(0).Should(Be.Null);
            stub.MethodWithOutParameter(out outparam);
            outparam.Should(Be.EqualTo(0));
            stub.MethodWithRefParameter(ref refparam);
            refparam.Should(Be.EqualTo("test"));
        }