public void TestMapFindsContentSectionAndSkipFirstLine() { //given const string fileName = "FileName"; var xmlFile = new XmlStockFile { Values = new[] { new StockValue { Date = "2013-5-20", Open = "30.16", High = "30.39", Low = "30.02", Close = "30.17", Volume = "1478200" } } }; var mapper = new XmlStockFileMapper(); //when var result = mapper.Map(fileName, xmlFile); //then Assert.That(result.FileName, Is.EqualTo(fileName)); Assert.That(result.StockData.Count, Is.EqualTo(1)); Assert.That(result.StockData[0].Date, Is.EqualTo(xmlFile.Values[0].Date)); Assert.That(result.StockData[0].Open, Is.EqualTo(xmlFile.Values[0].Open)); Assert.That(result.StockData[0].High, Is.EqualTo(xmlFile.Values[0].High)); Assert.That(result.StockData[0].Low, Is.EqualTo(xmlFile.Values[0].Low)); Assert.That(result.StockData[0].Close, Is.EqualTo(xmlFile.Values[0].Close)); Assert.That(result.StockData[0].Volume, Is.EqualTo(xmlFile.Values[0].Volume)); }
public StockFile Map(string fileName, XmlStockFile file) { return(new StockFile { FileName = fileName, StockData = file.Values.Select(v => new StockData { Date = v.Date, Open = v.Open, High = v.High, Low = v.Low, Close = v.Close, Volume = v.Volume }).ToList() }); }
public async void TestReadFile() { //given const string filePath = "c:\\d\\d\\test.xml"; var xmlFile = new XmlStockFile(); var stockFile = new StockFile(); var fileHelper = Mock.Of <IXmlStockFileReaderHelper>(h => h.ReadXmlFile(filePath) == xmlFile); var mapper = Mock.Of <IXmlStockFileMapper>(m => m.Map("test", xmlFile) == stockFile); var reader = new XmlStockFileReader(mapper, fileHelper); //when var result = await reader.ReadFile(filePath); //then Assert.That(result, Is.SameAs(stockFile)); }
public void TestReadText() { //given const string testFilePath = "filePath"; var fileLines = new[] { "Content:", "<?xml version=\"1.0\" encoding=\"utf-8\" ?>", "<values>", "<value date=\"2013-5-20\" open=\"30.16\" high=\"30.39\" low=\"30.02\" close=\"30.17\" volume=\"1478200\" />", "</values>" }; var fileReader = Mock.Of <IFileReaderHelper>(r => r.ReadText(testFilePath) == fileLines); var helper = new XmlStockFileReaderHelper(fileReader); var expectedResult = new XmlStockFile { Values = new[] { new StockValue { Date = "2013-5-20", Open = "30.16", High = "30.39", Low = "30.02", Close = "30.17", Volume = "1478200" } } }; //when var result = helper.ReadXmlFile(testFilePath); //then Assert.That(result.Values.Count(), Is.EqualTo(1)); Assert.That(result.Values[0].Date, Is.EqualTo(expectedResult.Values[0].Date)); Assert.That(result.Values[0].Open, Is.EqualTo(expectedResult.Values[0].Open)); Assert.That(result.Values[0].High, Is.EqualTo(expectedResult.Values[0].High)); Assert.That(result.Values[0].Low, Is.EqualTo(expectedResult.Values[0].Low)); Assert.That(result.Values[0].Close, Is.EqualTo(expectedResult.Values[0].Close)); Assert.That(result.Values[0].Volume, Is.EqualTo(expectedResult.Values[0].Volume)); }