Exemple #1
0
        public void DAOMemory_Update()
        {
            IDAO <Person> db = new DAOMemory <Person>();

            db.Create(new Person()
            {
                name = "Juan Carlos Sosa Peña", age = 36
            });
            db.Create(new Person()
            {
                name = "Ana Griselda Prada Perez", age = 35
            });

            // Valid Object Id Updated
            Person p1 = new Person()
            {
                id = 1, name = "José Luis Sosa Gill", age = 73
            };

            db.Update(p1);
            Assert.AreEqual(73, db.Retrive(1).age);

            // Invalid Object Id Updated
            Person p2 = new Person()
            {
                id = 3, name = "Pedro Antonio Perez", age = 15
            };

            Assert.Throws <InvalidOperationException>(() => db.Update(p2));
        }
        public void Index()
        {
            // Arrange
            IDAO <Person> db = new DAOMemory <Person, List <Person> >();

            db.Create(new Person()
            {
                id = 1, name = "Juan Carlos Sosa", age = 36
            });
            db.Create(new Person()
            {
                id = 2, name = "Ana Griselda Prada", age = 35
            });
            db.Create(new Person()
            {
                id = 3, name = "Beatriz Antonia Perez", age = 62
            });

            PeopleController controller = new PeopleController(db);

            // Act
            ViewResult    view  = controller.Index() as ViewResult;
            List <Person> model = view.Model as List <Person>;

            // Assert
            Assert.IsInstanceOf <List <Person> >(model);
        }
Exemple #3
0
        public void DAOMemory_Retrive()
        {
            IDAO <Person> db = new DAOMemory <Person>();

            db.Create(new Person()
            {
                name = "Juan Carlos Sosa Peña", age = 36
            });
            db.Create(new Person()
            {
                name = "Ana Griselda Prada Perez", age = 35
            });

            // Valid Object Id Retrived
            Assert.AreEqual(36, db.Retrive(1).age);
            // Invalid Object Id Retrive
            Assert.Throws <InvalidOperationException>(() => db.Retrive(3));
        }
Exemple #4
0
        public void DAOMemory_RetriveAll()
        {
            IDAO <Person> db = new DAOMemory <Person>();

            // Empty List Retrived
            Assert.IsInstanceOf <List <Person> >(db.RetriveAll());
            Assert.NotNull(db.RetriveAll());

            db.Create(new Person()
            {
                name = "Juan Carlos Sosa Peña", age = 36
            });
            db.Create(new Person()
            {
                name = "Ana Griselda Prada Perez", age = 35
            });

            // Filled List Retrived
            Assert.AreEqual(2, db.RetriveAll().Count);
        }
Exemple #5
0
        public void DAOMemory_Create()
        {
            IDAO <Person> db = new DAOMemory <Person>();

            db.Create(new Person()
            {
                name = "Juan Carlos Sosa Peña", age = 36
            });
            db.Create(new Person()
            {
                name = "Ana Griselda Prada Perez", age = 35
            });

            // First Object Creation
            Assert.AreEqual(36, db.Retrive(1).age);
            // Second Object Creation
            Assert.AreEqual(35, db.Retrive(2).age);
            // Null Object Creation
            Assert.Throws <NullReferenceException>(() => db.Create(null));
        }
Exemple #6
0
        public void DAOMemory_Delete()
        {
            IDAO <Person> db = new DAOMemory <Person>();

            db.Create(new Person()
            {
                name = "Juan Carlos Sosa Peña", age = 36
            });
            db.Create(new Person()
            {
                name = "Ana Griselda Prada Perez", age = 35
            });

            // Valid Object Id Deleted
            db.Delete(1);
            Assert.Throws <InvalidOperationException>(() => db.Retrive(1));

            // Invalid Object Id Updated
            Assert.Throws <InvalidOperationException>(() => db.Delete(1));
        }