public async Task AddImage_should_create_if_folder_absent() { var fileSystem = new MockFileSystem(); _cache = new DirectoryImageCache(_folderPath, 2, fileSystem); fileSystem.Directory.Exists(_folderPath).Should().BeFalse(); using (var s = new MemoryStream()) { await _cache.AddImageAsync("file", s); } fileSystem.Directory.Exists(_folderPath).Should().BeTrue(); }
public void Setup() { _fileSystem = Substitute.For <IFileSystem>(); _directory = Substitute.For <DirectoryBase>(); _fileSystem.Directory.Returns(_directory); _file = Substitute.For <FileBase>(); _fileSystem.File.Returns(_file); _fileInfo = Substitute.For <FileInfoBase>(); _fileInfoFactory = Substitute.For <IFileInfoFactory>(); _fileInfoFactory.FromFileName(Arg.Any <string>()).Returns(_fileInfo); _fileSystem.FileInfo.Returns(_fileInfoFactory); _cache = new DirectoryImageCache(_folderPath, 2, _fileSystem); }
public async Task Clear_should_remove_all() { var fileSystem = new MockFileSystem(); _cache = new DirectoryImageCache(_folderPath, 2, fileSystem); fileSystem.AddFile(Path.Combine(_folderPath, "*****@*****.**"), new MockFileData("")); fileSystem.AddFile(Path.Combine(_folderPath, "*****@*****.**"), new MockFileData("")); fileSystem.AllFiles.Count().Should().Be(2); await _cache.ClearAsync(); fileSystem.AllFiles.Count().Should().Be(0); }
public async void Clear_should_remove_all() { var fileSystem = new MockFileSystem(); _cache = new DirectoryImageCache(FolderPath, 2, fileSystem); fileSystem.AddFile($"{FolderPath}\\[email protected]", new MockFileData("")); fileSystem.AddFile($"{FolderPath}\\[email protected]", new MockFileData("")); fileSystem.AllFiles.Count().Should().Be(2); await _cache.ClearAsync(); fileSystem.AllFiles.Count().Should().Be(0); }
public void Setup() { if (Type.GetType("Mono.Runtime") != null) { _folderPath = "/home/user/gitextensions/images"; } _fileSystem = Substitute.For <IFileSystem>(); _directory = Substitute.For <DirectoryBase>(); _fileSystem.Directory.Returns(_directory); _file = Substitute.For <FileBase>(); _fileSystem.File.Returns(_file); _fileInfo = Substitute.For <FileInfoBase>(); _fileInfoFactory = Substitute.For <IFileInfoFactory>(); _fileInfoFactory.FromFileName(Arg.Any <string>()).Returns(_fileInfo); _fileSystem.FileInfo.Returns(_fileInfoFactory); _cache = new DirectoryImageCache(_folderPath, 2, _fileSystem); }
public async Task AddImage_should_create_image_from_stream() { var currentFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var folderPath = Path.Combine(currentFolder, "Images"); using (var imageStream = new MemoryStream()) { var fileSystem = new FileSystem(); Resources.User.Save(imageStream, ImageFormat.Png); imageStream.Position = 0; _cache = new DirectoryImageCache(folderPath, 2, fileSystem); fileSystem.Directory.Exists(_folderPath).Should().BeFalse(); await _cache.AddImageAsync("file.png", imageStream); fileSystem.Directory.Exists(folderPath).Should().BeTrue(); fileSystem.File.Exists(Path.Combine(folderPath, "file.png")).Should().BeTrue(); } }
public async Task AddImage_should_raise_invalidate() { var currentFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var folderPath = Path.Combine(currentFolder, "Images"); using (var imageStream = new MemoryStream()) { var fileSystem = new FileSystem(); Resources.User.Save(imageStream, ImageFormat.Png); imageStream.Position = 0; bool eventRaised = false; _cache = new DirectoryImageCache(folderPath, 2, fileSystem); _cache.Invalidated += (s, e) => eventRaised = true; await _cache.AddImageAsync("file.png", imageStream); eventRaised.Should().BeTrue(); } }