예제 #1
0
        public void ReadContent_WhenFileExists()
        {
            var reader = new XmlFileReader();
            var path   = "TestFiles/XmlFile.xml";

            string content = reader.ReadContent(path);

            Assert.NotEmpty(content);
        }
예제 #2
0
        public void ReturnNull_WhenFileDoesntExist()
        {
            var reader = new XmlFileReader();
            var path   = string.Empty;

            string content = reader.ReadContent(path);

            Assert.Null(content);
        }
예제 #3
0
        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());
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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));
        }
예제 #7
0
        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);
        }
예제 #8
0
        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));
        }