Example #1
0
        public void CreateRepository()
        {
            IStockRepository repository;

            repository = new FileStockRepository(repositoryDir);
            Assert.IsTrue(repositoryDir.Exists);
        }
Example #2
0
        public void FindStockFileName()
        {
            IFileRepository repository = new FileStockRepository(repositoryDir);

            Assert.AreEqual("stock123.txt", repository.StockFileName(123));
            hp.Id = 456;
            Assert.AreEqual("stock456.txt", repository.StockFileName(hp));
        }
Example #3
0
        public void CanSaveStockWritesToFile()
        {
            IFileRepository repository = new FileStockRepository(repositoryDir);

            repository.SaveStock(yhoo);
            Assert.IsFalse(yhoo.Id == 0);
            FileInfo fileYhoo = new FileInfo(repositoryDir + repository.StockFileName(yhoo));

            Assert.IsTrue(fileYhoo.Exists);
        }
Example #4
0
        public void FindNextId()
        {
            IStockRepository repository = new FileStockRepository(repositoryDir);
            long             id1        = repository.NextId();

            Assert.IsTrue(id1 != 0);
            long id2 = repository.NextId();

            Assert.IsTrue(id2 != 0);
            Assert.IsTrue(id2 != id1);
        }
Example #5
0
        public void CanClearRepository()
        {
            IStockRepository repository = new FileStockRepository(repositoryDir);

            repository.SaveStock(yhoo);
            repository.SaveStock(hp);
            repository.Clear();
            ICollection stocks;

            stocks = repository.FindAllStocks();
            Assert.AreEqual(0, stocks.Count);
        }
Example #6
0
        public void CanSaveAndLoad()
        {
            IStockRepository repository = new FileStockRepository(repositoryDir);

            repository.SaveStock(yhoo);
            long id = yhoo.Id;

            IStockRepository differentRepository = new FileStockRepository(repositoryDir);
            Stock            newYhoo             = differentRepository.LoadStock(id);

            Assert.AreEqual(yhoo, newYhoo);
        }
Example #7
0
        public void CanSaveAfterChange()
        {
            IStockRepository repository = new FileStockRepository(repositoryDir);

            repository.SaveStock(yhoo);
            yhoo.NumShares = 120;
            repository.SaveStock(yhoo);

            IStockRepository newRepository = new FileStockRepository(repositoryDir);
            Stock            loaded        = newRepository.LoadStock(yhoo.Id);

            Assert.AreEqual(120, loaded.NumShares);
        }