public void WhenWeSupplyASingleLineSampleText_ItShouldBeReturnedReversed() { var decryption = new ReverseStringDecryption(); var decrypt = decryption.Decrypt("abc"); Assert.Equal("cba", decrypt); }
public void WhenWeAskToReadContent_WithDecryption_RoleProviderShouldBeChecked() { 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 serviceCollection = new ServiceCollection(); serviceCollection.AddFileReading(); var mockedRbacService = Substitute.For <IRbacService>(); var decryption = new ReverseStringDecryption(); serviceCollection.Replace(ServiceDescriptor.Singleton <IRbacService>(mockedRbacService)); serviceCollection.Replace(ServiceDescriptor.Singleton <IFileSystem>(fileSystem)); var provider = serviceCollection.BuildServiceProvider(true); var reader = provider.GetService <IXmlReader>(); reader.ReadContent(Path(expectedDir, expectedPath), decryption); mockedRbacService.Received(1).ThrowWhenCantReadContent(Path(expectedDir, expectedPath)); //2 because of the TextReader decoration check and the Xml decoration check }
public void WhenWeSupplyANull_ResultShouldBeNull() { var decryption = new ReverseStringDecryption(); var decrypt = decryption.Decrypt(null); Assert.Null(decrypt); }
public void WhenWeSupplyAMultiLIneSampleText_ItShouldBeReturnedReversed() { var decryption = new ReverseStringDecryption(); var decrypt = decryption.Decrypt("abc" + System.Environment.NewLine + "123"); Assert.Equal("321" + System.Environment.NewLine + "cba", decrypt); }
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 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)); }
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")); }
public void WhenWeAskToReadContent_WithDecryption_RoleProviderShouldBeChecked() { var serviceCollection = new ServiceCollection(); serviceCollection.AddFileReading(); var mockedRbacService = Substitute.For <IRbacService>(); var decryption = new ReverseStringDecryption(); serviceCollection.Replace(ServiceDescriptor.Singleton <IRbacService>(mockedRbacService)); serviceCollection.Replace(ServiceDescriptor.Singleton <IFileSystem>(_fileSystem)); var provider = serviceCollection.BuildServiceProvider(true); var reader = provider.GetService <ITextReader>(); reader.ReadContent(_expFullNamePath, decryption); mockedRbacService.Received(1).ThrowWhenCantReadContent(_expFullNamePath); }