public virtual void Setup()
        {
            _latestRecentBackupQuery = A.Fake<LatestRecentBackupQuery>();
            _fileSystem = A.Fake<FileSystem>();

            _defaultSettings = new BackupSettings { BackupTargetDestination = "TargetDestination" };
        }
 public GetLatestBackupNameQuery(
     BackupSettings backupSettings, FileSystem fileSystem, BackupFileDatesQuery backupFileDatesQuery)
 {
     _backupSettings = backupSettings;
     _fileSystem = fileSystem;
     _backupFileDatesQuery = backupFileDatesQuery;
 }
 public CopyLatestBackupStorageTask(
     LatestRecentBackupQuery latestRecentBackupQuery, 
     FileSystem fileSystem, 
     BackupSettings backupSettings)
 {
     _latestRecentBackupQuery = latestRecentBackupQuery;
     _fileSystem = fileSystem;
     _backupSettings = backupSettings;
 }
        public virtual void Setup()
        {
            _fileSystem = A.Fake<FileSystem>();
            _backupFileDatesQuery = A.Fake<BackupFileDatesQuery>();

            _backupSettings = new BackupSettings
                {
                    BackupFilesLocation = "a\\files\\location"
                };
        }
        private void AddBasicAuthorizationHeader(BackupSettings backupSettings, HttpRequestMessage message)
        {
            string plainTextUserCredentials = string.Format(
                "{0}:{1}", backupSettings.BackupRequestUser, backupSettings.BackupRequestPassword);

            string encodedUserCredentials =
                Convert.ToBase64String(Encoding.ASCII.GetBytes(plainTextUserCredentials));

            message.Headers.Authorization = new AuthenticationHeaderValue("Basic", encodedUserCredentials);
        }
 public BackupExistsValidator(
     BackupSettings backupSettings, 
     FileSystem fileSystem, 
     BackupFileDatesQuery backupFileDatesQuery, 
     CurrentDateProvider currentDateProvider)
 {
     _backupSettings = backupSettings;
     _fileSystem = fileSystem;
     _backupFileDatesQuery = backupFileDatesQuery;
     _currentDateProvider = currentDateProvider;
 }
 public CleanUpOldDatabaseBackupsTask(
     FileSystem fileSystem, 
     BackupFileDatesQuery backupFileDatesQuery, 
     BackupSettings backupSettings, 
     BackupNotifier backupNotifier)
 {
     _fileSystem = fileSystem;
     _backupFileDatesQuery = backupFileDatesQuery;
     _backupSettings = backupSettings;
     _backupNotifier = backupNotifier;
 }
        public virtual void Setup()
        {
            _fileSystem = A.Fake<FileSystem>();
            _backupFileDatesQuery = A.Fake<BackupFileDatesQuery>();
            _backupNotifier = A.Fake<BackupNotifier>();

            _backupSettings = new BackupSettings
            {
                BackupTargetDestination = "A\\Target\\Destination"
            };

            _backupCleanUp = GetSUT();
        }
        public void Then_this_is_passed_to_the_HttpBackupRequest()
        {
            //Given:
            var backupSettings = new BackupSettings();

            HandledBackupRequest handledBackupRequest = GetSUT(backupSettings);

            //When:
            handledBackupRequest.RequestBackup();

            //Then:
            A.CallTo(() => HttpBackupRequest.Request(backupSettings)).MustHaveHappened();
        }
        public void Request(BackupSettings backupSettings)
        {
            var message = new HttpRequestMessage
                {
                    Method = HttpMethod.Post,
                    RequestUri = new Uri(backupSettings.BackupRequestUri),
                };

            AddBasicAuthorizationHeader(backupSettings, message);

            var client = new HttpClient();
            client.SendAsync(message).ContinueWith(task => { task.Result.EnsureSuccessStatusCode(); });
        }
        public void Then_a_list_of_all_backup_files_should_be_requested()
        {
            //Given:
            string backupFilesLocation = "someLocation";
            BackupSettings backupSettings = new BackupSettings
                {
                    BackupFilesLocation = backupFilesLocation
                };

            //When:
            whenABackupIsExpected(backupSettings);

            //Then:
            A.CallTo(() => _fileSystem.GetFileNames(backupFilesLocation)).MustHaveHappened();
        }
        public void Then_the_target_destination_is_a_combination_of_the_destination_and_the_expected_file_name(
            string latestBackupFilePath, string baseDestinationPath, string expectedDestinationFilePath)
        {
            //Given:
            A.CallTo(() => _latestRecentBackupQuery.GetName()).Returns(latestBackupFilePath);
            BackupSettings backupSettings = new BackupSettings { BackupTargetDestination = baseDestinationPath };

            CopyLatestBackupStorageTask copyLatestBackupStorageTask = GetSUT(backupSettings);

            //When:
            copyLatestBackupStorageTask.StoreBackup();

            //Then:
            A.CallTo(() => _fileSystem.CutFile(latestBackupFilePath, expectedDestinationFilePath))
             .MustHaveHappened();
        }
 public HandledBackupRequest GetSUT(BackupSettings backupSettings)
 {
     return new HandledBackupRequest(backupSettings, HttpBackupRequest);
 }
 public HandledBackupRequest(BackupSettings backupSettings, HttpBackupRequest httpBackupRequest)
 {
     _backupSettings = backupSettings;
     _httpBackupRequest = httpBackupRequest;
 }
 public BackupExistsValidator GetSUT(BackupSettings backupSettings)
 {
     return new BackupExistsValidator(backupSettings,
         _fileSystem, _backupFileDatesQuery, _currentDateProvider);
 }
 public CopyLatestBackupStorageTask GetSUT(BackupSettings backupSettings = null)
 {
     return new CopyLatestBackupStorageTask(
         _latestRecentBackupQuery, _fileSystem, backupSettings ?? _defaultSettings);
 }
 protected BackupValidationRecord whenABackupIsExpected(BackupSettings backupSettings)
 {
     BackupExistsValidator backupExistsValidator = GetSUT(backupSettings);
     return backupExistsValidator.GetBackupValidation();
 }
 public RestfulGetBackupStatus(BackupSettings backupSettings)
 {
     _backupSettings = backupSettings;
 }