public void ReadContent_WhenFileExists() { var reader = new XmlFileReader(); var path = "TestFiles/XmlFile.xml"; string content = reader.ReadContent(path); Assert.NotEmpty(content); }
public void ReturnNull_WhenFileDoesntExist() { var reader = new XmlFileReader(); var path = string.Empty; string content = reader.ReadContent(path); Assert.Null(content); }
public void IntegrationTest_WhenWeWantToReadFromTheFileSystem_ItShouldBeRead() { var fileSystem = new FileSystem(); var pathValidations = new PathValidations(new FileSystem()); var fileReader = new XmlFileReader(pathValidations, fileSystem); var content = fileReader.ReadContent("exc2.xml"); Assert.NotNull(content); Assert.StartsWith(@"<raw>", content.ToString()); }
public void WhenPathValidationsThrowsException_CallerShouldGetTheException() { var mockSystem = new MockFileSystem(); var exceptionMessage = nameof(WhenPathValidationsThrowsException_CallerShouldGetTheException) + "throws"; _pathValidations.When(x => x.ThrowWhenInvalid(Arg.Any <string>())).Do((callInfo) => throw new Exception(exceptionMessage)); var reader = new XmlFileReader(_pathValidations, mockSystem); var ex = Assert.Throws <Exception>(() => reader.ReadContent(@"c:\some\path\someFile.ext")); Assert.Equal(exceptionMessage, ex.Message); }
public void FileWithInvalidXmlThatHasBeenReadShouldReturnNull() { string expectedDir = @"c:\"; string expectedPath = @"someFile.tst"; string expectedContent = "<xml></xml<"; System.Collections.Generic.IDictionary <string, MockFileData> fileDictionary = new Dictionary <string, MockFileData>(); fileDictionary.Add($"{expectedDir}{expectedPath}", new MockFileData(expectedContent, System.Text.Encoding.UTF8)); var fileSystem = new MockFileSystem(fileDictionary, expectedDir); var reader = new XmlFileReader(_pathValidations, fileSystem); var content = reader.ReadContent($"{expectedDir}{expectedPath}"); Assert.Null(content); }
public void FileThatHasBeenReadShouldReturnSameValue() { string expectedDir = @"c:\"; string expectedPath = @"someFile.tst"; string expectedContent = "<xml></xml>"; System.Collections.Generic.IDictionary <string, MockFileData> fileDictionary = new Dictionary <string, MockFileData>(); fileDictionary.Add($"{expectedDir}{expectedPath}", new MockFileData(expectedContent, System.Text.Encoding.UTF8)); var fileSystem = new MockFileSystem(fileDictionary, expectedDir); var reader = new XmlFileReader(_pathValidations, fileSystem); var content = reader.ReadContent($"{expectedDir}{expectedPath}"); Assert.True(XNode.DeepEquals(XDocument.Parse(expectedContent).Document, content)); }
public void FalseEncryptedXmlFileShouldReturnNull() { string expectedDir = @"c:\"; string expectedPath = @"someFile.tst"; string encryptedContent = "<lmx/<>lmx<"; string expectedDecryptedContent = "<xml></xml<"; System.Collections.Generic.IDictionary <string, MockFileData> fileDictionary = new Dictionary <string, MockFileData>(); fileDictionary.Add($"{expectedDir}{expectedPath}", new MockFileData(encryptedContent, System.Text.Encoding.UTF8)); var fileSystem = new MockFileSystem(fileDictionary, expectedDir); var decryption = new ReverseStringDecryption(); var reader = new XmlFileReader(_pathValidations, fileSystem); var content = reader.ReadContent($"{expectedDir}{expectedPath}", decryption); Assert.Null(content); }
public void EncryptedXmlFileShouldBeAbleToBeRead() { string expectedDir = @"c:\"; string expectedPath = @"someFile.tst"; string encryptedContent = ">lmx/<>lmx<"; string expectedDecryptedContent = "<xml></xml>"; System.Collections.Generic.IDictionary <string, MockFileData> fileDictionary = new Dictionary <string, MockFileData>(); fileDictionary.Add($"{expectedDir}{expectedPath}", new MockFileData(encryptedContent, System.Text.Encoding.UTF8)); var fileSystem = new MockFileSystem(fileDictionary, expectedDir); var decryption = new ReverseStringDecryption(); var reader = new XmlFileReader(_pathValidations, fileSystem); var content = reader.ReadContent(Path(expectedDir, expectedPath), decryption); Assert.True(XNode.DeepEquals(XDocument.Parse(expectedDecryptedContent).Document, content)); }