public void InitializeConfigFile_InstalledFileExists_UserFileExists_ReturnTrue() { string installedFilePath = "installedFilePath"; string userFilePath = "userFilePath"; IFileSystemOperation stubFileSystemOperator = MockRepository.GenerateStub <IFileSystemOperation>(); stubFileSystemOperator.Stub(s => s.FileExists("")).IgnoreArguments().Repeat.Any().Return(true); OptimizedTarget target = new OptimizedTarget(null, stubFileSystemOperator); bool fileExistResult = target.InitializeConfigFile(installedFilePath, userFilePath); Assert.IsTrue(fileExistResult); }
public void InitializeConfigFile_InstalledFileNotExists_ReturnFalse() { string installedFilePath = "installedFilePath"; string userFilePath = "userFilePath"; IFileSystemOperation stubFileSystemOperator = MockRepository.GenerateStub <IFileSystemOperation>(); stubFileSystemOperator.Stub(s => s.FileExists(installedFilePath)).Return(false); OptimizedTarget target = new OptimizedTarget(null, stubFileSystemOperator); bool installedFileNotExistsResult = target.InitializeConfigFile(installedFilePath, userFilePath); Assert.IsFalse(installedFileNotExistsResult); }
public void InitializeConfigFile_InstalledFileExists_UserFileNotExists_CopyFileAndReturnTrue() { string installedFilePath = "installedFilePath"; string userFilePath = "userFilePath"; IFileSystemOperation mockFileSystemOperator = MockRepository.GenerateMock <IFileSystemOperation>(); mockFileSystemOperator.Stub(s => s.FileExists(installedFilePath)).Return(true); mockFileSystemOperator.Stub(s => s.FileExists(userFilePath)).Return(false); OptimizedTarget target = new OptimizedTarget(null, mockFileSystemOperator); bool installedFileExistsUserFileNotExistsResult = target.InitializeConfigFile(installedFilePath, userFilePath); mockFileSystemOperator.AssertWasCalled(s => s.FileCopy(installedFilePath, userFilePath)); Assert.IsTrue(installedFileExistsUserFileNotExistsResult); }
public void InitializeConfigFile_InstalledFileExists_UserFileNotExists_ThrowException_ReturnFalse() { string installedFilePath = "installedFilePath"; string userFilePath = "userFilePath"; IFileSystemOperation mockFileSystemOperator = MockRepository.GenerateMock <IFileSystemOperation>(); mockFileSystemOperator.Stub(s => s.FileExists(installedFilePath)).Return(true); mockFileSystemOperator.Stub(s => s.FileExists(userFilePath)).Return(false); mockFileSystemOperator.Stub(s => s.FileCopy("", "")).IgnoreArguments().Throw(new Exception()); OptimizedTarget target = new OptimizedTarget(null, mockFileSystemOperator); bool throwExceptionResult = target.InitializeConfigFile(installedFilePath, userFilePath); mockFileSystemOperator.AssertWasCalled(s => s.FileCopy(installedFilePath, userFilePath)); Assert.IsFalse(throwExceptionResult); }
// Used by unit test public OptimizedTarget(IHttpClientWrapper httpClientWrapper, IFileSystemOperation fileSystemOperator) { this._httpClientWrapper = httpClientWrapper; this._fileSystemOperator = fileSystemOperator; }
// Default public OptimizedTarget() { _httpClientWrapper = new HttpClientWrapper(); _fileSystemOperator = new FileSystemOperator(); }