public void ReadTest() { XmlFileReader xmlReader = new XmlFileReader("XMLFile1.xml"); string content = xmlReader.Read(); Assert.Equals(content, @"<tui><core><io>FileReader library</io></core></tui>"); }
public void A_User_Should_be_Able_to_Read_A_XmlFile(string fileName) { var xmlFileReader = new XmlFileReader(filePath, fileName); string contentFile = xmlFileReader.Read(); Assert.Equal("<note><to>Tove</to><from>Jani</from></note>", contentFile); }
public void A_User_Should_be_Able_to_Read_An_Encrypted_XmlFile_InjectingService() { string fileName = "EncryptedContentXML.xml"; //Mock DecryptService Service var mockDecryptService = new Mock <IDecryptDataService>(); mockDecryptService .Setup(mock => mock.DecryptData(It.IsAny <string>())) .Returns((string param) => { StringBuilder stringBuilder = new StringBuilder(param); char[] array = stringBuilder.ToString().ToCharArray(); Array.Reverse(array); return(new string(array)); }); var xmlFileReader = new XmlFileReader(filePath, fileName, mockDecryptService.Object); string contentFile = xmlFileReader.Read(); Assert.Equal("<note><to>Tove</to><from>Jani</from></note>", contentFile); }
public void Test_ReadXml_WriteCsv_Kunden() { using (var testPipeline = new Pipeline()) { var reader = new XmlFileReader() { File = this.testDataPath + @"kunden.xml", RowXPath = "/adre/kunde" }; reader.Formatter = new XPathToDataTableFormatter(); testPipeline.Commands.Add(reader); var writer = new FlatFileWriter() { File = this.resultPath + @"kunden.csv" }; writer.Formatter = new DataTableToCsvFormatter(); reader.AddChild(writer); testPipeline.ExecutePipeline(); } // check var targetlineCount = File.ReadLines(this.resultPath + @"kunden.csv").Count(); Assert.AreEqual(3, targetlineCount); }
public HtmlFileWriterTest() { _reader = new ConfigurationReader(); IFileSystemHelper fsh = (IFileSystemHelper)(new Mock <FileSystemHelper>().Object); _xfr = new XmlFileReader(_reader.GetXmlFilesDirectory(), _reader.GetXmlFilesProcessedDirectory(), fsh); _hfw = new HtmlFileWriter(_reader.GetHtmlFilesDirectory(), _reader.GetResourcesDirectory(), fsh); }
public async Task Read_UnexistingFile_ShouldThrowException() { // Arrange var path = @"C:\Nowhere"; var sut = new XmlFileReader(path, new FileValidator()); // Act/Assert await Assert.ThrowsAsync <Exception>(() => sut.ReadAsync()); }
public void A_User_Should_be_Able_to_Read_An_Encrypted_XmlFile_ExtensionMethod() { string fileName = "EncryptedContentXML.xml"; var xmlFileReader = new XmlFileReader(filePath, fileName); string contentFile = xmlFileReader.ReadAndDecrypt(); Assert.Equal("<note><to>Tove</to><from>Jani</from></note>", contentFile); }
public void ReturnNull_WhenFileDoesntExist() { var reader = new XmlFileReader(); var path = string.Empty; string content = reader.ReadContent(path); Assert.Null(content); }
public void Error_WrongConstructor_Read_An_Encrypted_XmlFile() { string fileName = "EncryptedContentXML.xml"; var xmlFileReader = new XmlFileReader(filePath, fileName); string contentFile = xmlFileReader.Read(); Assert.NotEqual("<note><to>Tove</to><from>Jani</from></note>", contentFile); }
public void ReadContent_WhenFileExists() { var reader = new XmlFileReader(); var path = "TestFiles/XmlFile.xml"; string content = reader.ReadContent(path); Assert.NotEmpty(content); }
public async Task Read_InvalidXmlFile_ShouldThrowException() { // Arrange var dir = TestHelper.GetFilesDirectory(); var path = Path.Combine(dir, "javascriptfile.js"); var sut = new XmlFileReader(path, new FileValidator()); // Act/Assert await Assert.ThrowsAsync <Exception>(() => sut.ReadAsync()); }
public void Load_ProcessXml() { var cb = new ContainerBuilder(); var module = new XmlFileReader("Files/RefereeXml.config"); cb.RegisterModule(module); var container = cb.Build(); container.AssertRegisteredNamed <object>("c", "The component from the configuration file was not registered."); }
/// <summary> /// DI framework simulator. Creates abstractions implementation starting from aggregation root. Everything remains at single place /// </summary> /// <returns></returns> public static TradesAggregationService Create() { var xmlFileReader = new XmlFileReader(); return(new TradesAggregationService( new SecuritiesProvider(xmlFileReader, new SecuritiesMapper()), new FilesProcessor(new TradesFileScanner(), xmlFileReader, new TradesFileProcessor(), new TradesMapper()), new ReportTxtFileWriter() )); }
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 AUserShouldBeAbleToReadAnEncryptedXMLFile() { IEncryptor encryptor = new ReverseEncryptor(); IFileReader fileReader = new XmlFileReader(encryptor); var filename = $@"{_currentDirectory}\files\xmlFile.xml"; var actual = fileReader.Read(filename); Assert.AreEqual("\n\r>txet/<!dlrow olleH>txet<\n\r>?\"0.1\"=noisrev lmx?<", actual); }
public static void Handler() { var listParcel = XmlFileReader.LoadXml(); var department = new Department(); foreach (var item in listParcel) { HandleParcel(department, item); } }
public void AUserShouldBeAbleToReadAXMLFile() { IFileReader fileReader = new XmlFileReader(); var filename = $@"{_currentDirectory}\files\xmlFile.xml"; var actual = XElement.Parse(fileReader.Read(filename)); var expected = XElement.Parse("<?xml version=\"1.0\"?><text>Hello world!</text>"); Assert.AreEqual(expected.ToString(), actual.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 AAdminShouldBeAbleToReadAllXMLFilesInRoleBasedSecurityContext() { IFileReader fileReader = new XmlFileReader(); Authorization adminAuthorization = new AdminAuthorization(fileReader); var filename = $@"{_currentDirectory}\files\admin.xml"; var actual = XElement.Parse(adminAuthorization.Read(filename)); var expected = XElement.Parse("<?xml version=\"1.0\"?><text>Hello admin!</text>"); Assert.AreEqual(expected.ToString(), actual.ToString()); }
public void Process() { XmlFileReader xfr = new XmlFileReader(_producerConsumer.GetConfigurationReader().GetXmlFilesDirectory(), _producerConsumer.GetConfigurationReader().GetXmlFilesProcessedDirectory(), _producerConsumer.FileSystemHelper);; int numberOfFiles = _producerConsumer.GetConfigurationReader().GetXmlFilesDirectory().GetFiles().Length; while (xfr.GetNextStackItem() != null) { IStackItem si = xfr.GetNextStackItem(); _producerConsumer.Queue.Enqueue(si); //_producerConsumer.lollypop.Set(); _producerConsumer.IsDoneReading = false; } _producerConsumer.IsDoneReading = true; }
public XmlFileReaderTest() { _reader = new ConfigurationReader(); IFileSystemHelper fsh = (IFileSystemHelper)(new Mock <FileSystemHelper>().Object); _xfr = new XmlFileReader(_reader.GetXmlFilesDirectory(), _reader.GetXmlFilesProcessedDirectory(), fsh); _numberOfFiles = _reader.GetXmlFilesDirectory().GetFiles().Length; _stackItems = new List <IStackItem>(); while (_xfr.GetNextStackItem() != null) { IStackItem si = _xfr.GetNextStackItem(); _stackItems.Add(si); } }
public async Task Read_ValidXmlFile_ShouldReturnFileContent() { // Arrange var dir = TestHelper.GetFilesDirectory(); var path = Path.Combine(dir, "regularxmlfile.xml"); var sut = new XmlFileReader(path, new FileValidator()); const string expectedFileContent = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n<customers>\r\n\t<customer>\r\n\t\t<name>Customer 1</name>\r\n\t\t<Address>\r\n\t\t\t<Street>Hello street</Street>\r\n\t\t\t<HouseNr>87</HouseNr>\r\n\t\t\t<Box>4b</Box>\r\n\t\t\t<ZipCode>1000</ZipCode>\r\n\t\t\t<City>Brussels</City>\r\n\t\t</Address>\r\n\t</customer>\r\n\t<customer>\r\n\t\t<name>Customer 2</name>\r\n\t\t<Address>\r\n\t\t\t<Street>Morning street</Street>\r\n\t\t\t<HouseNr>5</HouseNr>\r\n\t\t\t<Box>10</Box>\r\n\t\t\t<ZipCode>9900</ZipCode>\r\n\t\t\t<City>Gent</City>\r\n\t\t</Address>\r\n\t</customer>\r\n</customers>"; // Act var fileContent = await sut.ReadAsync(); // Assert Assert.Equal(expectedFileContent, fileContent); }
public SingleSnapshotModel(String path) { this.SnapshotPath = path; this.Included = true; String[] splitedPath = path.Split(new string[] { Path.DirectorySeparatorChar.ToString() }, StringSplitOptions.None); int pathCount = splitedPath.Count(); this.EntityName = splitedPath[pathCount - 2]; this.SnapshotId = splitedPath[pathCount - 3]; this.EntityNumber = this.SnapshotId.Split('_').First(); this.ErrorNumber = this.SnapshotId.Split('_').Last(); XmlFileReader xmlFileReader = new XmlFileReader(path); this.ErrorMessage = xmlFileReader.GetErrorNodeText(); }
public async Task Read_SecuredXmlFileAsReceptionist_ShouldReturnUnauthorizedMsg() { // Arrange var dir = TestHelper.GetFilesDirectory(); var path = Path.Combine(dir, "regularxmlfile.xml"); var xmlFileReader = new XmlFileReader(path, new FileValidator()); var sut = new SecuredFileReader(xmlFileReader, new ReadAuthorization(UserRole.Receptionist)); const string expectedContent = "Unauthorized request."; // Act var fileContent = await sut.ReadAsync(); // Assert Assert.Equal(expectedContent, fileContent); }
public async Task <ActionResult <UploadResultDto> > UploadAsync([FromForm] IFormFile file) { if (file == null || file.Length == 0) { throw new ArgumentException("The specified file is null or empty.", nameof(file)); } if (!_allowedFileExtensions.Contains(Path.GetExtension(file.FileName))) { throw new ArgumentException("The specified file has invalid extension.", nameof(file)); } byte[] bytes; await using (var memoryStream = new MemoryStream()) { await file.CopyToAsync(memoryStream); bytes = memoryStream.ToArray(); } IFileReader fileReader; if (Path.GetExtension(file.FileName) == ".csv") { fileReader = new CsvFileReader(); } else { fileReader = new XmlFileReader(); } var parseResult = await _uploadService.UploadAsync <ParseResult>(bytes, fileReader); var result = new UploadResultDto(); if (parseResult.IsSucceeded) { result.Info.Add($"Uploaded {parseResult.TransactionData.Count()} Transactions"); } else { result.Errors = parseResult.Errors.ToList(); } result.Warnings = parseResult.Warnings.ToList(); return(Ok(result)); }
public void AUserShouldBeAbleToReadLimitedXMLFilesInRoleBasedSecurityContext() { IFileReader fileReader = new XmlFileReader(); Authorization userAuthorization = new UserAuthorization(fileReader); var adminFilename = $@"{_currentDirectory}\files\admin.xml"; var filename = $@"{_currentDirectory}\files\xmlFile.xml"; var actualAdmin = userAuthorization.Read(adminFilename); var actual = XElement.Parse(userAuthorization.Read(filename)); var expected = XElement.Parse("<?xml version=\"1.0\"?><text>Hello world!</text>"); Assert.AreEqual(string.Empty, actualAdmin); Assert.AreEqual(expected.ToString(), actual.ToString()); }
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 AUserShouldBeAbleToSwitchEncryptionXmlFile() { IEncryptor encryptor = new ReverseEncryptor(); var fileReader = new XmlFileReader(encryptor); var filename = $@"{_currentDirectory}\files\xmlFile.xml"; var actualReversedXml = fileReader.Read(filename); fileReader.SetEncryptor(VoidEncryptor.Instance); var actualXml = fileReader.Read(filename); Assert.AreEqual("\n\r>txet/<!dlrow olleH>txet<\n\r>?\"0.1\"=noisrev lmx?<", actualReversedXml); Assert.AreEqual("<?xml version=\"1.0\"?>\r\n<text>Hello world!</text>\r\n", actualXml); }
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 DataContext() { var fileName = ConfigurationManager.AppSettings[GROUP]; Groups = (List <Group>)XmlFileReader.Deserialize(fileName, typeof(List <Group>)); fileName = ConfigurationManager.AppSettings[STUDENT]; Students = (List <Student>)XmlFileReader.Deserialize(fileName, typeof(List <Student>)); fileName = ConfigurationManager.AppSettings[ABSENT]; Absents = (List <Absent>)XmlFileReader.Deserialize(fileName, typeof(List <Absent>)); fileName = ConfigurationManager.AppSettings[SCHEDULE]; Schedules = (List <Schedule>)XmlFileReader.Deserialize(fileName, typeof(List <Schedule>)); fileName = ConfigurationManager.AppSettings[LESSON]; Lessons = (List <Lesson>)XmlFileReader.Deserialize(fileName, typeof(List <Lesson>)); }
private string GetlanguageBasedValueOfKey(string key, string languageCode, string pageName) { string RetVal; string LanguageFolderPath; string LanguageFile; XmlFileReader objxmlFilereader; RetVal = string.Empty; objxmlFilereader = null; try { LanguageFolderPath = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, Constants.FolderName.Language); LanguageFile = Path.Combine(LanguageFolderPath, languageCode) + "\\" + pageName; objxmlFilereader = new XmlFileReader(LanguageFile); if (objxmlFilereader != null) { RetVal = objxmlFilereader.GetXMLNodeAttributeValue(Constants.Map.MapLangXPath.Replace(Constants.Map.LangReplaceXPathString, key), Constants.Map.XMLValueAtributeName); } } catch (Exception ex) { Global.CreateExceptionString(ex, null); throw ex; } finally { } return RetVal; }
private LanguageStrings GetMapLanguageStrings(string LanguageFolderPath, string LangCode) { LanguageStrings RetVal = new LanguageStrings(); string MapSettingFile = string.Empty; string xmlNodePath = string.Empty; XmlFileReader objxmlFilereader = null; try { MapSettingFile = Path.Combine(LanguageFolderPath, LangCode) + "\\" + Constants.Map.MapLanguageFileName; objxmlFilereader = new XmlFileReader(MapSettingFile); if (objxmlFilereader != null) { RetVal.DisclaimerText = objxmlFilereader.GetXMLNodeAttributeValue(Constants.Map.MapLangXPath.Replace(Constants.Map.LangReplaceXPathString, "langMapDisclaimerText"), Constants.Map.XMLValueAtributeName); RetVal.MissingValue = objxmlFilereader.GetXMLNodeAttributeValue(Constants.Map.MapLangXPath.Replace(Constants.Map.LangReplaceXPathString, "langMissingValue"), Constants.Map.XMLValueAtributeName); RetVal.Map = objxmlFilereader.GetXMLNodeAttributeValue(Constants.Map.MapLangXPath.Replace(Constants.Map.LangReplaceXPathString, "langMap"), Constants.Map.XMLValueAtributeName); RetVal.Data = objxmlFilereader.GetXMLNodeAttributeValue(Constants.Map.MapLangXPath.Replace(Constants.Map.LangReplaceXPathString, "langData"), Constants.Map.XMLValueAtributeName); RetVal.Source = objxmlFilereader.GetXMLNodeAttributeValue(Constants.Map.MapLangXPath.Replace(Constants.Map.LangReplaceXPathString, "langSource"), Constants.Map.XMLValueAtributeName); RetVal.MostRecentData = objxmlFilereader.GetXMLNodeAttributeValue(Constants.Map.MapLangXPath.Replace(Constants.Map.LangReplaceXPathString, "langMostRecentData"), Constants.Map.XMLValueAtributeName); RetVal.Theme = objxmlFilereader.GetXMLNodeAttributeValue(Constants.Map.MapLangXPath.Replace(Constants.Map.LangReplaceXPathString, "langTheme"), Constants.Map.XMLValueAtributeName); } if (string.IsNullOrEmpty(RetVal.MostRecentData)) RetVal.MostRecentData = new LanguageStrings().MostRecentData; if (string.IsNullOrEmpty(RetVal.Theme)) RetVal.Theme = new LanguageStrings().Theme; } catch (Exception ex) { RetVal = null; Global.CreateExceptionString(ex, null); } return RetVal; }