public void ConfigRepositoryRemoveSiteTest() { FileHelper.FileSystem = new MockFileSystem(new Dictionary <string, MockFileData>() { { @"c:\site1.publishsettings", new MockFileData(string.Format(ProfileTemplate, "site1")) }, { @"c:\site2.foo.publishsettings", new MockFileData(string.Format(ProfileTemplate, "site2")) }, { @"c:\foo.txt", new MockFileData("bar") }, { @"c:\site1\", new MockDirectoryData() } }); IConfigRepository repository = new ConfigRepository(); repository.RemoveSite("site1"); repository.RemoveSite("site2"); FileBase fileBase = FileHelper.FileSystem.File; DirectoryBase dirBase = FileHelper.FileSystem.Directory; Assert.IsFalse(fileBase.Exists(@"c:\site1.publishSettings"), "site1 publishSettings still exists"); Assert.IsFalse(dirBase.Exists(@"c:\site1"), "site1 folder still exists"); Assert.IsFalse(fileBase.Exists(@"c:\site2.foo.publishsettings"), "sit2 publishSettings still exists"); }
public void Resolve_should_return_original_path_if_git_file_or_folder_absent() { _directory.Exists(_gitWorkingDir).Returns(false); _file.Exists(Arg.Any <string>()).Returns(false); _resolver.Resolve(_workingDir).Should().Be(_workingDir); }
public async Task DeleteImage_should_return_if_folder_absent() { _file.Exists(Arg.Any <string>()).Returns(false); await _cache.DeleteImageAsync(FileName); _file.DidNotReceive().Delete(Arg.Any <string>()); }
public void Get_if_file_does_not_exist_create_temp() { const string file = @"c:\file.txt"; _file.Exists(file).Returns(false); _iconProvider.Get(file).Should().BeNull(); var tempPath = Path.Combine(Path.GetTempPath(), "file.txt"); _file.Received(1).WriteAllText(tempPath, string.Empty); }
public static void SafeAction(this FileBase fileBase, string file, Action <string> action) { if (fileBase == null) { throw new ArgumentNullException("fileBase"); } if (string.IsNullOrEmpty(file)) { throw new ArgumentNullException("file"); } if (action == null) { throw new ArgumentNullException("action"); } var tmp = String.Concat(file, ".tmp"); action(tmp); if (!fileBase.Exists(tmp)) { throw new InvalidOperationException("action must create a file"); } //fileBase.Replace(tmp, file, null); write a TestHelper for Replace and make a pull request first fileBase.Delete(file); fileBase.Move(tmp, file); }
public void LocalExists_should_return_true_if_file_exists() { IEnumerable <GitItemStatus> selectedItemsWithParent = new List <GitItemStatus> { new GitItemStatus() { IsTracked = true, Name = "file1" }, new GitItemStatus() { IsTracked = true, Name = "file2" } }; _fullPathResolver.Resolve("file1").Returns("file1"); _fullPathResolver.Resolve("file2").Returns("file2"); _file.Exists("file1").Returns(false); _file.Exists("file2").Returns(true); _tester.AnyLocalFileExists(selectedItemsWithParent).Should().BeTrue(); }
public void LoadGitCommitTemplate_should_load_file_content() { const string relativePath = "./template.txt"; string fullPath = Path.GetFullPath(Path.Combine(_workingDir, relativePath)); _module.WorkingDir.Returns(_workingDir); _fullPathResolver.Resolve(relativePath).Returns(fullPath); _module.GetEffectiveSetting("commit.template").Returns(relativePath); _file.Exists(fullPath).Returns(true); _file.ReadAllText(fullPath).Returns("line1"); var content = _manager.LoadGitCommitTemplate(); content.Should().NotBeEmpty(); }
public MockFileSystem(IDictionary<string, MockFileData> files) { file = new MockFile(this); directory = new MockDirectory(this, file); fileInfoFactory = new MockFileInfoFactory(this); path = new MockPath(); directoryInfoFactory = new MockDirectoryInfoFactory(this); //For each mock file add a file to the files dictionary //Also add a file entry for all directories leading up to this file this.files = new Dictionary<string, MockFileData>(StringComparer.InvariantCultureIgnoreCase); foreach (var entry in files) { var directoryPath = Path.GetDirectoryName(entry.Key); if (!directory.Exists(directoryPath)) directory.CreateDirectory(directoryPath); if (!file.Exists(entry.Key)) this.files.Add(entry.Key, entry.Value); } }
public void AmendState_should_be_false_if_file_is_missing() { _file.Exists(_amendSaveStatePath).Returns(false); AppSettings.RememberAmendCommitState = true; _manager.AmendState.Should().BeFalse(); }
public void IsIndexLocked(bool fileExists) { _file.Exists(Arg.Any <string>()).Returns(fileExists); _manager.IsIndexLocked().Should().Be(fileExists); }