Beispiel #1
0
        public void Animal_needs_an_enclosure()
        {
            using (var db = new FakeZooDbContext())
            {
                db.Animals.Add(new Animal {
                    Name = "Mufasa", EnclosureId = 1, Species = "Lion"
                });
                db.SaveChanges();

                var controller = new HomeController()
                {
                    Database = db
                };

                Assert.Throws <NullReferenceException>(() => controller.Index());

                db.Enclosures.Add(new Enclosure());
                db.SaveChanges();

                Assert.Throws <NullReferenceException>(() => controller.Index());

                db.Animals.Find(1).Enclosure = new Enclosure();

                var result = controller.Index();

                Assert.IsType <ViewResult>(result);
            }
        }
Beispiel #2
0
        public void Can_throw_an_exception_from_db_context()
        {
            var context = new FakeZooDbContext {
                ThrowException = () => new DBConcurrencyException("someone changed the game on you")
            };

            Assert.Throws <DBConcurrencyException>(() => context.SaveChanges());
        }
        public void Can_add_an_animal()
        {
            var db = new FakeZooDbContext();

            db.Animals.Add(new Animal {Name = "Simba", EnclosureId = 1, Species = "Lion"});
            db.SaveChanges();

            var animal = db.Animals.Find(1);

            Assert.Equal("Simba", animal.Name);
        }
        public void Can_add_a_keeper()
        {
            using (var db = new FakeZooDbContext())
            {
                db.Keepers.Add(new Keeper() {FirstName = "Ranger", LastName = "Rick"});
                db.SaveChanges();

                var keeper = db.Keepers.Find(1);

                Assert.Equal("Ranger", keeper.FirstName);
            }
        }
Beispiel #5
0
        public void Can_add_an_animal()
        {
            var db = new FakeZooDbContext();

            db.Animals.Add(new Animal {
                Name = "Simba", EnclosureId = 1, Species = "Lion"
            });
            db.SaveChanges();

            var animal = db.Animals.Find(1);

            Assert.Equal("Simba", animal.Name);
        }
        public void Animal_needs_an_enclosure()
        {
            using (var db = new FakeZooDbContext())
            {
                db.Animals.Add(new Animal { Name = "Mufasa", EnclosureId = 1, Species = "Lion" });
                db.SaveChanges();

                var controller = new HomeController() {Database = db};

                Assert.Throws<NullReferenceException>(() => controller.Index());

                db.Enclosures.Add(new Enclosure());
                db.SaveChanges();

                Assert.Throws<NullReferenceException>(() => controller.Index());

                db.Animals.Find(1).Enclosure = new Enclosure();

                var result = controller.Index();

                Assert.IsType<ViewResult>(result);
            }
        }
Beispiel #7
0
        public void Can_add_a_keeper()
        {
            using (var db = new FakeZooDbContext())
            {
                db.Keepers.Add(new Keeper()
                {
                    FirstName = "Ranger", LastName = "Rick"
                });
                db.SaveChanges();

                var keeper = db.Keepers.Find(1);

                Assert.Equal("Ranger", keeper.FirstName);
            }
        }
        public void Can_throw_an_exception_from_db_context()
        {
            var context = new FakeZooDbContext {
                ThrowException = () => new DBConcurrencyException("someone changed the game on you")
            };

            Assert.Throws<DBConcurrencyException>(() => context.SaveChanges());
        }