コード例 #1
0
        public void TestInstanceMethods()
        {
            MethodTests tests1 = new MethodTests {
                Value = 10
            };
            MethodTests tests2 = new MethodTests {
                Value = 10
            };

            tests1.Value.ShouldBe(tests2.Value);

            tests1.IncrementValue();

            using (Redirection redirection = Redirection.Redirect <Action>(IncrementValue, DecrementValue))
            {
                tests2.IncrementValue();

                tests1.Value.ShouldNotBe(tests2.Value);
                tests1.Value.ShouldBe(11);
                tests2.Value.ShouldBe(9);

                redirection.Stop();

                tests1.Value = tests2.Value = 0;

                tests1.IncrementValue();
                tests2.IncrementValue();

                tests1.Value.ShouldBe(tests2.Value);
                tests1.Value.ShouldBe(1);
                tests2.Value.ShouldBe(1);
            }
        }
コード例 #2
0
        public void TestInstanceMethodsWithParameters()
        {
            MethodTests tests1 = new MethodTests {
                Value = 10
            };
            MethodTests tests2 = new MethodTests {
                Value = 10
            };

            tests1.Value.ShouldBe(tests2.Value);

            tests1.IncrementValueBy(5);

            using (Redirection redirection = Redirection.Redirect <Action <int> >(IncrementValueBy, DecrementValueBy))
            {
                tests2.IncrementValueBy(5);

                tests1.Value.ShouldNotBe(tests2.Value);
                tests1.Value.ShouldBe(15);
                tests2.Value.ShouldBe(5);

                redirection.Stop();

                tests1.Value = tests2.Value = 0;

                tests1.IncrementValueBy(3);
                tests2.IncrementValueBy(3);

                tests1.Value.ShouldBe(tests2.Value);
                tests1.Value.ShouldBe(3);
                tests2.Value.ShouldBe(3);
            }
        }