Exemplo n.º 1
0
        public void GetSpecificRecordFromCsvRepo()
        {
            var deserializer = new StocksDeserializer(new StockQuoteCsvClassMap());
            var allStocks    = new List <Company> {
                deserializer.Deserialize(Encoding.UTF8.GetString(Properties.Resources._11BIT)),
                deserializer.Deserialize(Encoding.UTF8.GetString(Properties.Resources.CDPROJEKT)),
                deserializer.Deserialize(Encoding.UTF8.GetString(Properties.Resources.MBANK))
            };

            var outputFile = new FileInfo(Path.ChangeExtension(nameof(GetSpecificRecordFromCsvRepo), "csv"));

            using (var unitOfWork = new StockCsvUnitOfWork(new StockCsvContext <Company>(outputFile)))
            {
                unitOfWork.Repository.AddRange(allStocks);

                var oneStock = unitOfWork.Repository.Entities.FirstOrDefault(x => x.Ticker == "MBANK");
                unitOfWork.Repository.Remove(oneStock);

                unitOfWork.Complete();
            }
        }
Exemplo n.º 2
0
        public void SavingToCsvRepoWorks()
        {
            var deserializer = new StocksDeserializer(new StockQuoteCsvClassMap());
            var allStocks    = new List <Company> {
                deserializer.Deserialize(Encoding.UTF8.GetString(Properties.Resources._11BIT)),
                deserializer.Deserialize(Encoding.UTF8.GetString(Properties.Resources.CDPROJEKT)),
                deserializer.Deserialize(Encoding.UTF8.GetString(Properties.Resources.MBANK))
            };

            var outputFile = new FileInfo(Path.ChangeExtension(nameof(SavingToCsvRepoWorks), "csv"));

            using (var unitOfWork = new StockCsvUnitOfWork(new StockCsvContext <Company>(outputFile)))
            {
                foreach (var stock in allStocks)
                {
                    unitOfWork.Repository.AddOrUpdate(stock);
                    unitOfWork.Complete();
                }
            }
            var received = File.ReadAllText(outputFile.FullName);
        }