public void InsertAggregateChildToNewAggregateRootObject()
        {
            TestInitialize();

            Employee supervisorEmployee = TestDataHelper.CreateEmployeeWithValidData();

            Employee subordinateEmployee = TestDataHelper.CreateEmployeeWithValidData();

            supervisorEmployee.Subordinates = new List <Employee> {
                subordinateEmployee
            };
            //marking to add to database

            DatabaseContext ctx = new DatabaseContext();

            ctx.Entry(supervisorEmployee).State = EntityState.Added;
            ctx.SaveChanges();

            int actualCount = (from e in ctx.EmployeeRepository select e).ToList().Count;

            Assert.Equal(16, actualCount);

            supervisorEmployee = ctx.EmployeeRepository.Find(15);
            Assert.Equal(1, supervisorEmployee.Subordinates.Count);
        }
        public void Test_Copy()
        {
            Employee emp  = TestDataHelper.CreateEmployeeWithValidData();
            Type     type = emp.GetType();

            PropertyInfo[] myObjectFields = type.GetProperties(
                BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

            foreach (PropertyInfo fi in myObjectFields)
            {
                Console.WriteLine(fi.ToString());
            }
        }
示例#3
0
        public void Edit_Negative_Test_Post_Test()
        {
            //Arrange
            var controller = DependencyHelper.GetInstance <EmployeesController>();
            var employee   = TestDataHelper.CreateEmployeeWithValidData(1);

            employee.Address.AddressLine = "2, ABC Road";
            controller.FireValidationForModel(employee);
            //Act
            controller.Edit(employee);

            //Assert
            Assert.IsTrue(EmployeeAddressMustBeUnique.IsErrorAvalilableIn(controller, employee));
        }
示例#4
0
        public void Edit_Positive_Post_Test()
        {
            //Arrange
            var controller = DependencyHelper.GetInstance <EmployeesController>();

            var employee = TestDataHelper.CreateEmployeeWithValidData(1);

            controller.FireValidationForModel(employee);

            //Act
            var result = controller.Edit(employee);

            //Assert
            Assert.IsTrue(controller.ModelState.IsValid);
        }
示例#5
0
        public void Edit_Test()
        {
            //Arrange
            var controller = DependencyHelper.GetInstance <EmployeesController>();

            var employee = TestDataHelper.CreateEmployeeWithValidData(1);

            employee.Address.AddressLine = string.Empty;

            controller.FireValidationForModel(employee.Address);

            //Act
            var result = controller.Edit(employee);

            //Assert
            Assert.IsFalse(controller.ModelState.IsValid);
        }
示例#6
0
        public void InsertAggregateChildToAggregateRoot()
        {
            DatabaseContext ctx = new DatabaseContext();

            Employee supervisorEmployee = ctx.EmployeeRepository.Find(1);

            Employee subordinateEmployee = TestDataHelper.CreateEmployeeWithValidData();

            supervisorEmployee.Subordinates.Add(subordinateEmployee); //marking to add to database

            ctx.SaveChanges();


            int actualCount = (from e in ctx.EmployeeRepository select e).ToList().Count;

            Assert.AreEqual(15, actualCount);
            Assert.AreEqual(11, supervisorEmployee.Subordinates.Count);
        }
        public void Edit_Negative_Test_Post_Mock_Test()
        {
            //Arrange
            _employee    = TestDataHelper.CreateEmployeeWithValidData();
            _employee.Id = 100;
            _fakeEmployeeDbSet.Add(_employee);

            _employee    = TestDataHelper.CreateEmployeeWithValidData();
            _employee.Id = 200;
            _fakeEmployeeDbSet.Add(_employee);

            _mockDbContext.Setup(db => db.EmployeeRepository).Returns(_fakeEmployeeDbSet);

            //Act
            _employeeController.Validate(_employee);

            //Assert
            Assert.True(EmployeeAddressMustBeUnique.IsErrorAvalilableIn(_employeeController, _employee));
        }
        public void Edit_Test()
        {
            //Arrange
            TestInitialize();

            var controller = DependencyHelper.GetInstance <EmployeesController>();

            var employee = TestDataHelper.CreateEmployeeWithValidData(1);

            employee.Address.AddressLine = string.Empty;

            controller.Validate(employee.Address);

            //Act
            var result = controller.Edit(employee);

            //Assert
            Assert.NotNull(result);
            Assert.False(controller.ModelState.IsValid);
        }
        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));
        }