public void GetAllDepartmentsEmpty()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                DepartmentRepository rep = new DepartmentRepository(ctx);

                IEnumerable<Department> result = rep.GetAllDepartments();
                Assert.AreEqual(0, result.Count());
            }
        }
Esempio n. 2
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.");
            }
        }
Esempio n. 3
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 GetAllDepartments()
        {
            Department d1 = new Department();
            Department d2 = new Department();
            Department d3 = new Department();

            using (FakeEmployeeContext ctx = new FakeEmployeeContext(new Employee[] { }, new Department[] { d1, d2, d3 }))
            {
                DepartmentRepository rep = new DepartmentRepository(ctx);

                IEnumerable<Department> result = rep.GetAllDepartments();

                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(d1));
                Assert.IsTrue(result.Contains(d2));
                Assert.IsTrue(result.Contains(d3));
            }
        }
Esempio n. 5
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();
        }
Esempio n. 6
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();
        }