コード例 #1
0
        public void GetAllDepartmentsEmpty()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                DepartmentRepository rep = new DepartmentRepository(ctx);

                IEnumerable<Department> result = rep.GetAllDepartments();
                Assert.AreEqual(0, result.Count());
            }
        }
コード例 #2
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.");
            }
        }
コード例 #3
0
        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));
            }
        }