public void CanSaveNewEmployeeToDatabase()
        {
            var employeeFactory = new EmployeeFactory();
            int lastPK          = employeeFactory.getAll().Last().EmployeeId;

            Employee Jeb = new Employee()
            {
                FirstName     = "Jeb",
                LastName      = "Bush",
                DepartmentId  = 1,
                Administrator = false
            };

            Jeb.save();

            Employee shouldBeJeb = employeeFactory.getAll().Last();

            Assert.NotNull(shouldBeJeb);
            Assert.NotNull(shouldBeJeb.EmployeeId);
            Assert.True(shouldBeJeb.EmployeeId > lastPK);
            Assert.True(Jeb.FirstName == shouldBeJeb.FirstName);
            Assert.True(Jeb.LastName == shouldBeJeb.LastName);
            Assert.True(Jeb.DepartmentId == shouldBeJeb.DepartmentId);
            Assert.True(Jeb.Administrator == shouldBeJeb.Administrator);

            var conn = new BangazonWorkforceConnection();

            conn.insert($"DELETE FROM Employee WHERE EmployeeId = {shouldBeJeb.EmployeeId}");
        }
Exemple #2
0
        /**
         * Purpose: Saves an employee instance to the database
         * Return:
         *     void
         */
        public void save()
        {
            string query = string.Format(@"
            INSERT INTO Employee 
                (FirstName, LastName, DepartmentId, Administrator, StartDate)
            VALUES 
                ('{0}', '{1}', '{2}', '{3}', '{4}');
            ",
                                         this.FirstName,
                                         this.LastName,
                                         this.DepartmentId,
                                         this.Administrator ? 1 : 0,
                                         this.StartDate
                                         );

            BangazonWorkforceConnection conn = new BangazonWorkforceConnection();

            conn.insert(query);
        }