Exemplo n.º 1
0
        /// <summary>
        /// Uses dependency injection and inversion of control. By using these
        /// techniques we make the object constructing this object provide all
        /// of the external dependencies. The code is less fragile, reuse is 
        /// encouraged, and there should be less bugs.
        /// Look at the DependencyLoader to see how we're telling the system to
        /// load the implementation classes for this class.
        /// </summary>
        /// <param name="fileSync"></param>
        /// <param name="userInteractions"></param>
        /// <param name="settings"></param>
        /// <param name="backupAccess"></param>
        public RunBackup(
            IFileSync fileSync, 
            IInteractionContext userInteractions, 
            ISettingsProvider settings, 
            IBackupAccess backupAccess)
        {
            _FileSystem = fileSync;
            _Interactions = userInteractions;
            _Settings = settings;
            _BackupDirectory = backupAccess;

            _FileSystem.AppliedChange += OnAppliedChange;
            _FileSystem.SkippedChange += OnSkippedChange;
        }
        public void Setup()
        {
            //Here we're doing all of the set up for this clump of tests.

            // Mocks basically allow us to pretend like we have a class
            // when we really don't just so the program runs. This really
            // comes in handy when you have a large interface and don't want to
            // create a huge real class that has to have a bunch of empty methods
            // that never get called.
            Interactions = MockRepository.GenerateStub<IInteractionContext>();
            FileSync = MockRepository.GenerateStub<IFileSync>();
            BackupAccess = MockRepository.GenerateStub<IBackupAccess>();
            Settings = MockRepository.GenerateStub<ISettingsProvider>();
            BackupRunner = new RunBackup(FileSync, Interactions, Settings, BackupAccess);

            Context();
            Because();
        }