Example #1
0
        public void FileThatHasBeenReadShouldReturnSameValue()
        {
            var reader  = new JsonFileReader(_pathValidations, _fileSystem);
            var content = reader.ReadContent(_expFullNamePath);

            Assert.True(content.RootElement.GetProperty("foo").ValueEquals("bar"));
        }
Example #2
0
        public void IntegrationTest_WhenWeWantToReadFromTheFileSystem_ItShouldBeRead()
        {
            var fileSystem      = new FileSystem();
            var pathValidations = new PathValidations(new FileSystem());
            var fileReader      = new JsonFileReader(pathValidations, fileSystem);
            var content         = fileReader.ReadContent("exc7.json");

            Assert.NotNull(content);
            Assert.True(content.RootElement.GetProperty("foo").ValueEquals("bar"));
        }
Example #3
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 JsonFileReader(_pathValidations, mockSystem);

            var ex = Assert.Throws <Exception>(() => reader.ReadContent(@"c:\some\path\someFile.ext"));

            Assert.Equal(exceptionMessage, ex.Message);
        }
Example #4
0
        public void FalseEncryptedJSONFileShouldReturnNull()
        {
            string expectedDir  = @"c:\";
            string expectedPath = @"someFile.tst";

            string encryptedContent = @"{ ""rab"":""oof"" {";

            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 JsonFileReader(_pathValidations, fileSystem);
            var content = reader.ReadContent(Path(expectedDir, expectedPath), decryption);

            Assert.Null(content);
        }
Example #5
0
        public void EncryptedJSONFileShouldBeAbleToBeRead()
        {
            string expectedDir  = @"c:\";
            string expectedPath = @"someFile.tst";

            string encryptedContent = @"} ""rab"":""oof"" {";

            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 JsonFileReader(_pathValidations, fileSystem);
            var content = reader.ReadContent(Path(expectedDir, expectedPath), decryption);

            Assert.NotNull(content);
            Assert.True(content.RootElement.GetProperty("foo").ValueEquals("bar"));
        }