public void GetLongestServingEmployees()
        {
            Employee e1 = new Employee { HireDate = new DateTime(2003, 1, 1) };
            Employee e2 = new Employee { HireDate = new DateTime(2001, 1, 1) };
            Employee e3 = new Employee { HireDate = new DateTime(2000, 1, 1) };
            Employee e4 = new Employee { HireDate = new DateTime(2002, 1, 1) };

            // The following employee verifies GetLongestServingEmployees does not return terminated employees
            Employee e5 = new Employee { HireDate = new DateTime(1999, 1, 1), TerminationDate = DateTime.Today };

            using (FakeEmployeeContext ctx = new FakeEmployeeContext(new Employee[] { e1, e2, e3, e4, e5 }, new Department[] { }))
            {
                EmployeeRepository rep = new EmployeeRepository(ctx);

                // Select a subset
                List<Employee> result = rep.GetLongestServingEmployees(2).ToList();
                Assert.AreEqual(2, result.Count, "Expected two items in result.");
                Assert.AreSame(e3, result[0], "Incorrect item at position 0.");
                Assert.AreSame(e2, result[1], "Incorrect item at position 1.");

                // Select more than are present
                result = rep.GetLongestServingEmployees(50).ToList();
                Assert.AreEqual(4, result.Count, "Expected four items in result.");
            }
        }
        public void GetLongestServingEmployees()
        {
            Employee e1 = new Employee { HireDate = new DateTime(2003, 1, 1) };
            Employee e2 = new Employee { HireDate = new DateTime(2001, 1, 1) };
            Employee e3 = new Employee { HireDate = new DateTime(2000, 1, 1) };
            Employee e4 = new Employee { HireDate = new DateTime(2002, 1, 1) };

            // 以下雇员验证 GetLongestServingEmployees 不返回已离职的雇员。
            Employee e5 = new Employee { HireDate = new DateTime(1999, 1, 1), TerminationDate = DateTime.Today };

            using (FakeEmployeeContext ctx = new FakeEmployeeContext(new Employee[] { e1, e2, e3, e4, e5 }, new Department[] { }))
            {
                EmployeeRepository rep = new EmployeeRepository(ctx);

                // 选择子集
                List<Employee> result = rep.GetLongestServingEmployees(2).ToList();
                Assert.AreEqual(2, result.Count, "Expected two items in result.");
                Assert.AreSame(e3, result[0], "Incorrect item at position 0.");
                Assert.AreSame(e2, result[1], "Incorrect item at position 1.");

                // 所选项多于现有项
                result = rep.GetLongestServingEmployees(50).ToList();
                Assert.AreEqual(4, result.Count, "Expected four items in result.");
            }
        }
        public void GetAllEmployeesEmpty()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                EmployeeRepository rep = new EmployeeRepository(ctx);

                IEnumerable<Employee> result = rep.GetAllEmployees();
                Assert.AreEqual(0, result.Count());
            }
        }
Beispiel #4
0
        public void SaveCommand()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                UnitOfWork unit = new UnitOfWork(ctx);
                IDepartmentRepository departmentRepository = new DepartmentRepository(ctx);
                IEmployeeRepository employeeRepository = new EmployeeRepository(ctx);
                MainViewModel main = new MainViewModel(unit, departmentRepository, employeeRepository);

                bool called = false;
                ctx.SaveCalled += (sender, e) => { called = true; };
                main.SaveCommand.Execute(null);
                Assert.IsTrue(called, "SaveCommand should result in save on underlying UnitOfWork.");
            }
        }
Beispiel #5
0
        public void Initialization()
        {
            using (FakeEmployeeContext ctx = Generation.BuildFakeSession())
            {
                UnitOfWork unit = new UnitOfWork(ctx);
                IDepartmentRepository departmentRepository = new DepartmentRepository(ctx);
                IEmployeeRepository employeeRepository = new EmployeeRepository(ctx);

                int departmentCount = departmentRepository.GetAllDepartments().Count();
                int employeeCount = employeeRepository.GetAllEmployees().Count();

                MainViewModel main = new MainViewModel(unit, departmentRepository, employeeRepository);

                Assert.IsNotNull(main.DepartmentWorkspace, "Department workspace should be initialized.");
                Assert.AreEqual(
                    departmentCount,
                    main.DepartmentWorkspace.AllDepartments.Count,
                    "Department workspace should contain all departments from repository.");

                Assert.IsNotNull(main.EmployeeWorkspace, "Employee workspace should be initialized.");
                Assert.AreEqual(
                    employeeCount,
                    main.EmployeeWorkspace.AllEmployees.Count,
                    "Employee workspace should contain all employees from repository.");

                Assert.IsNotNull(main.LongServingEmployees, "Long serving employee list should be initialized.");
                Assert.AreEqual(5, main.LongServingEmployees.Count(), "Long serving employee list should be restricted to five employees.");

                Assert.AreSame(
                    main.DepartmentWorkspace.AllDepartments,
                    main.EmployeeWorkspace.AllEmployees[0].DepartmentLookup,
                    "A single instance of the department list should be used so that adds/removes flow throughout the application.");

                Assert.AreSame(
                   main.EmployeeWorkspace.AllEmployees,
                   main.EmployeeWorkspace.AllEmployees[0].ManagerLookup,
                   "A single instance of the employee list should be used so that adds/removes flow throughout the application.");

                Assert.IsNotNull(main.SaveCommand, "SaveCommand should be initialized.");
            }
        }
        public void GetAllEmployees()
        {
            Employee e1 = new Employee();
            Employee e2 = new Employee();
            Employee e3 = new Employee();

            using (FakeEmployeeContext ctx = new FakeEmployeeContext(new Employee[] { e1, e2, e3 }, new Department[] { }))
            {
                EmployeeRepository rep = new EmployeeRepository(ctx);

                IEnumerable<Employee> result = rep.GetAllEmployees();

                Assert.IsNotInstanceOfType(
                    result,
                    typeof(IQueryable),
                    "Repositories should not return IQueryable as this allows modification of the query that gets sent to the store. ");

                Assert.AreEqual(3, result.Count());
                Assert.IsTrue(result.Contains(e1));
                Assert.IsTrue(result.Contains(e2));
                Assert.IsTrue(result.Contains(e3));
            }
        }
Beispiel #7
0
        /// <summary>
        /// 启动时启动输入窗体
        /// </summary>
        /// <param name="e">startup 事件的参数</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            if (this.useFakes)
            {
                this.context =  Generation.BuildFakeSession();
            }
            else
            {
                //注意: 如果 .\SQLEXPRESS 中没有 Microsoft SQL Server Express 实例,
                //      您将需要更新 App.config 中的“EmployeeEntities”连接字符串
                this.context = new EmployeeEntities();
            }

            IDepartmentRepository departmentRepository = new DepartmentRepository(this.context);
            IEmployeeRepository employeeRepository = new EmployeeRepository(this.context);
            IUnitOfWork unit = new UnitOfWork(this.context);

            MainViewModel main = new MainViewModel(unit, departmentRepository, employeeRepository);
            MainView window = new View.MainView { DataContext = main };
            window.Show();
        }
Beispiel #8
0
        /// <summary>
        /// Lauches the entry form on startup
        /// </summary>
        /// <param name="e">Arguments of the startup event</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            if (this.useFakes)
            {
                this.context =  Generation.BuildFakeSession();
            }
            else
            {
                //NOTE: If there is not a Microsoft SQL Server Express instance available at .\SQLEXPRESS
                //      you will need to update the "EmployeeEntities" connection string in App.config
                this.context = new EmployeeEntities();
            }

            IDepartmentRepository departmentRepository = new DepartmentRepository(this.context);
            IEmployeeRepository employeeRepository = new EmployeeRepository(this.context);
            IUnitOfWork unit = new UnitOfWork(this.context);

            MainViewModel main = new MainViewModel(unit, departmentRepository, employeeRepository);
            MainView window = new View.MainView { DataContext = main };
            window.Show();
        }