Esempio n. 1
0
        static void Main(string[] args)
        {
            var bookCtx = new BookContext();
            long count = 0;

            var books = new List<Book>();

            Console.WriteLine("Loading Books ...");

            var stopWatch = new Stopwatch();
            stopWatch.Start();

            foreach (var item in GetBookData())
            {
                try
                {
                    var book = new Book()
                    {
                        ISBN = item[0],
                        Title = item[1],
                        Author = item[2],
                        PublicationYear = int.Parse(item[3]),
                        Publisher = item[4],
                        ImageUrlSmall = item[5],
                        ImageUrlMedium = item[6],
                        ImageUrlLarge = item[7],
                    };

                    books.Add(book);
                    count++;
                }
                catch (Exception)
                {
                    Console.WriteLine("Error in line: {0}", count+1);
                }

                //Insert every 1,000 records
                if ((count % 1000) == 0)
                {
                    bookCtx.Books.InsertMany(books);
                    Console.WriteLine("Inserting: {0}", count);
                    books = new List<Book>();
                }
            }

            //Insert last if any
            if (books.Count > 0)
            {
                bookCtx.Books.InsertMany(books);
                Console.WriteLine("Inserting: {0}", count);
                books = null;
            }

            stopWatch.Stop();

            Console.WriteLine("Finished!");
            Console.WriteLine("Time elapsed: {0}", stopWatch.Elapsed);

            // Read some
            /*
            var books = Queryable.Where(bookCtx.Books.AsQueryable(), b => b.PageCount > 50);
            Console.WriteLine("Books with more than 50 pages: {0}", books.Count());
            Console.WriteLine("First One: {0}", books.FirstOrDefault().Title);
            Console.ReadKey();
            */
        }
Esempio n. 2
0
 public void SaveBook_ChangeValue_PriceNegative()
 {
     var b = new Book {Price = -1};
     b.SaveBook();
 }
Esempio n. 3
0
 public void SaveBook_ChangeValue_PriceHigher()
 {
     var b = new Book {Price = 98};
     b.SaveBook();
 }
Esempio n. 4
0
 public void UpdatePriceByPercent_ChangeValue_ReturnPriceTimesPercent()
 {
     var b = new Book {Price = 10};
     b.UpdatePriceByPercent(.05M);
     Assert.AreEqual(10M*.05M, b.Price);
 }