public void MockFileInfo_Length_ShouldThrowFileNotFoundExcpetionIfFileDoesNotExistInMemoryFileSystem()
        {
            // Arrange
            const string fileContent = "Demo text content";
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { @"c:\a.txt", new MockFileData(fileContent) },
                { @"c:\a\b\c.txt", new MockFileData(fileContent) },
            });
            var fileInfo = new MockFileInfo(fileSystem, @"c:\foo.txt");

            try
            {
                // Act
                fileInfo.Length.ToString();

                // Assert
                Assert.Fail("Expected exception was not thrown");
            }
            catch (FileNotFoundException ex)
            {
                // Assert
                Assert.AreEqual(@"c:\foo.txt", ex.FileName);
            }
        }
        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 MockFileInfo_Exists_ShouldReturnFalseIfFileDoesNotExistInMemoryFileSystem()
        {
            // Arrange
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { @"c:\a.txt", new MockFileData("Demo text content") },
                { @"c:\a\b\c.txt", new MockFileData("Demo text content") },
            });
            var fileInfo = new MockFileInfo(fileSystem, @"c:\foo.txt");

            // Act
            var result = fileInfo.Exists;

            // Assert
            Assert.IsFalse(result);
        }
        public void MockFileInfo_Length_ShouldThrowFileNotFoundExceptionIfFileDoesNotExistInMemoryFileSystem()
        {
            // Arrange
            const string fileContent = "Demo text content";
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { @"c:\a.txt", new MockFileData(fileContent) },
                { @"c:\a\b\c.txt", new MockFileData(fileContent) },
            });
            var fileInfo = new MockFileInfo(fileSystem, @"c:\foo.txt");

// ReSharper disable ReturnValueOfPureMethodIsNotUsed
            var ex = Assert.Throws<FileNotFoundException>(() => fileInfo.Length.ToString(CultureInfo.InvariantCulture));
// ReSharper restore ReturnValueOfPureMethodIsNotUsed
            Assert.AreEqual(@"c:\foo.txt", ex.FileName);
        }
        public void MockFileInfo_Exists_ShouldReturnTrueIfFileExistsInMemoryFileSystem()
        {
            // Arrange
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), new MockFileData("Demo text content") },
                { XFS.Path(@"c:\a\b\c.txt"), new MockFileData("Demo text content") },
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));

            // Act
            var result = fileInfo.Exists;

            // Assert
            Assert.IsTrue(result);
        }
        public void MockFileInfo_Length_ShouldReturnLengthOfFileInMemoryFileSystem()
        {
            // Arrange
            const string   FILE_CONTENT = "Demo text content";
            MockFileSystem fileSystem   = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), new MockFileData(FILE_CONTENT) },
                { XFS.Path(@"c:\a\b\c.txt"), new MockFileData(FILE_CONTENT) },
            });
            MockFileInfo fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));

            // Act
            long result = fileInfo.Length;

            // Assert
            Assert.Equal(FILE_CONTENT.Length, result);
        }
        public void MockFileInfo_LastAccessTimeUtc_ShouldReturnLastAccessTimeUtcOfFileInMemoryFileSystem()
        {
            // Arrange
            var lastAccessTime = DateTime.Now.AddHours(-4);
            var fileData = new MockFileData("Demo text content") { LastAccessTime = lastAccessTime };
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { @"c:\a.txt", fileData }
            });
            var fileInfo = new MockFileInfo(fileSystem, @"c:\a.txt");

            // Act
            var result = fileInfo.LastAccessTimeUtc;

            // Assert
            Assert.AreEqual(lastAccessTime.ToUniversalTime(), result);
        }
        public void MockFileInfo_Length_ShouldReturnLengthOfFileInMemoryFileSystem()
        {
            // Arrange
            const string fileContent = "Demo text content";
            var          fileSystem  = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), new MockFileData(fileContent) },
                { XFS.Path(@"c:\a\b\c.txt"), new MockFileData(fileContent) },
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));

            // Act
            var result = fileInfo.Length;

            // Assert
            Assert.Equal(fileContent.Length, result);
        }
        public void MockFileInfo_CreationTimeUtc_ShouldReturnCreationTimeUtcOfFileInMemoryFileSystem()
        {
            var creationTime = DateTime.Now.AddHours(-4);
            var fileData     = new MockFileData("Demo text content")
            {
                CreationTime = creationTime
            };
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));

            var result = fileInfo.CreationTimeUtc;

            Assert.AreEqual(creationTime.ToUniversalTime(), result);
        }
        public void MockFileInfo_Length_ShouldThrowFileNotFoundExceptionIfFileDoesNotExistInMemoryFileSystem()
        {
            // Arrange
            const string fileContent = "Demo text content";
            var          fileSystem  = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), new MockFileData(fileContent) },
                { XFS.Path(@"c:\a\b\c.txt"), new MockFileData(fileContent) },
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\foo.txt"));

// ReSharper disable ReturnValueOfPureMethodIsNotUsed
            var ex = Assert.Throws <FileNotFoundException>(() => fileInfo.Length.ToString(CultureInfo.InvariantCulture));

// ReSharper restore ReturnValueOfPureMethodIsNotUsed
            Assert.Equal(XFS.Path(@"c:\foo.txt"), ex.FileName);
        }
        public void MockFileInfo_Length_ShouldReturnLengthOfFileInMemoryFileSystem()
        {
            // Arrange
            const string fileContent = "Demo text content";
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { @"c:\a.txt", new MockFileData(fileContent) },
                { @"c:\a\b\c.txt", new MockFileData(fileContent) },
            });
            var fileInfo = new MockFileInfo(fileSystem, @"c:\a.txt");

            // Act
            var result = fileInfo.Length;

            // Assert
            Assert.AreEqual(fileContent.Length, result);
        }
        public void MockFileInfo_IsReadOnly_ShouldSetReadOnlyAttributeOfFileInMemoryFileSystem()
        {
            // Arrange
            MockFileData   fileData   = new MockFileData("Demo text content");
            MockFileSystem fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            MockFileInfo fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"))
            {
                IsReadOnly = true
            };

            // Act

            // Assert
            Assert.Equal(FileAttributes.ReadOnly, fileData.Attributes & FileAttributes.ReadOnly);
        }
Esempio n. 13
0
        public void GetFullPath_valid_path(string basePath, string fileName, string expectedValue)
        {
            var combined = new StAbWrapper().Path.Combine(basePath, fileName);

            _diskManager.Path.Combine(basePath, fileName).Returns(combined);

            var info = new MockFileInfo {
                FullName = combined
            };

            _diskManager.NewFileInfo(combined).Returns(info);

            var result = DWPSUtils.GetFullPath(basePath, fileName);

            Assert.AreEqual(expectedValue, result);
            _diskManager.Path.Received(1).Combine(basePath, fileName);
            _diskManager.Received(1).NewFileInfo(combined);
        }
        public void OpenText_MockFileDataopulated_ReturnsData()
        {
            //Arrange
            var fileData   = new MockFileData("Demo text content");
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { @"z:\a.txt", fileData }
            });

            var fileInfo = new MockFileInfo(fileSystem, @"z:\a.txt");

            //Act
            var reader = fileInfo.OpenText();
            var result = reader.ReadToEnd();

            //Assert
            Assert.AreEqual("Demo text content", result);
        }
Esempio n. 15
0
        public void MockFileInfo_CreationTime_ShouldSetCreationTimeOfFileInMemoryFileSystem()
        {
            var creationTime = DateTime.Now.AddHours(-4);
            var fileData     = new MockFileData("Demo text content")
            {
                CreationTime = creationTime
            };
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));
            var newTime  = DateTime.Now;

            fileInfo.CreationTime = newTime;

            Assert.AreEqual(newTime, fileInfo.CreationTime);
        }
        public void MockFileInfo_IsReadOnly_ShouldSetNotReadOnlyAttributeOfFileInMemoryFileSystem()
        {
            // Arrange
            var fileData = new MockFileData("Demo text content")
            {
                Attributes = FileAttributes.ReadOnly
            };
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));

            // Act
            fileInfo.IsReadOnly = false;

            // Assert
            Assert.AreNotEqual(FileAttributes.ReadOnly, fileData.Attributes & FileAttributes.ReadOnly);
        }
        public void MockFileInfo_AppendText_ShouldCreateFileIfMissing()
        {
            var fileSystem = new MockFileSystem();
            var targetFile = XFS.Path(@"c:\a.txt");
            var fileInfo   = new MockFileInfo(fileSystem, targetFile);

            using (var file = fileInfo.AppendText())
                file.WriteLine("This should be the contents");

            string newcontents;

            using (var newfile = fileInfo.OpenText())
            {
                newcontents = newfile.ReadToEnd();
            }

            Assert.That(fileSystem.File.Exists(targetFile), Is.True);
            Assert.AreEqual($"This should be the contents{Environment.NewLine}", newcontents);
        }
Esempio n. 18
0
        public void MockFileInfo_LastWriteTimeUtc_ShouldSetLastWriteTimeUtcOfFileInMemoryFileSystem()
        {
            var lastWriteTime = DateTime.Now.AddHours(-4);
            var fileData      = new MockFileData("Demo text content")
            {
                LastWriteTime = lastWriteTime
            };
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));

            var newUtcTime = DateTime.UtcNow;

            fileInfo.LastWriteTime = newUtcTime;

            Assert.AreEqual(newUtcTime, fileInfo.LastWriteTime);
        }
        public void MockFileInfo_LastWriteTimeUtc_ShouldReturnLastWriteTimeUtcOfFileInMemoryFileSystem()
        {
            // Arrange
            var lastWriteTime = DateTime.Now.AddHours(-4);
            var fileData      = new MockFileData("Demo text content")
            {
                LastWriteTime = lastWriteTime
            };
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));

            // Act
            var result = fileInfo.LastWriteTimeUtc;

            // Assert
            Assert.AreEqual(lastWriteTime.ToUniversalTime(), result);
        }
        public void MockFileInfo_CreationTime_ShouldReturnCreationTimeOfFileInMemoryFileSystem()
        {
            // Arrange
            var creationTime = DateTime.Now.AddHours(-4);
            var fileData     = new MockFileData("Demo text content")
            {
                CreationTime = creationTime
            };
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));

            // Act
            var result = fileInfo.CreationTime;

            // Assert
            Assert.Equal(creationTime, result);
        }
Esempio n. 21
0
        public async System.Threading.Tasks.Task SummaryTest(string rawData, string expected)
        {
            var data       = Environment.NewLine + Environment.NewLine + rawData;
            var parserMock = new Mock <IFormatParser>();

            parserMock.Setup(parser => parser.ParseTag(It.IsAny <string>())).Returns(Enumerable.Empty <string>);
            parserMock.Setup(parser => parser.ParseTitle(It.IsAny <string>())).Returns(string.Empty);
            IFormatter formatter = new Formatter(Path.Combine(AppPathInfo.OutputPath, AppPathInfo.ContentPath), parserMock.Object);

            formatter.EnableSummary();

            var          mockFileSystem = new MockFileSystem();
            const string anyFile        = "asdf.md";
            var          info           = new MockFileInfo(mockFileSystem, anyFile);

            mockFileSystem.AddFile(anyFile, new MockFileData(Environment.NewLine + Environment.NewLine + rawData));
            formatter.SummaryLength = 7;
            var summary = (await formatter.GetBlogEntryAsync(info).ConfigureAwait(false)).Summary;

            Assert.Equal(expected, summary);
        }
Esempio n. 22
0
        public void MockFileInfo_AppendText_ShouldAddTextToFileInMemoryFileSystem()
        {
            var fileData   = new MockFileData("Demo text content");
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));

            using (var file = fileInfo.AppendText())
                file.WriteLine("This should be at the end");

            string newcontents;

            using (var newfile = fileInfo.OpenText())
            {
                newcontents = newfile.ReadToEnd();
            }

            Assert.AreEqual($"Demo text contentThis should be at the end{Environment.NewLine}", newcontents);
        }
    public void Rename_NormalFile()
    {
        var          mockFileSystem  = CreateMockFileSystem();
        var          mockFile        = new MockFileInfo(mockFileSystem, filePathA);
        const string renamedFileName = "newFileName.txt";
        string       renamedFilePath = Path.Combine(targetDirPath, renamedFileName);

        mockFile.Rename(renamedFilePath);
        mockFile.Refresh();

        mockFile.FullName
        .Should().Be(renamedFilePath);

        mockFile.Name
        .Should().Be(renamedFileName);

        mockFileSystem.AllPaths
        .Should().NotContain(filePathA);
        mockFileSystem.AllPaths
        .Should().Contain(renamedFilePath);
    }
    public void Rename_File_OnlyCase()
    {
        var          mockFileSystem  = CreateMockFileSystem();
        var          mockFile        = new MockFileInfo(mockFileSystem, filePathA);
        const string renamedFileName = "a.txt";
        string       renamedFilePath = Path.Combine(targetDirPath, renamedFileName);

        mockFile.Rename(renamedFilePath);
        mockFile.Refresh();

        mockFile.FullName
        .Should().Be(renamedFilePath);

        mockFile.Name
        .Should().Be(renamedFileName);

        //MockFileSystemのバグ?変更されない
        //mockFileSystem.AllPaths
        //    .Should().NotContain(filePathA);
        //mockFileSystem.AllPaths
        //    .Should().Contain(renamedFilePath);
    }
        public void MockFileInfo_AppendText_ShouldAddTextToFileInMemoryFileSystem()
        {
            // Arrange
            var fileData   = new MockFileData("Demo text content");
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));

            // Act
            using (var file = fileInfo.AppendText())
                file.WriteLine("This should be at the end");

            string newcontents;

            using (var newfile = fileInfo.OpenText())
                newcontents = newfile.ReadToEnd();

            // Assert
            Assert.Equal("Demo text contentThis should be at the end\r\n", newcontents);
        }
        public void MockFileInfo_LastAccessTimeUtc_ShouldSetCreationTimeUtcOfFileInMemoryFileSystem()
        {
            // Arrange
            var lastAccessTime = DateTime.Now.AddHours(-4);
            var fileData       = new MockFileData("Demo text content")
            {
                LastAccessTime = lastAccessTime
            };
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));

            // Act
            var newUtcTime = DateTime.UtcNow;

            fileInfo.LastAccessTimeUtc = newUtcTime;

            // Assert
            Assert.Equal(newUtcTime, fileInfo.LastAccessTimeUtc);
        }
        public void MockFileInfo_CreationTime_ShouldSetCreationTimeOfFileInMemoryFileSystem()
        {
            // Arrange
            DateTime     creationTime = DateTime.Now.AddHours(-4);
            MockFileData fileData     = new MockFileData("Demo text content")
            {
                CreationTime = creationTime
            };
            MockFileSystem fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            MockFileInfo fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));

            // Act
            DateTime newTime = DateTime.Now;

            fileInfo.CreationTime = newTime;

            // Assert
            Assert.Equal(newTime, fileInfo.CreationTime);
        }
        public void MockFileInfo_Encrypt_ShouldReturnXorOfFileInMemoryFileSystem()
        {
            // Arrange
            var fileData   = new MockFileData("Demo text content");
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));

            // Act
            fileInfo.Encrypt();

            string newcontents;

            using (var newfile = fileInfo.OpenText())
            {
                newcontents = newfile.ReadToEnd();
            }

            // Assert
            Assert.AreNotEqual("Demo text content", newcontents);
        }
        public void MockFileInfo_OpenWrite_ShouldAddDataToFileInMemoryFileSystem()
        {
            // Arrange
            var fileData   = new MockFileData("Demo text content");
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            var fileInfo   = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));
            var bytesToAdd = new byte[] { 65, 66, 67, 68, 69 };

            // Act
            using (var file = fileInfo.OpenWrite())
                file.Write(bytesToAdd, 0, bytesToAdd.Length);

            string newcontents;

            using (var newfile = fileInfo.OpenText())
                newcontents = newfile.ReadToEnd();

            // Assert
            Assert.AreEqual("ABCDEtext content", newcontents);
        }
        public void CreateText_DataSentIn_ShouldWriteToFile()
        {
            //Arrange
            var fileData   = new MockFileData("");
            var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { @"z:\a.txt", fileData }
            });

            var fileInfo = new MockFileInfo(fileSystem, @"z:\a.txt");

            //Act
            var writer = fileInfo.CreateText();

            writer.WriteLine("test");
            writer.Close();

            var reader = fileInfo.OpenText();
            var result = reader.ReadToEnd();

            //Assert
            Assert.AreEqual("test", result);
        }
        public void TrimToDefaultLength()
        {
            // Arrange
            var    creationTime = DateTime.Now.AddHours(-4);
            string myFileName   = "1c4b311d47205c46951385c440c80bf12008ed1459b5d0d2b2bd1ec18a102d4e";
            string myPath       = Path.Combine("C:\\Users\\PGullas\\Pictures\\downloaded lock screens\\download-test", myFileName);

            byte[] fileContentsBase64 = Encoding.ASCII.GetBytes("iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAYAAACp8Z5+AAAAE0lEQVR42mP8z8BQz4AEGEkXAADyrgX9UgHC3gAAAABJRU5ErkJggg==");

            var fileData = new MockFileData(fileContentsBase64)
            {
                CreationTime = creationTime
            };
            var fs = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { myPath, fileData }
            });

            // FileInfoWrapper fileInfoWrap = new FileInfoWrapper()

            FileInfoBase fi = fs.FileInfo.FromFileName(myPath);

            var myFileInfo = new MockFileInfo(fs, myPath);

            // SystemWrapper.IO.FileInfoWrap fileInfoWrap = new SystemWrapper.IO.FileInfoWrap(myPath);
            LockScreenImageToLog ls = new LockScreenImageToLog(fi, fs);
            string expectedName     = "a102d4e";



            // act
            string nameToTest = ls.GetFilenameTrimmedDownToLast();

            // assert
            Assert.AreEqual(expectedName, nameToTest);
        }
        public void MockFileInfo_IsReadOnly_ShouldSetNotReadOnlyAttributeOfFileInMemoryFileSystem()
        {
            // Arrange
            var fileData = new MockFileData("Demo text content") {Attributes = FileAttributes.ReadOnly};
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));

            // Act
            fileInfo.IsReadOnly = false;

            // Assert
            Assert.AreNotEqual(FileAttributes.ReadOnly, fileData.Attributes & FileAttributes.ReadOnly);
        }
        public void MockFileInfo_AppendText_ShouldAddTextToFileInMemoryFileSystem()
        {
            // Arrange
            var fileData = new MockFileData("Demo text content");
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));

            // Act
            using (var file = fileInfo.AppendText())
                file.WriteLine("This should be at the end");

            string newcontents;
            using (var newfile = fileInfo.OpenText())
                newcontents = newfile.ReadToEnd();

            // Assert
            Assert.AreEqual("Demo text contentThis should be at the end\r\n", newcontents);
        }
        public void CreateText_DataSentIn_ShouldWriteToFile()
        {
            //Arrange
            var fileData = new MockFileData("");
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { @"z:\a.txt", fileData }
            });

            var fileInfo = new MockFileInfo(fileSystem, @"z:\a.txt");

            //Act
            var writer = fileInfo.CreateText();
            writer.WriteLine("test");
            writer.Close();

            var reader = fileInfo.OpenText();
            var result = reader.ReadToEnd();

            //Assert
            Assert.AreEqual("test",result);
        }
        public void MockFileInfo_GetDirectory_ShouldReturnDirectoryInfoWithCorrectPath()
        {
            // Arrange
            var fileInfo = new MockFileInfo(new MockFileSystem(), @"c:\temp\level1\level2\file.txt");

            // Act
            var result = fileInfo.Directory;

            Assert.AreEqual(@"c:\temp\level1\level2\", result.FullName);
        }
        public void MockFileInfo_GetDirectoryName_ShouldReturnCompleteDirectoryPath()
        {
            // Arrange
            var fileInfo = new MockFileInfo(new MockFileSystem(), @"c:\temp\level1\level2\file.txt");

            // Act
            var result = fileInfo.DirectoryName;

            Assert.AreEqual(@"c:\temp\level1\level2", result);
        }
        public void MockFileInfo_GetExtensionWithoutExtension_ShouldReturnEmptyString()
        {
            // Arrange
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>());
            var fileInfo = new MockFileInfo(fileSystem, @"c:\a");

            // Act
            var result = fileInfo.Extension;

            // Assert
            Assert.AreEqual(string.Empty, result);
        }
        public void MockFileInfo_LastWriteTimeUtc_ShouldSetLastWriteTimeUtcOfFileInMemoryFileSystem()
        {
            // Arrange
            var lastWriteTime = DateTime.Now.AddHours(-4);
            var fileData = new MockFileData("Demo text content") { LastWriteTime = lastWriteTime };
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));

            // Act
            var newUtcTime = DateTime.UtcNow;
            fileInfo.LastWriteTime = newUtcTime;

            // Assert
            Assert.AreEqual(newUtcTime, fileInfo.LastWriteTime);
        }
Esempio n. 39
0
 public FileInfoCopySpy(IMockFileDataAccessor fileSystem, string path)
 {
     _fileInfo = new MockFileInfo(fileSystem, path);
 }
        public void MockFileInfo_GetExtension_ShouldReturnExtension()
        {
            // Arrange
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>());
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));

            // Act
            var result = fileInfo.Extension;

            // Assert
            Assert.AreEqual(".txt", result);
        }
        public void MockFileInfo_CreationTime_ShouldSetCreationTimeOfFileInMemoryFileSystem()
        {
            // Arrange
            var creationTime = DateTime.Now.AddHours(-4);
            var fileData = new MockFileData("Demo text content") { CreationTime = creationTime };
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));

            // Act
            var newTime = DateTime.Now;
            fileInfo.CreationTime = newTime;

            // Assert
            Assert.AreEqual(newTime, fileInfo.CreationTime);
        }
        public void MockFileInfo_Decrypt_ShouldReturnCorrectContentsFileInMemoryFileSystem()
        {
            // Arrange
            var fileData = new MockFileData("Demo text content");
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));
            fileInfo.Encrypt();

            // Act
            fileInfo.Decrypt();

            string newcontents;
            using (var newfile = fileInfo.OpenText())
            {
                newcontents = newfile.ReadToEnd();
            }

            // Assert
            Assert.AreEqual("Demo text content", newcontents);
        }
        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);*/
        }
        public void MockFileInfo_OpenWrite_ShouldAddDataToFileInMemoryFileSystem()
        {
            // Arrange
            var fileData = new MockFileData("Demo text content");
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));
            var bytesToAdd = new byte[] {65, 66, 67, 68, 69};

            // Act
            using (var file = fileInfo.OpenWrite())
                file.Write(bytesToAdd, 0, bytesToAdd.Length);

            string newcontents;
            using (var newfile = fileInfo.OpenText())
                newcontents = newfile.ReadToEnd();

            // Assert
            Assert.AreEqual("ABCDEtext content", newcontents);
        }
        public void MockFileInfo_CreationTimeUtc_ShouldReturnCreationTimeUtcOfFileInMemoryFileSystem()
        {
            // Arrange
            var creationTime = DateTime.Now.AddHours(-4);
            var fileData = new MockFileData("Demo text content") { CreationTime = creationTime };
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { XFS.Path(@"c:\a.txt"), fileData }
            });
            var fileInfo = new MockFileInfo(fileSystem, XFS.Path(@"c:\a.txt"));

            // Act
            var result = fileInfo.CreationTimeUtc;

            // Assert
            Assert.AreEqual(creationTime.ToUniversalTime(), result);
        }
        public void OpenText_MockFileDataopulated_ReturnsData()
        {
            //Arrange
            var fileData = new MockFileData("Demo text content");
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { @"z:\a.txt", fileData }
            });

            var fileInfo = new MockFileInfo(fileSystem, @"z:\a.txt");

            //Act
            var reader = fileInfo.OpenText();
            var result = reader.ReadToEnd();

            //Assert
            Assert.AreEqual("Demo text content", result);
        }