Beispiel #1
0
        public static void PopulateDatabase()
        {
            using var context = new BooksContext();

            context.AddRange(
                new ForumUser {
                Username = "******"
            },
                new ForumUser {
                Username = "******"
            },
                new ForumUser {
                Username = "******"
            },
                new ForumUser {
                Username = "******"
            },
                new ForumUser {
                Username = "******"
            },
                new ForumModerator {
                Username = "******", ForumName = "Viral Cats"
            },
                new ForumUser {
                Username = "******"
            },
                new ForumUser {
                Username = "******"
            });

            context.SaveChanges();
        }
Beispiel #2
0
        public BookControllerTest()
        {
            var dbOptions = new DbContextOptionsBuilder <BooksContext>()
                            .UseInMemoryDatabase(databaseName: "in-memory")
                            .Options;

            _dbContext = new BooksContext(dbOptions);
            _dbContext.AddRange(new BooksContextSeed().GetFakeBooks());
            _dbContext.SaveChanges();

            var bookContext = new BooksContext(dbOptions);

            //Real mapper
            var mappingProfile = new MappingProfileUnitTest();
            var configuration  = new MapperConfiguration(cfg => cfg.AddProfile(mappingProfile));
            var mapper         = new Mapper(configuration);

            string projectDirectory = Directory.GetParent(Environment.CurrentDirectory).Parent.FullName;

            //Mocking IWebHostEnvironment
            var mockEnvironment = new Mock <IWebHostEnvironment>();

            mockEnvironment
            .Setup(m => m.WebRootPath)
            .Returns(projectDirectory);

            _bookController = new BookController(mockEnvironment.Object, bookContext, mapper);
        }
Beispiel #3
0
        public static void PopulateDatabase()
        {
            using var context = new BooksContext(quiet: true);

            context.AddRange(
                new User {
                Popularity = 1, Username = "******"
            },
                new User {
                Popularity = 2, Username = "******"
            },
                new User {
                Popularity = 3, Username = "******"
            },
                new User {
                Popularity = 4, Username = "******"
            },
                new User {
                Popularity = 5, Username = "******"
            },
                new User {
                Popularity = 1, Username = "******"
            },
                new User {
                Popularity = 2, Username = "******"
            },
                new User {
                Popularity = 3, Username = "******"
            });

            context.SaveChanges();
        }
        public static void PopulateDatabase()
        {
            using var context = new BooksContext(quiet: true);

            context.AddRange(
                new User
            {
                FirstName = "Arthur"
            },
                new User
            {
                FirstName = "Arthur",
                LastName  = "Vickers"
            },
                new User
            {
                FirstName = "",
                LastName  = "Vickers"
            },
                new User
            {
                FirstName = " ",
                LastName  = "Vickers"
            },
                new User
            {
                FirstName = "Arthur",
                LastName  = "\t"
            });

            context.SaveChanges();
        }
Beispiel #5
0
        public void AddMultipleBook(IEnumerable <Book> books)
        {
            if (books == null)
            {
                throw new ArgumentNullException(nameof(books));
            }

            _context.AddRange(books);
        }
        /// <summary>
        /// 初始化,填充数据
        /// </summary>
        public void CreateChapters()
        {
            var chapters = new List <BookChapter>();

            for (int i = 0; i < 8; i++)
            {
                chapters.Add(new BookChapter
                {
                    Number = i,
                    Title  = sampleTitles[i],
                    Pages  = numberPages[i]
                });
            }
            _booksContext.AddRange(chapters);
            _booksContext.SaveChanges();
        }
        public static void PopulateDatabase()
        {
            using var context = new BooksContext(quiet: true);

            context.AddRange(
                new User {
                PhoneNumber = 4255551234, Username = "******"
            },
                new User {
                PhoneNumber = 5155552234, Username = "******"
            },
                new User {
                PhoneNumber = 18005525123, Username = "******"
            });

            context.SaveChanges();
        }
        public static void PopulateDatabase()
        {
            using var context = new BooksContext(quiet: true);

            context.AddRange(
                new Shard
            {
                Token1          = "A",
                Token2          = "B",
                Token3          = "C",
                TokensProcessed = "ABC"
            },
                new Shard
            {
                Token1          = "D",
                Token2          = "H",
                Token3          = "C",
                TokensProcessed = "DH"
            },
                new Shard
            {
                Token1 = "A",
                Token2 = "B",
                Token3 = "C"
            },
                new Shard
            {
                Token1          = "D",
                Token2          = "E",
                Token3          = "F",
                TokensProcessed = "DEF"
            },
                new Shard
            {
                Token1          = "J",
                Token2          = "A",
                Token3          = "M",
                TokensProcessed = "JAM"
            });

            context.SaveChanges();
        }
        public static void PopulateDatabase()
        {
            using var context = new BooksContext(quiet: true);

            context.AddRange(
                new User {
                Username = "******"
            },
                new User {
                Username = "******"
            },
                new User {
                Username = "******"
            });

            context.SaveChanges();

            context.ChangeTracker.Entries <User>().First().Entity.Username = "******";
            context.SaveChanges();
        }
Beispiel #10
0
 public static void EnsureDatabaseSeeded(this BooksContext context)
 {
     if (!context.Book.Any())
     {
         context.AddRange(new Book[] {
             new Book()
             {
                 ISBN        = "000123456",
                 Title       = "Harry Potter and The Deathly Hallows",
                 Author      = "J.K. Rowling",
                 Genre       = "Fantasy Ficton",
                 Description = "Without the guidance and protection of their professors, Harry (Daniel Radcliffe), Ron (Rupert Grint) and Hermione (Emma Watson) begin a mission to destroy the Horcruxes, the sources of Voldemort's immortality. Though they must rely on one another more than ever, dark forces threaten to tear them apart. Voldemort's Death Eaters have seized control of the Ministry of Magic and Hogwarts, and they are searching for Harry -- even as he and his friends prepare for the ultimate showdown.",
                 BookCover   = "https://images-na.ssl-images-amazon.com/images/I/51tB0kftR-L._SX345_BO1,204,203,200_.jpg",
                 Rating      = 4.7,
                 Stock       = 22
             },
             new Book()
             {
                 ISBN        = "000123457",
                 Title       = "The Help",
                 Author      = "Kathryn Stockett",
                 Genre       = "Novel",
                 Description = "In Jackson, Mississippi, in the 60's, the aspirant writer Skeeter Phelan has just graduated and returns home after finding a job writing in a futile newspaper column in the local newspaper. When she arrives home, she finds that her nanny and family's maid Constantine Jefferson is gone. Skeeter sees the chance of writing a book about the relationship of the black maids with the Southern society for an editor from New York. First she convinces Aibileen Clark to open her heart to her; then Minny Jackson is unfairly fired by the arrogant Hilly Holbrook, who is a leader in the racist high society, and Minny decides to tell her stories after finding a job with the outcast Celia Foote. Soon eleven other maids accept to be interviewed by Skeeter that also tells the truth about Constantine. When the book 'The Help' is released, Jackson's high society will never be the same.",
                 BookCover   = "https://images.gr-assets.com/books/1303597269l/10966007.jpg",
                 Rating      = 4.4,
                 Stock       = 41
             },
             new Book()
             {
                 ISBN        = "000123458",
                 Title       = "The Green Mile",
                 Author      = "Stephen King",
                 Genre       = "Dark Fantasy",
                 Description = "The protagonist and narrator of the book and the death-row supervisor at Cold Mountain Penitentiary. He is 40 years old when the main bulk of the story takes place, in 1932. He is a caring man and takes excellent care of the men on his block, avoiding conflict and keeping the peace whenever possible.",
                 BookCover   = "https://prodimage.images-bn.com/pimages/9781501192265_p0_v2_s550x406.jpg",
                 Rating      = 4.2,
                 Stock       = 35
             },
             new Book()
             {
                 ISBN        = "000123459",
                 Title       = "The Martian",
                 Author      = "Andy Weir",
                 Genre       = "Novel",
                 Description = " An astronaut becomes stranded on Mars after his team assume him dead, and must rely on his ingenuity to find a way to signal to Earth that he is alive. During a manned mission to Mars, Astronaut Mark Watney is presumed dead after a fierce storm and left behind by his crew.",
                 BookCover   = "https://images-na.ssl-images-amazon.com/images/I/81wFMY9OAFL.jpg",
                 Rating      = 3.9,
                 Stock       = 45
             },
             new Book()
             {
                 ISBN        = "000123460",
                 Title       = "No Country for Old Men",
                 Author      = "Cormac McCarthy",
                 Genre       = "Adventure",
                 Description = "The plot follows the interweaving paths of the three central characters (Llewelyn Moss, Anton Chigurh, and Ed Tom Bell) set in motion by events related to a drug deal gone bad near the Mexican–American border in remote Terrell County in southwest Texas.",
                 BookCover   = "http://bookcoverarchive.com/wp-content/uploads/amazon/no_country_for_old_men.jpg",
                 Rating      = 4.1,
                 Stock       = 27
             },
             new Book()
             {
                 ISBN        = "000123461",
                 Title       = "Oh My God, What a Complete Aisling",
                 Author      = "Emer McLysaght and Sarah Breen",
                 Genre       = "Humour",
                 Description = "What a complete Aisling can be considered a late coming of age novel. 28 years old and in love with her boyfriend John, Aisling is looking for the wedding ring. When John fails to deliver after 7 years of dating, Aisling breaks up with him and tries to move her life on. But naturally moving on is not so simple, what with her dad being ill and all. New friendships, new relationships, new adventures all combine together in a humorous and engaging novel.",
                 BookCover   = "https://cdn.waterstones.com/override/v2/large/9781/4059/9781405938204.jpg",
                 Rating      = 4.3,
                 Stock       = 18
             },
             new Book()
             {
                 ISBN        = "000123462",
                 Title       = "Becoming",
                 Author      = "Michelle Obama",
                 Genre       = "Autobiography",
                 Description = "The book's 24 chapters (plus a preface and epilogue) are divided into three sections: Becoming Me, Becoming Us, and Becoming More. Become Me traces Obama's early life growing up on the South Side of Chicago, through her education at Princeton University and Harvard Law School, to her early career as a lawyer at the law firm Sidley Austin, where she met Barack Obama. Becoming Us departs from the beginning of their romantic relationship and follows their marriage, the beginning of his political career in the Illinois State Senate. The section ends with election night in 2008 when Barack Obama was elected President of the United States and Becoming More describes their life as First Family.",
                 BookCover   = "https://images-na.ssl-images-amazon.com/images/I/81h2gWPTYJL.jpg",
                 Rating      = 3.9,
                 Stock       = 22
             },
             new Book()
             {
                 ISBN        = "000123463",
                 Title       = "The Girl on The Train",
                 Author      = "Paula Hawkins",
                 Genre       = "Thriller",
                 Description = "Commuter Rachel Watson catches daily glimpses of a seemingly perfect couple, Scott and Megan, from the window of her train. One day, Watson witnesses something shocking unfold in the backyard of the strangers' home. Rachel tells the authorities what she thinks she saw after learning that Megan is now missing and feared dead. Unable to trust her own memory, the troubled woman begins her own investigation, while police suspect that Rachel may have crossed a dangerous line.",
                 BookCover   = "https://images-na.ssl-images-amazon.com/images/I/8183Y1myPvL.jpg",
                 Rating      = 3.7,
                 Stock       = 29
             },
             new Book()
             {
                 ISBN        = "000123464",
                 Title       = "Alan Turing: The Enigma",
                 Author      = " Andrew Hodges",
                 Genre       = "Biography",
                 Description = "Alan Turing: The Enigma is a biography of the British mathematician, codebreaker, and early computer scientist, Alan Turing by Andrew Hodges. The book covers Alan Turing's life and work.",
                 BookCover   = "https://images-na.ssl-images-amazon.com/images/I/51MmySzVSeL.jpg",
                 Rating      = 3.5,
                 Stock       = 12
             },
             new Book()
             {
                 ISBN        = "000123465",
                 Title       = "Gone Girl",
                 Author      = "Gillian Flynn",
                 Genre       = "Thriller",
                 Description = "With his wife's disappearance having become the focus of an intense media circus, a man sees the spotlight turned on him when it's suspected that he may not be innocent. On the occasion of his fifth wedding anniversary, Nick Dunne reports that his wife, Amy, has gone missing.",
                 BookCover   = "https://images-na.ssl-images-amazon.com/images/I/516Gb2s1eGL._SX324_BO1,204,203,200_.jpg",
                 Rating      = 4.4,
                 Stock       = 20
             }
         });
         context.SaveChanges();
     }
 }