Exemplo n.º 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);
            }
        }
Exemplo n.º 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());
        }
Exemplo n.º 3
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());
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 8
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);
            }
        }