public void UpdateEmployee_SupervisorsCountryIsNotSame_ShouldThrowException()
        {
            /************* Arrange: Setting up data containers ************************************************/

            //constants to be used in test containers (optional), for test readability

            const int    SUPERVISOR_ID                 = 100;
            const string SUPERVISOR_COUNTRY            = "USA";
            const int    SUBORDINATE_ID                = 200;
            const string SUBORDINATE_DIFFERENT_COUNTRY = "UK";

            //creating sample data for other employee, that would contain the different COUNTRY of the employee

            Employee supervisorEmployee = TestDataHelper.CreateEmployeeWithValidData();

            supervisorEmployee.Id = SUPERVISOR_ID;
            supervisorEmployee.Address.Country = SUPERVISOR_COUNTRY;

            _employee    = TestDataHelper.CreateEmployeeWithValidData();
            _employee.Id = SUBORDINATE_ID;
            _employee.Address.Country = SUBORDINATE_DIFFERENT_COUNTRY;
            _employee.ReportsTo       = SUPERVISOR_ID;

            /************* Arrange: Setting up mock test ************************************************/

            //populating sample data to ObjectSet container that would be considered as the data source in mock database for employee entities
            _fakeEmployeeDbSet.Add(supervisorEmployee);
            _fakeEmployeeDbSet.Add(_employee);

            //setting up the mock database with sample object
            _mockDbContext.Setup(db => db.EmployeeRepository).Returns(_fakeEmployeeDbSet);

            /************* Action ************************************************/
            _employeeController.FireValidationForModel(_employee);
            _employeeController.Edit(_employee);

            /************* Assert ************************************************/
            Assert.IsTrue(SupervisorCountryMustBeSame.IsErrorAvalilableIn(_employeeController));
        }
Beispiel #2
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            yield return(EmployeeAddressMustBeUnique.Validate(this));

            yield return(SupervisorCountryMustBeSame.Validate(this));
        }