Exemplo n.º 1
0
        public Stock LoadStock(long id)
        {
            FileInfo fi  = new FileInfo(_repositoryDir + StockFileName((int)id));
            StockIO  sio = new StockIO();

            return(sio.ReadStock(fi));
        }
Exemplo n.º 2
0
        public void CanWriteStockYahoo()
        {
            StockIO      io = new StockIO();
            StringWriter sw = new StringWriter();

            io.WriteStock(sw, yhoo);
            Assert.AreEqual("YHOO" + NL + "57,2" + NL + "30" + NL, sw.ToString());
        }
Exemplo n.º 3
0
        public void CanWriteToWriterHp()
        {
            StockIO      io = new StockIO();
            StringWriter sw = new StringWriter();

            io.WriteStock(sw, hp);
            Assert.AreEqual("HP" + NL + "11,4" + NL + "10" + NL, sw.ToString());
        }
Exemplo n.º 4
0
        public void SaveStock(Stock stock)
        {
            stock.Id = this.NextId();
            FileInfo fi  = new FileInfo(_repositoryDir + StockFileName(stock));
            StockIO  sio = new StockIO();

            sio.WriteStock(fi, stock);
        }
Exemplo n.º 5
0
        public ICollection FindAllStocks()
        {
            List <Stock> stocks = new List <Stock>();
            StockIO      sio    = new StockIO();

            string[] fileEntries = Directory.GetFiles(_repositoryDir.Name);
            foreach (string fileName in fileEntries)
            {
                FileInfo fi = new FileInfo(_repositoryDir + Path.GetFileName(fileName));
                stocks.Add(sio.ReadStock(fi));
            }
            return(stocks);
        }
Exemplo n.º 6
0
        public void CanWriteToFile()
        {
            FileInfo output = new FileInfo("stockout.txt");

            try {
                StockIO io = new StockIO();
                io.WriteStock(output, hp);
                Assert.IsTrue(output.Exists);
                Stock loaded = io.ReadStock(output);
                Assert.AreEqual(hp, loaded);
            }
            finally {
                output.Delete();
            }
        }
Exemplo n.º 7
0
        public void CanReadStock()
        {
            StockIO io = new StockIO();

            String hpData   = "HP" + NL + "11,4" + NL + "10" + NL;
            String yhooData = "YHOO" + NL + "57,2" + NL + "30" + NL;

            StringReader data   = new StringReader(hpData);
            Stock        loaded = io.ReadStock(data);

            Assert.AreEqual(hp, loaded);

            data   = new StringReader(yhooData);
            loaded = io.ReadStock(data);
            Assert.AreEqual(yhoo, loaded);
        }