public void SpySurrogateTest()
        {
            var subrogateScope = new SpringDeepSubrogationScope(this,
                                                                (AbstractApplicationContext)applicationContext);

            try
            {
                subrogateScope.DeepSubrogate();

                _vehicle.Accelerate(50);
                _vehicle.Accelerate(150);

                _airplane.Accelerate(500);
                _airplane.Accelerate(1500);

                Assert.AreEqual(200.0, _vehicle.SpeedInKph);
                Assert.AreEqual(2000.0, _airplane.SpeedInKph);
                A.CallTo(() => _calculator.Add(A <double> ._, A <double> ._))
                .MustHaveHappened(Repeated.Exactly.Times(4));
            }
            finally
            {
                subrogateScope.DeepRestore();
            }
        }
        public void SpiesAreApplied()
        {
            var subrogateScope = new SpringDeepSubrogationScope(this,
                                                                (AbstractApplicationContext)applicationContext);

            subrogateScope.DeepSubrogate();

            Assert.AreEqual(13, _calculator.Add(7, 6));
            A.CallTo(() => _calculator.Add(A <double> ._, A <double> ._))
            .MustHaveHappened(Repeated.Exactly.Once);
            Assert.IsNotNull(_vehicle);

            subrogateScope.DeepRestore();
        }
Пример #3
0
        public void SubrogateAndRestoreContextTest()
        {
            var subrogateScope = new SpringDeepSubrogationScope(this,
                                                                (AbstractApplicationContext)applicationContext);

            var oldCalculator = _dummyCalculator;

            subrogateScope.DeepSubrogate();

            Assert.AreNotSame(oldCalculator.GetType(), _dummyCalculator.GetType());

            subrogateScope.DeepRestore();

            Assert.AreSame(oldCalculator.GetType(), _dummyCalculator.GetType());
        }
Пример #4
0
        public void SubrogateObjectInConcreteClassInstanceFieldTest()
        {
            var subrogateScope = new SpringDeepSubrogationScope(this,
                                                                (AbstractApplicationContext)applicationContext);

            // Subrogate the referenced objects as marked with the [Subrogate] annotation.
            subrogateScope.DeepSubrogate();

            // Now that the original objects have been subrogates with fakes / mocks,
            // configure those. In this case, configure the Add method of ICalculator
            // to always return 100, no matter the arguments.
            A.CallTo(() => _dummyCalculator.Add(A <double> ._, A <double> ._)).Returns(100.0);

            // Make sure vehicle's speed is 0.0 Km/h (stopped)
            _vehicle.Stop();
            Assert.AreEqual(0, _vehicle.SpeedInKph);

            // Accelerate the vehicle by 10 and then 40 Km/h.
            _vehicle.Accelerate(10);
            _vehicle.Accelerate(40);
            // Expected result here is 100.0, instead of 50.0. This is because every time we add
            // two doubles, the result is always 100.0, as configured before.
            Assert.AreEqual(100, _vehicle.SpeedInKph);

            // Restore the original objects that were subrogated earlier.
            subrogateScope.DeepRestore();

            // Make sure vehicle's speed is 0.0 Km/h (stopped)
            _vehicle.Stop();
            Assert.AreEqual(0, _vehicle.SpeedInKph);

            // Accelerate the vehicle by 10 and then 40 Km/h.
            _vehicle.Accelerate(10);
            _vehicle.Accelerate(40);
            // Expected result here is 50.0 This is because the original ICalculator object has been
            // restored and does the correct math.
            Assert.AreEqual(50, _vehicle.SpeedInKph);
        }
Пример #5
0
 protected void SubrogationCleanup()
 {
     _subrogationScope = null;
 }
Пример #6
0
        protected void SubrogationInit()
        {
            var appContext = GetContext(ContextKey);

            _subrogationScope = new SpringDeepSubrogationScope(this, appContext);
        }