public void FileThatHasBeenReadShouldReturnSameValue() { var reader = new JsonFileReader(_pathValidations, _fileSystem); var content = reader.ReadContent(_expFullNamePath); Assert.True(content.RootElement.GetProperty("foo").ValueEquals("bar")); }
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")); }
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); }
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); }
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")); }