Example #1
0
        public void TestFind()
        {
            ExecInDatabase((options) => {
                using (var context = new TestingDbContext(options)) {
                    var repository = new WrittersRepository(context);
                    repository.SaveRange(new [] {
                        new Writter {
                            Name = "John Doe"
                        },
                        new Writter {
                            Name = "Janne Doe"
                        },
                        new Writter {
                            Name = "Dick Doe"
                        }
                    });
                }

                using (var context = new TestingDbContext(options)) {
                    var repository = new WrittersRepository(context);
                    var writter    = repository.Find(_ => _.Name.StartsWith("Dick")).FirstOrDefault();
                    Assert.IsNotNull(writter);
                    Assert.AreEqual(writter.Name, "Dick Doe");
                }
            });
        }
Example #2
0
        public void TestDeleteAll()
        {
            ExecInDatabase((options) => {
                using (var context = new TestingDbContext(options)) {
                    var repository = new WrittersRepository(context);
                    repository.SaveRange(new [] {
                        new Writter {
                            Name = "John Doe"
                        },
                        new Writter {
                            Name = "Janne Doe"
                        },
                        new Writter {
                            Name = "Dick Doe"
                        }
                    });
                }

                using (var context = new TestingDbContext(options)) {
                    var repository = new WrittersRepository(context);
                    repository.DeleteAll();
                }

                using (var context = new TestingDbContext(options)) {
                    var repository = new WrittersRepository(context);
                    Assert.AreEqual(repository.Count(), 0);
                }
            });
        }
Example #3
0
        public void TestFindAll()
        {
            ExecInDatabase((options) => {
                using (var context = new TestingDbContext(options)) {
                    var repository = new WrittersRepository(context);
                    repository.SaveRange(new [] {
                        new Writter {
                            Name = "John Doe"
                        },
                        new Writter {
                            Name = "Janne Doe"
                        },
                        new Writter {
                            Name = "Dick Doe"
                        }
                    });
                }

                using (var context = new TestingDbContext(options)) {
                    var repository    = new WrittersRepository(context);
                    var writters      = repository.FindAll();
                    var writtersNames = new [] { "John Doe", "Janne Doe", "Dick Doe" };
                    Assert.AreEqual(writters.Count(), 3);
                    Assert.IsTrue(writtersNames.SequenceEqual(writters.Select(_ => _.Name)));
                }
            });
        }
Example #4
0
        public void TestSave()
        {
            ExecInDatabase((options) => {
                using (var context = new TestingDbContext(options)) {
                    var repository = new WrittersRepository(context);
                    repository.Save(new Writter {
                        Name = "John Doe"
                    });
                    repository.SaveRange(new [] {
                        new Writter {
                            Name = "Janne Doe"
                        },
                        new Writter {
                            Name = "Dick Doe"
                        }
                    });
                }

                using (var context = new TestingDbContext(options)) {
                    var repository = new WrittersRepository(context);
                    var first      = repository.Query().First();
                    Assert.AreEqual(repository.Count(), 3);
                    Assert.AreEqual(first.Id, 1);
                    Assert.AreEqual(first.Name, "John Doe");
                    Assert.IsTrue(first.Books.IsEmpty());
                }
            });
        }