コード例 #1
0
        public void GlobalTriggerCausesPersist()
        {
            //The idea: verify that firing the PersistRequired event causes the data store to commit the data

            Mock <IStore>        storeMoq        = new Mock <IStore>();
            Mock <IStoreFactory> storeFactoryMoq = new Mock <IStoreFactory>();

            storeFactoryMoq.Setup(sf => sf.CreateStoreForObject(It.IsAny <string>())).Returns(storeMoq.Object);

            var stateTracker1 = new StateTracker(storeFactoryMoq.Object, _trigger);

            stateTracker1.RegisterConfigurationInitializer(new FooConfigurationInitializer());//add initializer

            var testData1 = new Foo()
            {
                Double = 123.45f, Int = 456
            };
            var cfg1 = stateTracker1.Configure(testData1).IdentifyAs("x");

            //verify changes were committed once the persist trigger was fired
            storeMoq.Verify(s => s.CommitChanges(), Times.Never);
            _trigger.Fire();
            storeMoq.Verify(s => s.CommitChanges(), Times.Once);
        }