Exemplo n.º 1
0
        public void TestDeleteRelational()
        {
            ExecInDatabase((options) => {
                using (var context = new TestingDbContext(options)) {
                    var repository = new WrittersRepository(context);
                    var writter    = new Writter {
                        Name = "John Doe"
                    };
                    writter.Books.Add(new Book {
                        Name = "Universe Mysteries", Pages = 42
                    });
                    repository.Save(writter);
                }

                using (var context = new TestingDbContext(options)) {
                    var repository = new WrittersRepository(context);
                    var writter    = repository.Query().First();
                    repository.Delete(writter);
                }

                using (var context = new TestingDbContext(options)) {
                    var writterRepository = new WrittersRepository(context);
                    var bookRepository    = new BooksRepository(context);
                    Assert.AreEqual(writterRepository.Count(), 0);
                    Assert.AreEqual(bookRepository.Count(), 0);
                }
            });
        }
Exemplo n.º 2
0
        public void TestUpdateRelational()
        {
            ExecInDatabase((options) => {
                using (var context = new TestingDbContext(options)) {
                    var repository = new WrittersRepository(context);
                    var writter    = new Writter {
                        Name = "John Doe"
                    };
                    writter.Books.Add(new Book {
                        Name = "Universe Mysteries", Pages = 42
                    });
                    repository.Save(writter);
                }

                using (var context = new TestingDbContext(options)) {
                    var repository = new WrittersRepository(context);
                    var writter    = repository.Query().Include(_ => _.Books).First();
                    var book       = writter.Books.First();
                    writter.Name   = "Janne Doe";
                    book.Name      = "Stars of the Universe";
                    book.Pages     = 1000;
                    repository.Update(writter);
                }

                using (var context = new TestingDbContext(options)) {
                    var repository = new WrittersRepository(context);
                    var writter    = repository.Query().Include(_ => _.Books).First();
                    var book       = writter.Books.First();
                    Assert.AreEqual(repository.Count(), 1);
                    Assert.AreEqual(writter.Id, 1);
                    Assert.AreEqual(writter.Name, "Janne Doe");
                    Assert.AreEqual(book.Id, 1);
                    Assert.AreEqual(book.Name, "Stars of the Universe");
                    Assert.AreEqual(book.Pages, 1000);
                }
            });
        }