Example #1
0
        public void TestCreateBookWithAuthorOk()
        {
            //SETUP1
            var options = SqliteInMemory.CreateOptions <PocoOnlyDbContext>();

            using (var context = new PocoOnlyDbContext(options))
            {
                context.Database.EnsureCreated();

                //ATTEMPT
                var book = new Book("test", null, DateTime.UtcNow, "Me", 123, null,
                                    new List <Author> {
                    new Author("Me", "*****@*****.**")
                });
                context.Add(book);
                context.SaveChanges();
            }
            using (var context = new PocoOnlyDbContext(options))
            {
                //VERIFY
                context.Books.Count().ShouldEqual(1);
                context.Authors.Count().ShouldEqual(1);
                context.Books.Include(x => x.AuthorsLink).ThenInclude(x => x.Author)
                .Single().AuthorsLink.SingleOrDefault().Author.Name.ShouldEqual("Me");
            }
        }
Example #2
0
        public void TestAddReviewToBookOk()
        {
            //SETUP1
            var options = SqliteInMemory.CreateOptions <PocoOnlyDbContext>();

            using (var context = new PocoOnlyDbContext(options))
            {
                context.Database.EnsureCreated();
                var book = new Book("test", null, DateTime.UtcNow, "Me", 123, null,
                                    new List <Author> {
                    new Author("Me", "*****@*****.**")
                });
                context.Add(book);
                context.SaveChanges();
            }
            using (var context = new PocoOnlyDbContext(options))
            {
                var rep = new Repository(context, null);

                //ATTEMPT
                var ok = rep.AddReview(1, 2, "OK", "Me");

                //VERIFY
                ok.ShouldBeTrue();
            }
            using (var context = new PocoOnlyDbContext(options))
            {
                context.Set <Review>().Count().ShouldEqual(1);
                context.Books.Include(x => x.Reviews)
                .Single().Reviews.SingleOrDefault().VoterName.ShouldEqual("Me");
            }
        }
Example #3
0
        public void TestCreatePocoOnlyDatabaseOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <PocoOnlyDbContext>();

            using (var context = new PocoOnlyDbContext(options))
            {
                var log = context.SetupLogging();

                //ATTEMPT
                context.Database.EnsureCreated();

                //VERIFY
                foreach (var logOutput in log)
                {
                    _output.WriteLine(logOutput.ToString());
                }
            }
        }
Example #4
0
 public PocoOnlyController(PocoOnlyDbContext context)
 {
     _repository = new Repository(context, null);
 }
Example #5
0
 public Repository(PocoOnlyDbContext context, IMailService mailService)
 {
     _context     = context;
     _mailService = mailService;
 }