public void MockFile_AppendAllText_ShouldPersistNewTextWithCustomEncoding() { // Arrange const string path = @"c:\something\demo.txt"; var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { path, new MockFileData("Demo text content") } }); var file = new MockFile(fileSystem); // Act file.AppendAllText(path, "+ some text", Encoding.BigEndianUnicode); // Assert var expected = new byte[] { 68, 101, 109, 111, 32, 116, 101, 120, 116, 32, 99, 111, 110, 116, 101, 110, 255, 253, 0, 43, 0, 32, 0, 115, 0, 111, 0, 109, 0, 101, 0, 32, 0, 116, 0, 101, 0, 120, 0, 116 }; CollectionAssert.AreEqual( expected, file.ReadAllBytes(path)); }
public void Mockfile_Create_OverwritesExistingFile() { string path = XFS.Path(@"c:\some\file.txt"); var fileSystem = new MockFileSystem(); var mockFile = new MockFile(fileSystem); fileSystem.Directory.CreateDirectory(Path.GetDirectoryName(path)); // Create a file using (var stream = mockFile.Create(path)) { var contents = new UTF8Encoding(false).GetBytes("Test 1"); stream.Write(contents, 0, contents.Length); } // Create new file that should overwrite existing file var expectedContents = new UTF8Encoding(false).GetBytes("Test 2"); using (var stream = mockFile.Create(path)) { stream.Write(expectedContents, 0, expectedContents.Length); } var actualContents = fileSystem.GetFile(path).Contents; Assert.That(actualContents, Is.EqualTo(expectedContents)); }
public void Mockfile_Create_ThrowsWhenPathIsReadOnly() { string path = XFS.Path(@"c:\something\read-only.txt"); var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { path, new MockFileData("Content") } }); var mockFile = new MockFile(fileSystem); mockFile.SetAttributes(path, FileAttributes.ReadOnly); var exception = Assert.Throws<UnauthorizedAccessException>(() => mockFile.Create(path).Close()); Assert.That(exception.Message, Is.EqualTo(string.Format(CultureInfo.InvariantCulture, "Access to the path '{0}' is denied.", path))); }
public void TestBuildZipFile() { ZipArchive zipArchive = this.GetZipArchive(); ZipArchiveEntry zipArchiveEntry = zipArchive.CreateEntry("folderName.dll"); MockFile mockFile = new MockFile { FileExists = false }; this.mockFileSystem.SetupGet(x => x.File).Returns(mockFile); this.service.BuildZipFile("updatesDirectory", "folderName", zipArchive, zipArchiveEntry); }
public void Mockfile_CreateOverload_ShouldCreateNewStream() { string fullPath = XFS.Path(@"c:\something\demo.txt"); var fileSystem = new MockFileSystem(); fileSystem.AddDirectory(XFS.Path(@"c:\something")); FileOptions fileOption = FileOptions.WriteThrough; var mockFile = new MockFile(fileSystem); Assert.That(fileSystem.FileExists(fullPath), Is.False); mockFile.Create(fullPath, 20, fileOption).Dispose(); Assert.That(fileSystem.FileExists(fullPath), Is.True); }
public async Task Test4_UploadToDesignShopWithValidCurrentWorkingFormButInvalidMimeType() { // Act var result = await _fixture._controller.PostUploadImageStore(_fixture._designShopWithCurrentWorkingForm.Id, MockFile.mock("example1.png", "application/pdf")); // Assert // First assert: did we get an actionresult with an ImageStore var firstResult = Assert.IsType <ActionResult <ImageStore> >(result); // Second assert, is the file accepted Assert.IsType <BadRequestResult>(result.Result); }
public void Mockfile_Create_ShouldCreateNewStream() { string fullPath = XFS.Path(@"c:\something\demo.txt"); var fileSystem = new MockFileSystem(); var sut = new MockFile(fileSystem); Assert.That(fileSystem.FileExists(fullPath), Is.False); sut.Create(fullPath).Close(); Assert.That(fileSystem.FileExists(fullPath), Is.True); }
public void Mockfile_Create_ShouldCreateNewStream() { const string fullPath = @"c:\something\demo.txt"; var fileSystem = new MockFileSystem(); var sut = new MockFile(fileSystem); Assert.That(fileSystem.FileExists(fullPath), Is.False); sut.Create(fullPath).Close(); Assert.That(fileSystem.FileExists(fullPath), Is.True); }
public async Task Test2_UploadToDesignShopWithoutValidCurrentWorkingForm() { // Act var result = await _fixture._controller.PostUploadImageStore( _fixture._designShopWithoutCurrentWorkingForm.Id, MockFile.mock("example.png", "image/png")); // Assert // First assert: did we get an actionresult with an ImageStore var firstResult = Assert.IsType <ActionResult <ImageStore> >(result); // Second assert, is the file accepted Assert.IsType <NotFoundResult>(result.Result); }
public List <IFile> searchFiles() { List <IFile> list = new List <IFile>(); for (int i = 0; i < 10; i++) { IFile file = new MockFile(); string name = "file" + i.ToString() + ".xc"; file.Path = name; list.Add(file); } return(list); }
public void Mockfile_Create_ShouldCreateNewStream() { string fullPath = XFS.Path(@"c:\something\demo.txt"); var fileSystem = new MockFileSystem(); var sut = new MockFile(fileSystem); Assert.False(fileSystem.FileExists(fullPath)); sut.Create(fullPath).Dispose(); Assert.True(fileSystem.FileExists(fullPath)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the writer. /// </summary> /// <param name="filename">The filename.</param> /// <param name="encoding">The encoding.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ TextWriter IFileOS.GetWriter(string filename, Encoding encoding) { if (!((IFileOS)this).FileExists(filename)) { AddFile(filename, string.Empty, encoding); } MockFile finfo = GetFileInfo(filename, FileLockType.Write); Assert.AreEqual(finfo.Encoding, encoding); StringWriter writer = new StringWriter(new StringBuilder()); finfo.AddStream(writer); return(writer); }
public void MockFile_Delete_ShouldRemoveFileFromFileSystem() { string fullPath = XFS.Path(@"c:\something\demo.txt"); var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { fullPath, new MockFileData("Demo text content") } }); var file = new MockFile(fileSystem); file.Delete(fullPath); Assert.That(fileSystem.FileExists(fullPath), Is.False); }
public void AppendToMockFile(string fileName, string fileContents) { if (!_mockFileTable.ContainsKey(fileName)) { CreateMockFile(fileName, fileContents); } else { var existingMockMetadata = _mockFileTable[fileName].Item1; StringBuilder builder = new StringBuilder(_mockFileTable[fileName].Item2); builder.AppendFormat("{0}{1}", Environment.NewLine, fileContents); _mockFileTable[fileName] = new MockFile(existingMockMetadata, builder.ToString()); } }
public void Mockfile_Create_ThrowsWhenPathIsReadOnly() { const string path = @"c:\something\read-only.txt"; var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { path, new MockFileData("Content") } }); var mockFile = new MockFile(fileSystem); mockFile.SetAttributes(path, FileAttributes.ReadOnly); var exception = Assert.Throws <UnauthorizedAccessException>(() => mockFile.Create(path).Close()); Assert.That(exception.Message, Is.EqualTo(string.Format("Access to the path '{0}' is denied.", path))); }
public void Initialize() { this.mockFileSystem = new Mock <IFileSystem>(); this.mockSettingsService = new Mock <ISettingsService>(); this.mockFile = new MockFile(); this.mockFileInfoFactory = new Mock <IFileInfoFactory>(); this.mockFileInfo = new MockFileInfo(); this.mockFileSystem.SetupGet(x => x.File).Returns(this.mockFile); this.mockFileSystem.SetupGet(x => x.FileInfo).Returns(this.mockFileInfoFactory.Object); this.mockFileInfoFactory.Setup(x => x.FromFileName(It.IsAny <string>())).Returns(this.mockFileInfo); this.service = new CodeConfigService(); }
public void Initialize() { this.mockFileSystem = new Mock<IFileSystem>(); this.mockSettingsService = new Mock<ISettingsService>(); this.mockFile = new MockFile(); this.mockFileInfoFactory = new Mock<IFileInfoFactory>(); this.mockFileInfo = new MockFileInfo(); this.mockFileSystem.SetupGet(x => x.File).Returns(this.mockFile); this.mockFileSystem.SetupGet(x => x.FileInfo).Returns(this.mockFileInfoFactory.Object); this.mockFileInfoFactory.Setup(x => x.FromFileName(It.IsAny<string>())).Returns(this.mockFileInfo); this.service = new CodeConfigService(); }
/// <summary> /// Returns the file at the path specified. /// </summary> /// <param name="path"></param> /// <param name="throwIfNotFound"></param> /// <returns></returns> private MockFile FindFile(string path, bool throwIfNotFound = false) { MockFile result = null; FollowPathAndPerformActionOnFile(path, (folder, fileName) => { result = folder.FindFile(fileName); }, throwIfNotFound); if (result == null && throwIfNotFound) { throw new FileNotFoundException($"{path} cannot be found"); } return(result); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Opens a TextReader on the given file /// </summary> /// <param name="filename">The fully-qualified filename</param> /// <param name="encoding">The encoding to use for interpreting the contents</param> /// ------------------------------------------------------------------------------------ TextReader IFileOS.GetReader(string filename, Encoding encoding) { MockFile finfo = GetFileInfo(filename, FileLockType.Read); // Make sure the encoding of the file is the same as the requested type. // However, it is possible that we want an ASCII encoded file opened in the magic // code page to turn it into unicode. Assert.IsTrue(finfo.Encoding == encoding || ((finfo.Encoding == Encoding.ASCII || finfo.Encoding == Encoding.UTF8) && encoding == Encoding.GetEncoding(FileUtils.kMagicCodePage))); StringReader reader = new StringReader(finfo.Contents.TrimStart('\ufeff')); finfo.AddStream(reader); return(reader); }
public void MockFile_ReadAllBytes_ShouldReturnOriginalByteData() { var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { XFS.Path(@"c:\something\demo.txt"), new MockFileData("Demo text content") }, { XFS.Path(@"c:\something\other.gif"), new MockFileData(new byte[] { 0x21, 0x58, 0x3f, 0xa9 }) } }); var file = new MockFile(fileSystem); var result = file.ReadAllBytes(XFS.Path(@"c:\something\other.gif")); CollectionAssert.AreEqual( new byte[] { 0x21, 0x58, 0x3f, 0xa9 }, result); }
public void TestCheckForUpdateNoUpdateAvailable() { FileSystem.Current.GetDirectory("c:\\program files\\MGDF\\game").Create(); FileSystem.Current.GetFile("c:\\program files\\MGDF\\game\\game.json").WriteText(ReadTextFile("console.json")); MockFile gamesManagerFile = (MockFile)FileSystem.Current.GetFile("C:\\program files\\MGDF\\GamesManager.exe"); gamesManagerFile.WriteText("EXECUTABLE"); gamesManagerFile.AssemblyVersion = new Version(1, 0, 0, 0); Game game = new Game("c:\\program files\\MGDF\\game\\game.json"); AvailableUpdates update = UpdateChecker.CheckForUpdate(game); Assert.IsNotNull(update); Assert.IsNull(update.Framework); }
public void MockFile_Exists_ShouldReturnTrueForPathVaryingByCase() { // Arrange MockFileSystem fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { XFS.Path(@"c:\something\demo.txt"), new MockFileData("Demo text content") }, { XFS.Path(@"c:\something\other.gif"), new MockFileData(new byte[] { 0x21, 0x58, 0x3f, 0xa9 }) } }); MockFile file = new MockFile(fileSystem); // Act bool result = file.Exists(XFS.Path(@"c:\SomeThing\Other.gif")); // Assert Assert.True(result); }
public void MockFile_ReadAllLines_ShouldReturnOriginalTextData() { // Arrange var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { XFS.Path(@"c:\something\demo.txt"), new MockFileData("Demo\r\ntext\ncontent\rvalue") }, { XFS.Path(@"c:\something\other.gif"), new MockFileData(new byte[] { 0x21, 0x58, 0x3f, 0xa9 }) } }); var file = new MockFile(fileSystem); // Act var result = file.ReadAllLines(XFS.Path(@"c:\something\demo.txt")); // Assert result.ShouldBeEquivalentTo(new[] { "Demo", "text", "content", "value" }, options => options.WithStrictOrdering()); }
public void Mockfile_Create_CanWriteToNewStream() { string fullPath = XFS.Path(@"c:\something\demo.txt"); var fileSystem = new MockFileSystem(); var data = new UTF8Encoding(false).GetBytes("Test string"); var sut = new MockFile(fileSystem); using (var stream = sut.Create(fullPath)) { stream.Write(data, 0, data.Length); } var mockFileData = fileSystem.GetFile(fullPath); var fileData = mockFileData.Contents; Assert.That(fileData, Is.EqualTo(data)); }
public void MockFile_Exists_ShouldReturnFalseForEntirelyDifferentPath() { // Arrange var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { XFS.Path(@"c:\something\demo.txt"), new MockFileData("Demo text content") }, { XFS.Path(@"c:\something\other.gif"), new MockFileData(new byte[] { 0x21, 0x58, 0x3f, 0xa9 }) } }); var file = new MockFile(fileSystem); // Act var result = file.Exists(XFS.Path(@"c:\SomeThing\DoesNotExist.gif")); // Assert Assert.IsFalse(result); }
public void Mockfile_Create_ShouldThrowUnauthorizedAccessExceptionIfPathIsReadOnly() { // Arrange string path = XFS.Path(@"c:\something\read-only.txt"); var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { path, new MockFileData("Content") } }); var mockFile = new MockFile(fileSystem); // Act mockFile.SetAttributes(path, FileAttributes.ReadOnly); // Assert var exception = Assert.Throws <UnauthorizedAccessException>(() => mockFile.Create(path).Dispose()); Assert.That(exception.Message, Is.EqualTo(string.Format(CultureInfo.InvariantCulture, "Access to the path '{0}' is denied.", path))); }
public void MockFile_Exists_ShouldReturnFalseForEntirelyDifferentPath() { // Arrange MockFileSystem fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { XFS.Path(@"c:\something\demo.txt"), new MockFileData("Demo text content") }, { XFS.Path(@"c:\something\other.gif"), new MockFileData(new byte[] { 0x21, 0x58, 0x3f, 0xa9 }) } }); MockFile file = new MockFile(fileSystem); // Act bool result = file.Exists(XFS.Path(@"c:\SomeThing\DoesNotExist.gif")); // Assert Assert.False(result); }
public void MockFile_Exists_ShouldReturnTrueForPathVaryingByCase() { // Arrange var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { XFS.Path(@"c:\something\demo.txt"), new MockFileData("Demo text content") }, { XFS.Path(@"c:\something\other.gif"), new MockFileData(new byte[] { 0x21, 0x58, 0x3f, 0xa9 }) } }); var file = new MockFile(fileSystem); // Act var result = file.Exists(XFS.Path(@"c:\SomeThing\Other.gif")); // Assert Assert.IsTrue(result); }
public void MockFile_Exists_ShouldReturnFalseForDirectories() { // Arrange var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { XFS.Path(@"c:\something\demo.txt"), new MockFileData("Demo text content") }, { XFS.Path(@"c:\something\other.gif"), new MockFileData(new byte[] { 0x21, 0x58, 0x3f, 0xa9 }) } }); var file = new MockFile(fileSystem); // Act var result = file.Exists(XFS.Path(@"c:\SomeThing\")); // Assert Assert.IsFalse(result); }
public void Mockfile_Create_ShouldThrowUnauthorizedAccessExceptionIfPathIsReadOnly() { // Arrange string path = XFS.Path(@"c:\something\read-only.txt"); MockFileSystem fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { path, new MockFileData("Content") } }); MockFile mockFile = new MockFile(fileSystem); // Act mockFile.SetAttributes(path, FileAttributes.ReadOnly); // Assert UnauthorizedAccessException exception = Assert.Throws <UnauthorizedAccessException>(() => mockFile.Create(path).Dispose()); Assert.Equal(exception.Message, $"Access to the path '{path}' is denied."); }
public void MockFile_Exists_ShouldReturnTrueForSamePath() { // Arrange var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { @"c:\something\demo.txt", new MockFileData("Demo text content") }, { @"c:\something\other.gif", new MockFileData(new byte[] { 0x21, 0x58, 0x3f, 0xa9 }) } }); var file = new MockFile(fileSystem); // Act var result = file.Exists(@"c:\something\other.gif"); // Assert Assert.IsTrue(result); }
/// <summary> /// Initializes a new instance of the <see cref="MockFileProvider"/> class. /// </summary> public MockFileProvider() { _randomNumberGenerator = new RNGCryptoServiceProvider(); _randomDataFile = new MockFile(CreateRandomData(10000)); var sub = new MockDirectory { { "index.html", StockResource.GetBytes("sub.index.html") }, }; _root = new MockDirectory { { "index.html", StockResource.GetBytes("index.html") }, { "random.dat", _randomDataFile }, { "sub", sub }, }; }
public void MockFile_ReadAllLines_ShouldReturnOriginalDataWithCustomEncoding() { // Arrange string text = "Hello\r\nthere\rBob\nBob!"; var encodedText = Encoding.BigEndianUnicode.GetBytes(text); var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { XFS.Path(@"c:\something\demo.txt"), new MockFileData(encodedText) } }); var file = new MockFile(fileSystem); // Act var result = file.ReadAllLines(XFS.Path(@"c:\something\demo.txt"), Encoding.BigEndianUnicode); // Assert result.ShouldBeEquivalentTo(new[] { "Hello", "there", "Bob", "Bob!" }, options => options.WithStrictOrdering()); }
public void MockFile_AppendAllText_ShouldPersistNewTextWithDifferentEncoding() { // Arrange const string Path = @"c:\something\demo.txt"; var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { Path, new MockFileData("AA", Encoding.UTF32) } }); var file = new MockFile(fileSystem); // Act file.AppendAllText(Path, "BB", Encoding.UTF8); // Assert fileSystem.GetFile(Path) .Contents.ShouldBeEquivalentTo(new byte[] { 255, 254, 0, 0, 65, 0, 0, 0, 65, 0, 0, 0, 66, 66 }, options => options.WithStrictOrdering()); }
public void Mockfile_Create_CanWriteToNewStream() { const string fullPath = @"c:\something\demo.txt"; var fileSystem = new MockFileSystem(); var data = new UTF8Encoding(false).GetBytes("Test string"); var sut = new MockFile(fileSystem); using (var stream = sut.Create(fullPath)) { stream.Write(data, 0, data.Length); } var mockFileData = fileSystem.GetFile(fullPath); var fileData = mockFileData.Contents; Assert.That(fileData, Is.EqualTo(data)); }
public void TestAddNewFile() { MockFile tester = new MockFile(); tester.createMockFile(); File file4 = new File(); file4.Name = "kk.doc"; file4.ContentType = " "; file4.Size = 100; file4.UserId = 1; file4.FileId = 4; tester.addNewFile(file4); List <File> result = tester.getAllFile(); int expected = 4; Assert.AreEqual(expected, result.Count, "Seharusnya 4"); }
public void MockFile_GetSetCreationTime_ShouldPersist() { // Arrange const string path = @"c:\something\demo.txt"; var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { path, new MockFileData("Demo text content") } }); var file = new MockFile(fileSystem); // Act var creationTime = new DateTime(2010, 6, 4, 13, 26, 42); file.SetCreationTime(path, creationTime); var result = file.GetCreationTime(path); // Assert Assert.AreEqual(creationTime, result); }
public void MockFile_AppendAllLines_ShouldPersistNewLinesToNewFile() { // Arrange string path = XFS.Path(@"c:\something\demo.txt"); var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { XFS.Path(@"c:\something\"), new MockDirectoryData() } }); var file = new MockFile(fileSystem); // Act file.AppendAllLines(path, new[] { "line 1", "line 2", "line 3" }); // Assert Assert.AreEqual( "line 1" + Environment.NewLine + "line 2" + Environment.NewLine + "line 3" + Environment.NewLine, file.ReadAllText(path)); }
public void MockFile_SetCreationTime_ShouldAffectCreationTimeUtc() { // Arrange string path = XFS.Path(@"c:\something\demo.txt"); var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { path, new MockFileData("Demo text content") } }); var file = new MockFile(fileSystem); // Act var creationTime = new DateTime(2010, 6, 4, 13, 26, 42); file.SetCreationTime(path, creationTime); var result = file.GetCreationTimeUtc(path); // Assert Assert.AreEqual(creationTime.ToUniversalTime(), result); }
public void MockFile_ReadAllText_ShouldReturnOriginalDataWithCustomEncoding() { // Arrange string text = "Hello there!"; var encodedText = Encoding.BigEndianUnicode.GetBytes(text); var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { XFS.Path(@"c:\something\demo.txt"), new MockFileData(encodedText) } }); var file = new MockFile(fileSystem); // Act var result = file.ReadAllText(XFS.Path(@"c:\something\demo.txt"), Encoding.BigEndianUnicode); // Assert Assert.AreEqual(text, result); }
public void MockFile_AppendAllLines_ShouldPersistNewLinesToNewFile() { // Arrange string path = XFS.Path(@"c:\something\demo.txt"); var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { XFS.Path(@"c:\something\"), new MockDirectoryData() } }); var file = new MockFile(fileSystem); // Act file.AppendAllLines(path, new[] { "line 1", "line 2", "line 3" }); // Assert Assert.AreEqual( "line 1" + Environment.NewLine + "line 2" + Environment.NewLine + "line 3" + Environment.NewLine, file.ReadAllText(path)); }
public void MockFile_AppendAllText_ShouldPersistNewText() { // Arrange string path = XFS.Path(@"c:\something\demo.txt"); var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { {path, new MockFileData("Demo text content")} }); var file = new MockFile(fileSystem); // Act file.AppendAllText(path, "+ some text"); // Assert Assert.AreEqual( "Demo text content+ some text", file.ReadAllText(path)); }
public void MockFile_ReadLines_ShouldReturnOriginalTextData() { // Arrange var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { XFS.Path(@"c:\something\demo.txt"), new MockFileData("Demo\r\ntext\ncontent\rvalue") }, { XFS.Path(@"c:\something\other.gif"), new MockFileData(new byte[] { 0x21, 0x58, 0x3f, 0xa9 }) } }); var file = new MockFile(fileSystem); // Act var result = file.ReadLines(XFS.Path(@"c:\something\demo.txt")); // Assert CollectionAssert.AreEqual( new[] { "Demo", "text", "content", "value" }, result); }
public void MockFile_AppendAllText_ShouldPersistNewTextWithDifferentEncoding() { // Arrange const string Path = @"c:\something\demo.txt"; var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { {Path, new MockFileData("AA", Encoding.UTF32)} }); var file = new MockFile(fileSystem); // Act file.AppendAllText(Path, "BB", Encoding.UTF8); // Assert CollectionAssert.AreEqual( new byte[] {255, 254, 0, 0, 65, 0, 0, 0, 65, 0, 0, 0, 66, 66}, fileSystem.GetFile(Path).Contents); }
public void MockFile_ReadLines_ShouldReturnOriginalDataWithCustomEncoding() { // Arrange string text = "Hello\r\nthere\rBob\nBob!"; var encodedText = Encoding.BigEndianUnicode.GetBytes(text); var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { XFS.Path(@"c:\something\demo.txt"), new MockFileData(encodedText) } }); var file = new MockFile(fileSystem); // Act var result = file.ReadLines(XFS.Path(@"c:\something\demo.txt"), Encoding.BigEndianUnicode); // Assert CollectionAssert.AreEqual( new [] { "Hello", "there", "Bob", "Bob!" }, result); }
public void MockFile_AppendAllText_ShouldFailIfNotExistButDirectoryAlsoNotExist() { // Arrange string path = @"c:\something\demo.txt"; var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { path, new MockFileData("Demo text content") } }); var file = new MockFile(fileSystem); // Act path = @"c:\something2\demo.txt"; // Assert Exception ex; ex = Assert.Throws<DirectoryNotFoundException>(() => fileSystem.File.AppendAllText(path, "some text")); Assert.That(ex.Message, Is.EqualTo(String.Format("Could not find a part of the path '{0}'.", path))); ex = Assert.Throws<DirectoryNotFoundException>(() => fileSystem.File.AppendAllText(path, "some text", Encoding.Unicode)); Assert.That(ex.Message, Is.EqualTo(String.Format("Could not find a part of the path '{0}'.", path))); }
public void Initialize() { this.mockPluginService = new Mock<IPluginService>(); this.mockVisualStudioService = new Mock<IVisualStudioService>(); this.mockFileSystem = new Mock<IFileSystem>(); this.mockSettingsService = new Mock<ISettingsService>(); this.mockNugetService = new Mock<INugetService>(); this.mockFile = new MockFile(); this.mockFileInfoFactory = new Mock<IFileInfoFactory>(); this.mockFileInfo = new MockFileInfo(); this.mockTestingServiceFactory = new Mock<ITestingServiceFactory>(); this.mockCodeSnippetFactory = new Mock<ICodeSnippetFactory>(); this.mockFileSystem.SetupGet(x => x.File).Returns(this.mockFile); this.mockFileSystem.SetupGet(x => x.FileInfo).Returns(this.mockFileInfoFactory.Object); this.mockFileInfoFactory.Setup(x => x.FromFileName(It.IsAny<string>())).Returns(this.mockFileInfo); /*this.service = new PluginsService( this.mockPluginService.Object, this.mockSettingsService.Object, this.mockNugetService.Object, this.mockCodeSnippetFactory.Object, this.mockTestingServiceFactory.Object);*/ }
private FileStatus createStatus(MockFile file) { return new FileStatus(file.length, false, 1, file.blockSize, 0, 0, FsPermission.createImmutable((short) 644), "owen", "group", file.path); }
static void ExecuteDefaultValueTest(Func<MockFile, string, DateTime> getDateValue) { var expected = new DateTime(1601, 01, 01, 00, 00, 00, DateTimeKind.Utc); const string path = @"c:\something\demo.txt"; var fileSystem = new MockFileSystem(); var file = new MockFile(fileSystem); var actual = getDateValue(file, path); Assert.That(actual.ToUniversalTime(), Is.EqualTo(expected)); }
public void MockFile_Exists_ShouldReturnFalseForNullPath() { var file = new MockFile(new MockFileSystem()); Assert.That(file.Exists(null), Is.False); }
public void Mockfile_Create_ShouldCreateNewStream() { const string fullPath = @"c:\something\demo.txt"; var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>()); var sut = new MockFile(fileSystem); Assert.That(fileSystem.FileExists(fullPath), Is.False); sut.Create(fullPath).Close(); Assert.That(fileSystem.FileExists(fullPath), Is.True); }
public FSDataOutputStream create(Path path, FsPermission fsPermission, bool overwrite, int bufferSize, short replication, long blockSize, Progressable progressable ) { MockFile file = null; for(MockFile currentFile: files) { if (currentFile.path.equals(path)) { file = currentFile; break; } } if (file == null) { file = new MockFile(path.toString(), (int) blockSize, new byte[0]); files.add(file); } return new MockOutputStream(file); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds the given filename to the collection of files that should be considered to /// exist and set its contents so it can be read. /// </summary> /// <param name="filename">The filename (may or may not include path).</param> /// <param name="contents">The contents of the file</param> /// <param name="encoding">File encoding</param> /// ------------------------------------------------------------------------------------ public void AddFile(string filename, string contents, Encoding encoding) { FileUtils.AssertValidFilePath(filename); string dir = Path.GetDirectoryName(filename); if (!string.IsNullOrEmpty(dir) && !((IFileOS)this).DirectoryExists(dir)) ExistingDirectories.Add(dir); // Theoretically, this should add containing folders recursively. m_existingFiles[filename] = new MockFile(contents, encoding); }
public void MockFile_ReadAllText_ShouldReturnOriginalDataWithCustomEncoding() { // Arrange const string text = "Hello there!"; var encodedText = Encoding.BigEndianUnicode.GetBytes(text); var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { @"c:\something\demo.txt", new MockFileData(encodedText) } }); var file = new MockFile(fileSystem); // Act var result = file.ReadAllText(@"c:\something\demo.txt", Encoding.BigEndianUnicode); // Assert Assert.AreEqual(text, result); }
public void MockFile_ReadAllText_ShouldReturnOriginalTextData() { // Arrange var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { @"c:\something\demo.txt", new MockFileData("Demo text content") }, { @"c:\something\other.gif", new MockFileData(new byte[] { 0x21, 0x58, 0x3f, 0xa9 }) } }); var file = new MockFile(fileSystem); // Act var result = file.ReadAllText(@"c:\something\demo.txt"); // Assert Assert.AreEqual( "Demo text content", result); }
public MockInputStream(MockFile file) { this.file = file; }
public void MockFile_SetLastWriteTimeUtc_ShouldAffectLastWriteTime() { // Arrange const string path = @"c:\something\demo.txt"; var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { path, new MockFileData("Demo text content") } }); var file = new MockFile(fileSystem); // Act var lastWriteTime = new DateTime(2010, 6, 4, 13, 26, 42); file.SetLastWriteTimeUtc(path, lastWriteTime.ToUniversalTime()); var result = file.GetLastWriteTime(path); // Assert Assert.AreEqual(lastWriteTime, result); }
public void MockFile_Delete_ShouldRemoveFileFromFileSystem() { const string fullPath = @"c:\something\demo.txt"; var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { fullPath, new MockFileData("Demo text content") } }); var file = new MockFile(fileSystem); file.Delete(fullPath); Assert.That(fileSystem.FileExists(fullPath), Is.False); }
public MockFileSystem(Configuration conf, MockFile... files) { setConf(conf); this.files.addAll(Arrays.asList(files)); }
public MockOutputStream(MockFile file) { super(new DataOutputBuffer(), null); this.file = file; }