Пример #1
0
        public void UpdateEmployee(BusinessObjects.Employee e)
        {
            var updatedEmployee =
                employeeAdapter.UpdateEmployeePerson(e.JobTitle, e.BusinessEntityId, e.FirstName, e.MiddleName, e.LastName);

            throw new NotImplementedException();
        }
 public void SetUp()
 {
     employeeBo     = new BusinessObjects.Employee();
     employeeEntity = new EntityFramework.Employee {
         Person = new Person()
     };
 }
Пример #3
0
        // Map BOs onto Entities
        // Surjective mapping onto only a subset of Entity, rest of data preserved
        // Hence map "onto", as opposed to "map to"

        public static void MapOntoEntity(this BusinessObjects.Employee source, Employee target)
        {
            target.Person.FirstName  = source.FirstName;
            target.Person.MiddleName = source.MiddleName;
            target.Person.LastName   = source.LastName;
            target.JobTitle          = source.JobTitle;
        }
        public void MapOntoEntity_NullEmployeeBusinessObject_NullReferenceExceptionThrown()
        {
            // Arrange
            BusinessObjects.Employee nullEmployeeBo = null;

            // Act/Assert
            Assert.Throws <NullReferenceException>(() => nullEmployeeBo.MapOntoEntity(employeeEntity));
        }
        public override void SetUp()
        {
            // Call base setup
            base.SetUp();

            // Create modified employee data to update with
            updateCeo = GetCeoEmployeeBo();
            updateCeo.FirstName = TestData.AlternativeFirstName;
        }
        public void UpdateEmployee(BusinessObjects.Employee employee)
        {
            // Paramaterised SQL query, update both tables
            string query = "UPDATE HumanResources.Employee SET JobTitle = @JobTitle WHERE BusinessEntityID = @BusinessEntityID; "
                           + "UPDATE Person.Person SET FirstName = @FirstName, MiddleName = @MiddleName, LastName = @LastName WHERE BusinessEntityID = @BusinessEntityID";

            // Send SQL to DB
            int rowsAffected = cnn.Execute(query, employee.MapToParams());
        }
        public override void SetUp()
        {
            // Call base setup
            base.SetUp();

            // Create modified employee data to update with
            updateCeo           = GetCeoEmployeeBo();
            updateCeo.FirstName = TestData.AlternativeFirstName;
        }
        public void UpdateEmployee(BusinessObjects.Employee employee)
        {
            // Get the current employee entity
            var entity = Db.Employees.Find(employee.BusinessEntityId);

            // Map our business object onto the entity
            employee.MapOntoEntity(entity);

            // Save the changes to the entity
            Db.SaveChanges();
        }
Пример #9
0
 public static object MapToParams(this BusinessObjects.Employee e)
 {
     return(new
     {
         BusinessEntityID = e.BusinessEntityId,
         FirstName = e.FirstName,
         MiddleName = e.MiddleName,
         LastName = e.LastName,
         JobTitle = e.JobTitle
     });
 }
Пример #10
0
        public virtual void Setup()
        {
            // Lazy, TODO: Register globally
            AutoMapperConfig.RegisterMapping();

            // Create mock for HumanResourcesService
            mockHumanResourcesService = new Mock <IHumanResourcesService>();

            // Create new Employee object
            ceoBo    = GetCeoEmployeeBo();
            ceoModel = GetCeoModel();
        }
        public virtual void Setup()
        {
            // Lazy, TODO: Register globally
            AutoMapperConfig.RegisterMapping();

            // Create mock for HumanResourcesService
            mockHumanResourcesService = new Mock<IHumanResourcesService>();

            // Create new Employee object
            ceoBo = GetCeoEmployeeBo();
            ceoModel = GetCeoModel();
        }
        public bool UpdateEmployee(BusinessObjects.Employee employee)
        {
            // Check business object sent is valid, and the employee exists
            if (employee == null ||
                employee.BusinessEntityId < 0 ||
                EmployeeDA.GetEmployeeByBusinessEntityId(employee.BusinessEntityId) == null)
            {
                return(false);
            }

            EmployeeDA.UpdateEmployee(employee);
            return(true);
        }
        public virtual void SetUp()
        {
            // New instances of the mocks
            mockEmployeeDa = new Mock <IEmployeeDA>();
            mockPhoneDa    = new Mock <IPersonPhoneDA>();
            mockAppReader  = new Mock <IAppSettingReader>();

            // Mock the app reader/web.config for each method. Determines which DataAccess method will be used.
            mockAppReader.Setup(x => x.GetAppSetting(TestData.DataAccessMethodKey)).Returns(TestData.DataAccessMethodEntityFramework);

            // Create test ceo
            ceo = GetCeoEmployeeBo();
        }
        public virtual void SetUp()
        {
            // New instances of the mocks
            mockEmployeeDa = new Mock<IEmployeeDA>();
            mockPhoneDa = new Mock<IPersonPhoneDA>();
            mockAppReader = new Mock<IAppSettingReader>();

            // Mock the app reader/web.config for each method. Determines which DataAccess method will be used.
            mockAppReader.Setup(x => x.GetAppSetting(TestData.DataAccessMethodKey)).Returns(TestData.DataAccessMethodEntityFramework);

            // Create test ceo
            ceo = GetCeoEmployeeBo();
        }
        public void UpdateEmployee_NullObjectGiven_FalseReturnedAndDataAccessNeverCalled()
        {
            // Arrange
            BusinessObjects.Employee nullEmployee = null;
            CreateHumanResourcesService();

            // Act
            bool returns = hr.UpdateEmployee(nullEmployee);

            // Assert
            mockEmployeeDa.Verify(x => x.GetEmployeeByBusinessEntityId(It.IsAny <int>()), Times.Never());
            mockEmployeeDa.Verify(x => x.UpdateEmployee(It.IsAny <BusinessObjects.Employee>()), Times.Never());
            Assert.IsFalse(returns);
        }
 public void SetUp()
 {
     employeeBo = new BusinessObjects.Employee();
     employeeEntity = new EntityFramework.Employee { Person = new Person() };
 }