Esempio n. 1
0
        public void SetupRestOfDto(BooksFilterBy filterBy, string filterValue, int pageSize,
                                   int expectedPageNum, int expectedNumPages)
        {
            //SETUP
            var       inMemDb  = new SqliteInMemory();
            const int numBooks = 12;

            using (var db = inMemDb.GetContextWithSetup())
            {
                db.Books.AddRange(EfTestData.CreateDummyBooks(numBooks, false));
                db.SaveChanges();

                var sfpDto = new SortFilterPageOptions
                {
                    FilterBy    = BooksFilterBy.ByVotes,
                    FilterValue = "Dummy",
                    PageNum     = 2
                };

                //need to do this to to setup PrevCheckState
                sfpDto.SetupRestOfDto(db.Books);

                //ATTEMPT
                sfpDto.PageNum     = 2;
                sfpDto.FilterBy    = filterBy;
                sfpDto.FilterValue = filterValue;
                sfpDto.PageSize    = pageSize;
                sfpDto.SetupRestOfDto(db.Books);

                //VERIFY
                sfpDto.PageNum.ShouldEqual(expectedPageNum);
                sfpDto.NumPages.ShouldEqual(expectedNumPages);
            }
        }
        public Ch05_AsyncPerformance(ITestOutputHelper output)
        {
            _output = output;

            _options = this.CreateUniqueClassOptions <EfCoreContext>();
            using (var context = new EfCoreContext(_options))
            {
                context.Database.EnsureClean();
                context.Books.AddRange(EfTestData.CreateDummyBooks(1000, false, false));
                context.SaveChanges();
                _firstBookId = context.Books.First().BookId;
            }
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="createLastInFuture">If true then the last book will be in the future</param>
        /// <param name="promotionPriceForFirstBook">if number it adds a promotion to the first book</param>
        public MockPlaceOrderDbAccess(bool createLastInFuture = false, int?promotionPriceForFirstBook = null)
        {
            var numBooks = createLastInFuture ? DateTime.UtcNow.Year - EfTestData.DummyBookStartDate.Year + 2 : 10;
            var books    = EfTestData.CreateDummyBooks(numBooks, createLastInFuture);

            if (promotionPriceForFirstBook != null)
            {
                books.First().Promotion = new PriceOffer
                {
                    NewPrice        = (int)promotionPriceForFirstBook,
                    PromotionalText = "Unit Test"
                }
            }
            ;
            Books = books.ToImmutableList();
        }
Esempio n. 4
0
        public void DropdownByDate()
        {
            //SETUP
            const int numBooks = 5;
            var       options  = SqliteInMemory.CreateOptions <EfCoreContext>();

            using (var context = new EfCoreContext(options))
            {
                context.Database.EnsureCreated();
                context.Books.AddRange(EfTestData.CreateDummyBooks(numBooks, true));
                context.SaveChanges();
                var service = new BookFilterDropdownService(context);

                //ATTEMPT
                var dropDown = service.GetFilterDropDownValues(BooksFilterBy.ByPublicationYear);

                //VERIFY
                dropDown.Select(x => x.Value).ToArray().ShouldEqual(new[] { "2014", "2013", "2012", "2011", "2010" });
            }
        }
Esempio n. 5
0
        public void DropdownByDate()
        {
            //SETUP
            var inMemDb = new SqliteInMemory();

            const int numBooks = 5;

            using (var db = inMemDb.GetContextWithSetup())
            {
                db.Books.AddRange(EfTestData.CreateDummyBooks(numBooks, true));
                db.SaveChanges();
                var service = new BookFilterDropdownService(db);

                //ATTEMPT
                var dropDown = service.GetFilterDropDownValues(BooksFilterBy.ByPublicationYear);

                //VERIFY
                dropDown.Select(x => x.Value).ToArray().ShouldEqual(new [] { "2014", "2013", "2012", "2011", "2010" });
            }
        }
Esempio n. 6
0
        public void TestBookQueryWithIncludes()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <EfCoreContext>();

            using var context = new EfCoreContext(options);
            context.Database.EnsureCreated();
            var book4Reviews2Authors = EfTestData.CreateDummyBooks(5).Last();

            context.Add(book4Reviews2Authors);
            context.SaveChanges();

            //ATTEMPT
            var query = context.Books
                        .Include(x => x.Reviews)
                        .Include(x => x.AuthorsLink)
                        .ThenInclude(x => x.Author);

            //VERIFY
            _output.WriteLine(query.ToQueryString());
        }
Esempio n. 7
0
        public Ch05_AsyncPerformance(ITestOutputHelper output)
        {
            _output = output;

            var connection     = this.GetUniqueDatabaseConnectionString();
            var optionsBuilder =
                new DbContextOptionsBuilder <EfCoreContext>();

            optionsBuilder.UseSqlServer(connection);
            _options = optionsBuilder.Options;
            using (var context = new EfCoreContext(_options))
            {
                context.Database.EnsureCreated();
                if (!context.Books.Any())
                {
                    context.Books.AddRange(EfTestData.CreateDummyBooks(1000, false, false));
                    context.SaveChanges();
                }
                _firstBookId = context.Books.First().BookId;
            }
        }
Esempio n. 8
0
        }                                             //#C

        /// <summary>
        ///
        /// </summary>
        /// <param name="createLastInFuture">If true then the last book will be in the future</param>
        /// <param name="promotionPriceForFirstBook">if number it adds a promotion to the first book</param>
        public MockPlaceOrderDbAccess(                            //#D
            bool createLastInFuture        = false,               //#E
            int?promotionPriceForFirstBook = null)                //#F
        {
            var numBooks = createLastInFuture                     //#G
                ? DateTime.UtcNow.Year -                          //#G
                           EfTestData.DummyBookStartDate.Year + 2 //#G
                : 10;                                             //#G
            var books = EfTestData.CreateDummyBooks               //#H
                            (numBooks, createLastInFuture);       //#H

            if (promotionPriceForFirstBook != null)
            {
                books.First().Promotion = new PriceOffer               //#I
                {                                                      //#I
                    NewPrice        = (int)promotionPriceForFirstBook, //#I
                    PromotionalText = "Unit Test"                      //#I
                }
            }
            ;                                                  //#I
            DummyBooks = books.ToImmutableList();
        }
Esempio n. 9
0
        public void CheckSortOnPrice()
        {
            //SETUP
            var inMemDb = new SqliteInMemory();
            var books   = EfTestData.CreateDummyBooks();

            books[5].Promotion = new PriceOffer
            {
                NewPrice        = 1.5m,
                PromotionalText = "Test to check order by works"
            };

            using (var db = inMemDb.GetContextWithSetup())
            {
                db.Books.AddRange(books);
                db.SaveChanges();

                //ATTEMPT
                var sorted = db.Books.MapBookToDto().OrderBooksBy(OrderByOptions.ByPriceHigestFirst).ToList();

                //VERIFY
                sorted[8].ActualPrice.ShouldEqual(1.5m);
            }
        }