コード例 #1
0
        public void ExchangeT_should_be_callable_indirectly()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                PInterlocked.ExchangeOfTTRefT <MyData>().Body = (ref MyData location1, MyData value) =>
                {
                    location1 = value;
                    return(new MyData(42));
                };

                // Act
                var data1  = new MyData(100);
                var data2  = new MyData(200);
                var actual = Interlocked.Exchange(ref data1, data2);

                // Assert
                Assert.AreEqual(200, data1.Value);
                Assert.AreEqual(42, actual.Value);
            }
        }
        public void AutoConfiguredMoqPrigCustomization_should_not_mock_ref_parameter_method_because_it_is_used_for_returning_value_condition()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var ms      = new MockStorage(MockBehavior.Default);
                var fixture = new Fixture().Customize(new AutoConfiguredMoqPrigCustomization(ms));

                PInterlocked.AddInt32RefInt32().Body = (ref int location1, int value) => 23;
                fixture.Create <PInterlocked>();


                // Act
                var location = 42;
                var result   = Interlocked.Add(ref location, int.MaxValue);


                // Assert
                Assert.AreEqual(42, location);
                Assert.AreEqual(23, result);
            }
        }
        public void AutoConfiguredMoqPrigCustomization_should_not_mock_generic_method_because_we_cannot_determine_the_generic_argument()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var ms      = new MockStorage(MockBehavior.Default);
                var fixture = new Fixture().Customize(new AutoConfiguredMoqPrigCustomization(ms));

                PInterlocked.ExchangeOfTTRefT <Version>().Body = (ref Version location1, Version value) => new Version(1, 2, 3);
                fixture.Create <PInterlocked>();


                // Act
                var location = new Version(4, 5, 6);
                var result   = Interlocked.Exchange(ref location, new Version(7, 8, 9));


                // Assert
                Assert.AreEqual(new Version(4, 5, 6), location);
                Assert.AreEqual(new Version(1, 2, 3), result);
            }
        }