Example #1
0
        public void updateStaff_Test()
        {
            // arrange
            var    staffDAO = A.Fake <Model.DataAccessLayer.IStaffDAO>();
            int    staffID  = 1;
            string fullName = "Full Name";
            string password = "******";

            Staff.Privelege privelege = Staff.Privelege.Normal;
            Staff           newStaff  = new Staff(staffID, fullName, password, privelege);
            bool            updateStaffMethodCalled = false;

            A.CallTo(() => staffDAO.updateStaff(newStaff)).Invokes(() => updateStaffMethodCalled = true);
            this.staffService = new StaffOps(staffDAO);
            bool eventFired = false;

            this.staffService.GetAllStaff += (sender, args) => { eventFired = true; };

            // act
            this.staffService.updateStaff(newStaff);

            // assert
            NUnit.Framework.Assert.IsTrue(eventFired);
            NUnit.Framework.Assert.IsTrue(updateStaffMethodCalled);
        }
Example #2
0
        public void getStaff_Test()
        {
            // this should return either a null or a staff object

            // arrange
            // set up the data access fake
            var    staffDAO = A.Fake <Model.DataAccessLayer.IStaffDAO>();
            int    staffID  = 1;
            string fullName = "Full Name";
            string password = "******";

            Staff.Privelege privelege = Staff.Privelege.Normal;
            A.CallTo(() => staffDAO.getStaff(0)).Returns(null);
            A.CallTo(() => staffDAO.getStaff(staffID)).Returns(new Staff(staffID, fullName, password, privelege));
            // instantiate the class under test
            staffService = new StaffOps(staffDAO);

            // act
            IStaff staffThatDoesNotExist = this.staffService.getStaff(0);
            IStaff staffThatExists       = this.staffService.getStaff(staffID);

            // assert
            NUnit.Framework.Assert.IsNull(staffThatDoesNotExist);
            NUnit.Framework.Assert.AreEqual(staffID, staffThatExists.StaffID);
            NUnit.Framework.Assert.AreEqual(fullName, staffThatExists.FullName);
            NUnit.Framework.Assert.AreEqual(password, staffThatExists.PasswordHash);
            NUnit.Framework.Assert.AreEqual(privelege, staffThatExists.privelege);
        }
Example #3
0
        /// <summary>
        /// Add a staff record to the database.
        /// </summary>
        /// <param name="staff">Staff object.</param>
        public void addStaff(IStaff staff)
        {
            // StaffID in the database is PK and AI
            string queryAddStaff = "INSERT INTO Staff (FullName, PasswordHash, Privelege) " +
                                   "VALUES (@name, @password, @privelege);";

            using (SqlConnection conn = new SqlConnection(this.connString))
            {
                // prepare the command
                SqlCommand cmd = new SqlCommand(queryAddStaff, conn);

                // parameterise
                SqlParameter nameParam = new SqlParameter();
                nameParam.ParameterName = "@name";
                nameParam.Value         = staff.FullName;
                cmd.Parameters.Add(nameParam);

                SqlParameter passParam = new SqlParameter();
                passParam.ParameterName = "@password";
                passParam.Value         = staff.PasswordHash;
                cmd.Parameters.Add(passParam);

                SqlParameter privParam = new SqlParameter();
                privParam.ParameterName = "@privelege";
                Staff.Privelege privelege = staff.privelege;
                switch (privelege)
                {
                case Staff.Privelege.Admin:
                    privParam.Value = "Admin";

                    break;

                case Staff.Privelege.Normal:
                    privParam.Value = "Normal";

                    break;

                default:
                    // this shouldn't happen
                    throw new Exception("Invalid staff data");
                }
                cmd.Parameters.Add(privParam);

                // try a connection
                conn.Open();

                // execute the query
                cmd.ExecuteNonQuery();
            }

            return;
        }
        public void importUpdateStaff_Test()
        {
            // arrange
            int    id       = 1;
            string fullName = "Full Name";
            string password = "******";

            Staff.Privelege privelege = Staff.Privelege.Normal;
            Staff           newStaff  = new Staff(id, fullName, password, privelege);
            // set up the model fake
            var  staffService            = A.Fake <Model.ServiceLayer.IStaffOps>();
            bool updateStaffMethodCalled = false;

            A.CallTo(() => staffService.importUpdateStaff(newStaff)).Invokes(() => { updateStaffMethodCalled = true; });
            // set up the class under test
            this.staffController = new StaffController(staffService);

            // act
            staffController.importUpdateStaff(newStaff);

            // assert
            NUnit.Framework.Assert.IsTrue(updateStaffMethodCalled);
        }