Example #1
0
        public void TestAddChild()
        {
            IStore store = new ThreadStaticStore();
            IDbContextFactory contextFactory = new DbContextFactory();

            using (UnitOfWork unitwork = new UnitOfWork(store, contextFactory))
            {
                IRepository<Demo, Guid> demoRepository = new Repository<Demo, Guid>(store);
                IRepository<DemoChild, Guid> demoChildRepository = new Repository<DemoChild, Guid>(store);
                IRepository<DemoBrother, Guid> demoBrotherRepository = new Repository<DemoBrother, Guid>(store);
                Demo demo = new Demo()
                {
                    Name = "C"
                };

                DemoChild child = new DemoChild();
                demo.Children.Add(child);

                DemoBrother brother = new DemoBrother();
                demo.Brothers.Add(brother);

                demoRepository.SaveOrUpdate(demo);
                demoChildRepository.SaveOrUpdate(child);
                demoBrotherRepository.SaveOrUpdate(brother);

                unitwork.SaveChanges();
            }
        }
Example #2
0
        public void TestCreateParty()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Party, Guid> partyRepository = new Repository<Party, Guid>(store);
                //用partyRepository也可以存進去,不知差別在哪
                IRepository<Employee, Guid> employeeRepository = new Repository<Employee, Guid>(store);
                IRepository<Post, Guid> postRepository = new Repository<Post, Guid>(store);
                IRepository<PartyHierarchy, Guid> partyHierarchyRepository = new Repository<PartyHierarchy, Guid>(store);
                Employee employee = new Employee()
                {
                    Name = "Allen"
                };

                Post post = new Post()
                {
                    Name = "總經理室主管"
                };

                employeeRepository.SaveOrUpdate(employee);
                postRepository.SaveOrUpdate(post);

                PartyService partyService = new PartyService(partyHierarchyRepository);
                partyService.AddEmployeeToPost(post,employee);

                unitwork.SaveChanges();
            }
        }
Example #3
0
        public void TestCreateMoreParty()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Post, Guid> postRepository = new Repository<Post, Guid>(store);
                IRepository<Employee, Guid> employeeRepository = new Repository<Employee, Guid>(store);
                IRepository<PartyHierarchy, Guid> partyHierarchyRepository = new Repository<PartyHierarchy, Guid>(store);
                Employee employee = new Employee()
                {
                    Name = "Bob",
                };

                Post post = new Post()
                {
                    Name = "總經理室副主管",
                };

                Post parentPost = postRepository.Query(q => q.Name == "總經理室主管").First();
                employeeRepository.SaveOrUpdate(employee);
                postRepository.SaveOrUpdate(post);

                PartyService partyService = new PartyService(partyHierarchyRepository);
                partyService.AddAccountability(parentPost, post);
                unitwork.SaveChanges();
                partyService.AddEmployeeToPost(post, employee);
                unitwork.SaveChanges();
            }
        }
Example #4
0
        public void CheckPermission2()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Permission, Guid> perRepository = new Repository<Permission, Guid>(store);
                PermissionService service = new PermissionService(perRepository);

                IRepository<Employee, Guid> empRepository = new Repository<Employee, Guid>(store);
                IRepository<Entity, Guid> entRepository = new Repository<Entity, Guid>(store);

                //人資部門可以看見Admin
                var operations = service.GetOperationFor(empRepository.Query(s => s.Name == "Fred").First()
                    , entRepository.Query(q => q.Name == "Employees").First());

                Assert.AreEqual(1, operations.Count);
                Assert.AreEqual("View", operations.First().Comment);

                //業務部門看不見
                var operation2s = service.GetOperationFor(empRepository.Query(s => s.Name == "Kalad").First()
                   , entRepository.Query(q => q.Name == "Employees").First());

                Assert.AreEqual(0, operation2s.Count);

                //老板通常是有超多權限,但只留較上層的權限
                var operation3s = service.GetOperationFor(empRepository.Query(s => s.Name == "Allen").First()
                  , entRepository.Query(q => q.Name == "Employees").First());

                Assert.AreEqual(1, operation3s.Count);
            }
        }
Example #5
0
        public void TestGetAllParentEntities()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Entity, Guid> repository = new Repository<Entity, Guid>(store);

                EntityService service = new EntityService();
                ICollection<Entity> entities = service.GetAllParentEntities(repository.Query(q => q.Name == "Section").First().Id);
                Assert.AreEqual(1, entities.Count);
            }
        }
Example #6
0
        public void TestData()
        {
            IStore store = new ThreadStaticStore();
            IDbContextFactory contextFactory = new DbContextFactory();

            using (UnitOfWork unitwork = new UnitOfWork(store, contextFactory))
            {
                IRepository<Demo,Guid> demoRepository = new Repository<Demo,Guid>(store);
                Demo demo = new Demo() { Name = "B"};
                demoRepository.SaveOrUpdate(demo);
                unitwork.SaveChanges();
            }
        }
Example #7
0
        public void TestGetChild()
        {
            IStore store = new ThreadStaticStore();
            IDbContextFactory contextFactory = new DbContextFactory();

            using (UnitOfWork unitwork = new UnitOfWork(store, contextFactory))
            {
                IRepository<Demo, Guid> demoRepository = new Repository<Demo, Guid>(store);
                demoRepository.Include(i => i.Children); //這兩個做eager Load
                demoRepository.Include(i => i.Brothers);
                var demos = demoRepository.Query(q => q.Name == "C");

                Assert.AreEqual(1, demos.Count());
                Assert.AreEqual(1, demos.First().Children.Count());
                Assert.AreEqual(1, demos.First().Brothers.Count());
            }
        }
Example #8
0
        public void CheckPermission1()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Permission, Guid> perRepository = new Repository<Permission, Guid>(store);
                PermissionService service = new PermissionService(perRepository);

                IRepository<Employee, Guid> empRepository = new Repository<Employee, Guid>(store);
                IRepository<Entity,Guid> entRepository = new Repository<Entity,Guid>(store);

                var operations = service.GetOperationFor(empRepository.Query(s => s.Name == "Allen").First()
                    , entRepository.Query(q => q.Name == "Personal Information").First());

                Assert.AreEqual(1, operations.Count);
                Assert.AreEqual("Full Control", operations.First().Comment);

            }
        }
Example #9
0
        public void TestCreateParentOrgan()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Organization,Guid> organRepository = new Repository<Organization,Guid>(store);
                IRepository<OrganizationHierarchy,Guid> organHireRepository = new Repository<OrganizationHierarchy,Guid>(store);
                Organization organ1 = new Organization()
                {
                    Name = "總經理室"
                };

                Organization organ2 = new Organization()
                {
                    Name = "業務部"
                };

                Organization organ3 = new Organization()
                {
                    Name = "人資部"
                };

                Organization organ4 = new Organization()
                {
                    Name = "企畫課"
                };

                organRepository.SaveOrUpdate(organ1);
                organRepository.SaveOrUpdate(organ2);
                organRepository.SaveOrUpdate(organ3);
                organRepository.SaveOrUpdate(organ4);

                unitwork.SaveChanges();

                OrganizationService service = new OrganizationService(organHireRepository);
                service.AddOrganizationHierarchy(organ1, organ2, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(organ1, organ3, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(organ3, organ4,OrganizationHierarchyType.AM);
                unitwork.SaveChanges();

            }
        }
Example #10
0
        public void TestAddPartyToOrganization()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Organization, Guid> organRepository = new Repository<Organization, Guid>(store);
                IRepository<Party, Guid> partyRepository = new Repository<Party, Guid>(store);

                Organization org1 = new Organization()
                {
                    Name = "總經理室"
                };

                organRepository.SaveOrUpdate(org1);

                Party party1 = partyRepository.Query(q => q.Name == "總經理室主管").First();
                Party party2 = partyRepository.Query(q => q.Name == "總經理室副主管").First();
                org1.Parties.Add(party1);
                org1.Parties.Add(party2);

                unitwork.SaveChanges();

            }
        }
Example #11
0
        public void TestCreateEntity()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                Entity entity = new Entity()
                {
                    Name = "頁面"
                };

                Entity childEntity = new Entity()
                {
                    Name = "Section"
                };

                entity.ChildEntity.Add(childEntity);

                IRepository<Entity, Guid> repository = new Repository<Entity, Guid>(store);

                repository.SaveOrUpdate(entity);
                repository.SaveOrUpdate(childEntity);

                unitwork.SaveChanges();
            }
        }
Example #12
0
        public void TestGetPostsOfEmployee()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Party, Guid> partyRepository = new Repository<Party, Guid>(store);
                PartyService partyService = new PartyService();
                Party emp = partyRepository.Query(s => s.Name == "Bob").First();
                var parties = partyService.GetPostsOf(emp.Id);

                Assert.AreEqual(1, parties.Count());
                Assert.AreEqual("總經理室副主管", parties.First().Name);
            }
        }
Example #13
0
        public void CheckPermission9()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Permission, Guid> perRepository = new Repository<Permission, Guid>(store);
                PermissionService service = new PermissionService(perRepository);

                IRepository<Organization, Guid> orgRepository = new Repository<Organization, Guid>(store);
                IRepository<Entity, Guid> entRepository = new Repository<Entity, Guid>(store);

                var operations = service.GetOperationFor(orgRepository.Query(s => s.Name == "企畫課").First()
                    , entRepository.Query(q => q.Name == "Employees").First());

                Assert.AreEqual(1, operations.Count);
                Assert.AreEqual("View", operations.First().Comment);
            }
        }
Example #14
0
        public void TestGetChildEntity()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Entity, Guid> repository = new Repository<Entity, Guid>(store);
                repository.Include(i => i.ChildEntity);
                Entity page = repository.Query(q => q.Name == "頁面").First();

                Assert.IsNotNull(page.ChildEntity);
                Assert.AreEqual(1, page.ChildEntity.Count());
            }
        }
Example #15
0
        public void TestAddEmployeeToPost()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Employee, Guid> empRepository = new Repository<Employee, Guid>(store);
                IRepository<Post, Guid> roleRepository = new Repository<Post, Guid>(store);
                IRepository<PartyHierarchy, Guid> partyHireRepository = new Repository<PartyHierarchy, Guid>(store);

                Employee prt1 = new Employee() { Name = "Allen" };
                Employee prt2 = new Employee() { Name = "Bob" };
                Employee prt3 = new Employee() { Name = "Cary" };
                Employee prt4 = new Employee() { Name = "David" };
                Employee prt5 = new Employee() { Name = "Edward" };
                Employee prt6 = new Employee() { Name = "Fred" };
                Employee prt7 = new Employee() { Name = "Gallon" };
                Employee prt8 = new Employee() { Name = "Hellen" };
                Employee prt9 = new Employee() { Name = "Ian" };
                Employee prt10 = new Employee() { Name = "Ivy" };
                Employee prt11 = new Employee() { Name = "Jay" };
                Employee prt12 = new Employee() { Name = "Kalad" };
                Employee prt13 = new Employee() { Name = "Larry" };
                Employee prt14 = new Employee() { Name = "Moppies" };
                Employee prt15 = new Employee() { Name = "Nana" };
                Employee prt16 = new Employee() { Name = "Outu" };

                empRepository.SaveOrUpdate(prt1);
                empRepository.SaveOrUpdate(prt2);
                empRepository.SaveOrUpdate(prt4);
                empRepository.SaveOrUpdate(prt5);
                empRepository.SaveOrUpdate(prt6);
                empRepository.SaveOrUpdate(prt7);
                empRepository.SaveOrUpdate(prt8);
                empRepository.SaveOrUpdate(prt9);
                empRepository.SaveOrUpdate(prt10);
                empRepository.SaveOrUpdate(prt11);
                empRepository.SaveOrUpdate(prt12);
                empRepository.SaveOrUpdate(prt13);
                empRepository.SaveOrUpdate(prt14);
                empRepository.SaveOrUpdate(prt15);
                empRepository.SaveOrUpdate(prt16);

                PartyService service = new PartyService(partyHireRepository);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "總經理室主管").First(), prt1);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "總經理室副主管").First(), prt2);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "總經理室秘書").First(), prt3);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "人資部主管").First(), prt4);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "人資部副主管").First(), prt5);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "企畫課主管").First(), prt6);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "企畫課副主管").First(), prt7);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "企畫課成員").First(), prt8);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "管理課主管").First(), prt9);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "管理課副主管").First(), prt10);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "管理課成員").First(), prt11);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務部主管").First(), prt12);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務部副主管").First(), prt13);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務一課主管").First(), prt14);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務一課副主管").First(), prt15);
                service.AddEmployeeToPost(roleRepository.Query(q => q.Name == "業務一課成員").First(), prt16);
                unitwork.SaveChanges();
            }
        }
Example #16
0
        public void CheckPermission7()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Permission, Guid> perRepository = new Repository<Permission, Guid>(store);
                PermissionService service = new PermissionService(perRepository);

                IRepository<Post, Guid> postRepository = new Repository<Post, Guid>(store);
                IRepository<Entity, Guid> entRepository = new Repository<Entity, Guid>(store);

                var operations = service.GetOperationFor(postRepository.Query(s => s.Name == "管理課副主管").First()
                    , entRepository.Query(q => q.Name == "員工請假報表").First());

                Assert.AreEqual(1, operations.Count);
                Assert.AreEqual("Full Control", operations.First().Comment);
            }
        }
Example #17
0
        public void TestAddPartyToOrg()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Organization, Guid> organRepository = new Repository<Organization, Guid>(store);

                Organization org1 = organRepository.Query(s => s.Name == "總經理室").First();
                Organization org2 = organRepository.Query(s => s.Name == "人資部").First();
                Organization org3 = organRepository.Query(s => s.Name == "業務部").First();
                Organization org4 = organRepository.Query(s => s.Name == "企畫課").First();
                Organization org5 = organRepository.Query(s => s.Name == "管理課").First();
                Organization org6 = organRepository.Query(s => s.Name == "業務一課").First();
                Organization org7 = organRepository.Query(s => s.Name == "業務二課").First();
                Organization org8 = organRepository.Query(s => s.Name == "業務三課").First();

                IRepository<Party, Guid> partyRepository = new Repository<Party, Guid>(store);
                Party prt1 = partyRepository.Query(s=> s.Name == "總經理室主管").First();
                Party prt2 = partyRepository.Query(s => s.Name == "總經理室副主管").First();
                Party prt3 = partyRepository.Query(s => s.Name == "總經理室秘書").First();
                Party prt4 = partyRepository.Query(s => s.Name == "人資部主管").First();
                Party prt5 = partyRepository.Query(s => s.Name == "人資部副主管").First();
                Party prt6 = partyRepository.Query(s => s.Name == "企畫課主管").First();
                Party prt7 = partyRepository.Query(s => s.Name == "企畫課副主管").First();
                Party prt8 = partyRepository.Query(s => s.Name == "企畫課成員").First();
                Party prt9 = partyRepository.Query(s => s.Name == "管理課主管").First();
                Party prt10 = partyRepository.Query(s => s.Name == "管理課副主管").First();
                Party prt11 = partyRepository.Query(s => s.Name == "管理課成員").First();
                Party prt12 = partyRepository.Query(s => s.Name == "業務部主管").First();
                Party prt13 = partyRepository.Query(s => s.Name == "業務部副主管").First();
                Party prt14 = partyRepository.Query(s => s.Name == "業務一課主管").First();
                Party prt15 = partyRepository.Query(s => s.Name == "業務一課副主管").First();
                Party prt16 = partyRepository.Query(s => s.Name == "業務一課成員").First();

                org1.Parties.Add(prt1);
                org1.Parties.Add(prt2);
                org1.Parties.Add(prt3);
                org2.Parties.Add(prt4);
                org2.Parties.Add(prt5);
                org4.Parties.Add(prt6);
                org4.Parties.Add(prt7);
                org4.Parties.Add(prt8);
                org5.Parties.Add(prt9);
                org5.Parties.Add(prt10);
                org5.Parties.Add(prt11);
                org3.Parties.Add(prt12);
                org3.Parties.Add(prt13);
                org6.Parties.Add(prt14);
                org6.Parties.Add(prt15);
                org6.Parties.Add(prt16);

                unitwork.SaveChanges();
            }
        }
Example #18
0
        public void TestAddPermission()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Party,Guid> prtRepository = new Repository<Party,Guid>(store);
                IRepository<Organization,Guid> orgRepository = new Repository<Organization,Guid>(store);
                IRepository<Permission,Guid> perRepository = new Repository<Permission,Guid>(store);
                IRepository<Operation,Guid> oerRepository = new Repository<Operation,Guid>(store);
                IRepository<Entity,Guid> entRepository = new Repository<Entity,Guid>(store);

                //所有員工都可以看見Personal Information,且完全操作其功能
                Permission per1 = new Permission()
                {
                    Entity = entRepository.Query(q => q.Name == "Personal Information").First(),
                    Operation = oerRepository.Query(q => q.Comment == "Full Control").First(),
                    Level = 0
                };

                //人資部門可以看見Admin,Employees
                Permission per2 = new Permission()
                {
                    Organization = orgRepository.Query(q => q.Name == "人資部").First(),
                    Entity = entRepository.Query(q => q.Name == "Admin").First(),
                    Operation = oerRepository.Query(q => q.Comment == "View").First(),
                    Level = 0
                };

                Permission per3 = new Permission()
                {
                    Organization = orgRepository.Query(q => q.Name == "人資部").First(),
                    Entity = entRepository.Query(q => q.Name == "Employees").First(),
                    Operation = oerRepository.Query(q => q.Comment == "View").First(),
                    Level = 0
                };

                //企畫課員可以全權管理Admin下的技能設定,職稱設定,假期設定
                Permission per4 = new Permission()
                {
                    Party = prtRepository.Query(q => q.Name == "企畫課成員").First(),
                    Entity = entRepository.Query(q => q.Name == "Admin").First(),
                    Operation = oerRepository.Query(q => q.Comment == "Full Control").First(),
                    Level = 0
                };

                //企畫課長(副課長)可以全權管理Organization
                Permission per5 = new Permission()
                {
                    Party = prtRepository.Query(q => q.Name == "企畫課副主管").First(),
                    Entity = entRepository.Query(q => q.Name == "Organization").First(),
                    Operation = oerRepository.Query(q => q.Comment == "Full Control").First(),
                    Level = 0
                };

                //管理課對Admin下的所有功能只有View
                Permission per6 = new Permission()
                {
                    Organization = orgRepository.Query(q => q.Name == "管理課").First(),
                    Entity = entRepository.Query(q => q.Name == "Admin").First(),
                    Operation = oerRepository.Query(q => q.Comment == "View").First(),
                    Level = 0
                };

                //管理課對Admin下的所有功能只有View,下次要做檢查重複
                //Permission per7 = new Permission()
                //{
                //    Organization = orgRepository.Query(q => q.Name == "管理課").First(),
                //    Entity = entRepository.Query(q => q.Name == "Admin").First(),
                //    Operation = oerRepository.Query(q => q.Comment == "View").First(),
                //    Level = 0
                //};

                //管理課可以全權管理Employees下的基本資料,技能指定,組織設定
                Permission per8 = new Permission()
                {
                    Organization = orgRepository.Query(q => q.Name == "管理課").First(),
                    Entity = entRepository.Query(q => q.Name == "Employees").First(),
                    Operation = oerRepository.Query(q => q.Comment == "Full Control").First(),
                    Level = 0
                };

                //管理課長(副課長)可以查詢員工請假報表
                Permission per9 = new Permission()
                {
                    Party = prtRepository.Query(q => q.Name == "管理課副主管").First(),
                    Entity = entRepository.Query(q => q.Name == "員工請假報表").First(),
                    Operation = oerRepository.Query(q => q.Comment == "Full Control").First(),
                    Level = 0
                };

                //所以理論上管理課長對Report有View的權限
                Permission per10 = new Permission()
                {
                    Party = prtRepository.Query(q => q.Name == "管理課副主管").First(),
                    Entity = entRepository.Query(q => q.Name == "Reports").First(),
                    Operation = oerRepository.Query(q => q.Comment == "View").First(),
                    Level = 0
                };

                //企畫課對Employees下的所有功能只有View
                Permission per11 = new Permission()
                {
                    Organization = orgRepository.Query(q => q.Name == "企畫課").First(),
                    Entity = entRepository.Query(q => q.Name == "Employees").First(),
                    Operation = oerRepository.Query(q => q.Comment == "View").First(),
                    Level = 0
                };

                perRepository.SaveOrUpdate(per1);
                perRepository.SaveOrUpdate(per2);
                perRepository.SaveOrUpdate(per3);
                perRepository.SaveOrUpdate(per4);
                perRepository.SaveOrUpdate(per5);
                perRepository.SaveOrUpdate(per6);
                perRepository.SaveOrUpdate(per8);
                perRepository.SaveOrUpdate(per9);
                perRepository.SaveOrUpdate(per10);
                perRepository.SaveOrUpdate(per11);

                unitwork.SaveChanges();
            }
        }
Example #19
0
        public void TestAddParty()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Post, Guid> postRepository = new Repository<Post, Guid>(store);
                IRepository<PartyHierarchy, Guid> partyHireRepository = new Repository<PartyHierarchy, Guid>(store);

                Post post1 = new Post() { Name = "總經理室主管" };
                Post post2 = new Post() { Name = "總經理室副主管" };
                Post post3 = new Post() { Name = "總經理室秘書" };
                Post post4 = new Post() { Name = "人資部主管" };
                Post post5 = new Post() { Name = "人資部副主管" };
                Post post6 = new Post() { Name = "企畫課主管" };
                Post post7 = new Post() { Name = "企畫課副主管" };
                Post post8 = new Post() { Name = "企畫課成員" };
                Post post9 = new Post() { Name = "管理課主管" };
                Post post10 = new Post() { Name = "管理課副主管" };
                Post post11 = new Post() { Name = "管理課成員" };
                Post post12 = new Post() { Name = "業務部主管" };
                Post post13 = new Post() { Name = "業務部副主管" };
                Post post14 = new Post() { Name = "業務一課主管" };
                Post post15 = new Post() { Name = "業務一課副主管" };
                Post post16 = new Post() { Name = "業務一課成員" };

                postRepository.SaveOrUpdate(post1);
                postRepository.SaveOrUpdate(post2);
                postRepository.SaveOrUpdate(post3);
                postRepository.SaveOrUpdate(post4);
                postRepository.SaveOrUpdate(post5);
                postRepository.SaveOrUpdate(post6);
                postRepository.SaveOrUpdate(post7);
                postRepository.SaveOrUpdate(post8);
                postRepository.SaveOrUpdate(post9);
                postRepository.SaveOrUpdate(post10);
                postRepository.SaveOrUpdate(post11);
                postRepository.SaveOrUpdate(post12);
                postRepository.SaveOrUpdate(post13);
                postRepository.SaveOrUpdate(post14);
                postRepository.SaveOrUpdate(post15);
                postRepository.SaveOrUpdate(post16);

                unitwork.SaveChanges();

                PartyService service = new PartyService(partyHireRepository);
                service.AddAccountability(post1, post2);
                unitwork.SaveChanges();
                service.AddAccountability(post1, post3);
                unitwork.SaveChanges();
                service.AddAccountability(post1, post4);
                unitwork.SaveChanges();
                service.AddAccountability(post1, post12);
                unitwork.SaveChanges();
                service.AddAccountability(post4, post5);
                unitwork.SaveChanges();
                service.AddAccountability(post4, post6);
                unitwork.SaveChanges();
                service.AddAccountability(post4, post9);
                unitwork.SaveChanges();
                service.AddAccountability(post6, post7);
                unitwork.SaveChanges();
                service.AddAccountability(post6, post8);
                unitwork.SaveChanges();
                service.AddAccountability(post9, post10);
                unitwork.SaveChanges();
                service.AddAccountability(post9, post11);
                unitwork.SaveChanges();
                service.AddAccountability(post12, post13);
                unitwork.SaveChanges();
                service.AddAccountability(post12, post14);
                unitwork.SaveChanges();
                service.AddAccountability(post14, post15);
                unitwork.SaveChanges();
                service.AddAccountability(post14, post16);
                unitwork.SaveChanges();
            }
        }
Example #20
0
        public void TestGetParentEntity()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Entity, Guid> repository = new Repository<Entity, Guid>(store);
                repository.Include(i => i.Parent);
                Entity section = repository.Query(q => q.Name == "Section").First() ;

                Assert.IsNotNull(section.Parent);
                Assert.AreEqual("頁面", section.Parent.Name);
            }
        }
Example #21
0
        public void TestGetParentOrganization()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Organization, Guid> organRepository = new Repository<Organization, Guid>(store);
                OrganizationService organizationService = new OrganizationService();

                ICollection<Organization> parents = organizationService.GetParentOrganizations(organRepository.Query(s => s.Name == "人資部").First().Id);
                Assert.AreEqual(1, parents.Count);
                Assert.AreEqual("總經理室", parents.First().Name);
            }
        }
Example #22
0
        public void TestGetAllChildAccountParties()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Party, Guid> partyRepository = new Repository<Party, Guid>(store);
                PartyService partyService = new PartyService();
                Party post = partyRepository.Query(s => s.Name == "總經理室主管").First();
                var posts = partyService.GetAllChildAccountParties(post.Id);

                Assert.AreEqual(1, posts.Count());
            }
        }
Example #23
0
        public void TestSimpleQuery()
        {
            IStore store = new ThreadStaticStore();
            IDbContextFactory contextFactory = new DbContextFactory();

            using (UnitOfWork unitwork = new UnitOfWork(store, contextFactory))
            {
                IRepository<Demo, Guid> demoRepository = new Repository<Demo, Guid>(store);
                IList<Demo> demos = demoRepository.Query(q => q.Name== "A" || q.Name == "B");
                Assert.AreEqual(2, demos.Count());
            }
        }
Example #24
0
        public void TestSpecifications()
        {
            IStore store = new ThreadStaticStore();
            IDbContextFactory contextFactory = new DbContextFactory();
            Specification<Demo> specify =  new Specification<Demo>(o => o.Name == "A");
            Specification<Demo> specify1 = new Specification<Demo>(o => o.Name == "B");
            Specification<Demo> specify2 = specify | specify1;

            using (UnitOfWork unitwork = new UnitOfWork(store, contextFactory))
            {
                IRepository<Demo,Guid> demoRepository = new Repository<Demo,Guid>(store);
                IList<Demo> demos = demoRepository.Query(specify2);
                Assert.AreEqual(2, demos.Count());
            }
        }
Example #25
0
        public void TestAddEntity()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Entity, Guid> repository = new Repository<Entity, Guid>(store);
                Entity entity1 = new Entity() {Name = "Admin"};
                Entity entity2 = new Entity() {Name = "Employees"};
                Entity entity3 = new Entity() {Name = "Reports"};
                Entity entity4 = new Entity() {Name = "Personal Information"};
                Entity entity11 = new Entity() {Name = "Organization"};
                Entity entity12 = new Entity() {Name = "技能設定"};
                Entity entity13 = new Entity() {Name = "職稱設定"};
                Entity entity14 = new Entity() {Name = "假期設定"};
                Entity entity21 = new Entity() {Name = "基本資料"};
                Entity entity22 = new Entity() {Name = "組職設定"};
                Entity entity23 = new Entity() {Name = "技能指定"};
                Entity entity31 = new Entity() {Name = "員工請假報表"};
                Entity entity41 = new Entity() {Name = "基本資訊"};
                Entity entity42 = new Entity() {Name = "請假"};
                Entity entity43 = new Entity() {Name = "打卡資訊"};

                repository.SaveOrUpdate(entity1);
                repository.SaveOrUpdate(entity2);
                repository.SaveOrUpdate(entity3);
                repository.SaveOrUpdate(entity4);
                repository.SaveOrUpdate(entity11);
                repository.SaveOrUpdate(entity12);
                repository.SaveOrUpdate(entity13);
                repository.SaveOrUpdate(entity14);
                repository.SaveOrUpdate(entity21);
                repository.SaveOrUpdate(entity22);
                repository.SaveOrUpdate(entity23);
                repository.SaveOrUpdate(entity31);
                repository.SaveOrUpdate(entity41);
                repository.SaveOrUpdate(entity42);
                repository.SaveOrUpdate(entity43);

                entity1.ChildEntity.Add(entity11);
                entity1.ChildEntity.Add(entity11);
                entity1.ChildEntity.Add(entity12);
                entity1.ChildEntity.Add(entity13);
                entity1.ChildEntity.Add(entity14);
                entity2.ChildEntity.Add(entity21);
                entity2.ChildEntity.Add(entity22);
                entity2.ChildEntity.Add(entity23);
                entity3.ChildEntity.Add(entity31);
                entity4.ChildEntity.Add(entity41);
                entity4.ChildEntity.Add(entity42);
                entity4.ChildEntity.Add(entity43);

                unitwork.SaveChanges();
            }
        }
Example #26
0
        public void TestAddOperation()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Operation, Guid> operationRepository = new Repository<Operation, Guid>(store);
                Operation opr1 = new Operation() { Comment = "Full Control"};
                Operation opr2 = new Operation() { Comment = "Add" };
                Operation opr3 = new Operation() { Comment = "Update" };
                Operation opr4 = new Operation() { Comment = "Delete" };
                Operation opr5 = new Operation() { Comment = "Search" };
                Operation opr6 = new Operation() { Comment = "View" };

                operationRepository.SaveOrUpdate(opr1);
                operationRepository.SaveOrUpdate(opr2);
                operationRepository.SaveOrUpdate(opr3);
                operationRepository.SaveOrUpdate(opr4);
                operationRepository.SaveOrUpdate(opr5);
                operationRepository.SaveOrUpdate(opr6);

                opr1.Children.Add(opr2);
                opr1.Children.Add(opr3);
                opr1.Children.Add(opr4);
                opr1.Children.Add(opr5);
                opr1.Children.Add(opr6);

                unitwork.SaveChanges();
            }
        }
Example #27
0
        public void TestAddOrganization()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Organization, Guid> organRepository = new Repository<Organization, Guid>(store);
                IRepository<OrganizationHierarchy, Guid> organHireRepository = new Repository<OrganizationHierarchy, Guid>(store);

                Organization org1 = new Organization() { Name = "總經理室" };
                Organization org2 = new Organization() { Name = "人資部" };
                Organization org3 = new Organization() { Name = "業務部" };
                Organization org4 = new Organization() { Name = "企畫課" };
                Organization org5 = new Organization() { Name = "管理課" };
                Organization org6 = new Organization() { Name = "業務一課" };
                Organization org7 = new Organization() { Name = "業務二課" };
                Organization org8 = new Organization() { Name = "業務三課" };

                organRepository.SaveOrUpdate(org1);
                organRepository.SaveOrUpdate(org2);
                organRepository.SaveOrUpdate(org3);
                organRepository.SaveOrUpdate(org4);
                organRepository.SaveOrUpdate(org5);
                organRepository.SaveOrUpdate(org6);
                organRepository.SaveOrUpdate(org7);
                organRepository.SaveOrUpdate(org8);

                unitwork.SaveChanges();

                OrganizationService service = new OrganizationService(organHireRepository);
                service.AddOrganizationHierarchy(org1, org2, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(org1, org3, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(org2, org4, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(org2, org5, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(org3, org6, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(org3, org7, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
                service.AddOrganizationHierarchy(org3, org8, OrganizationHierarchyType.AM);
                unitwork.SaveChanges();
            }
        }
Example #28
0
        public void TestGetData()
        {
            IStore store = new ThreadStaticStore();
            IDbContextFactory contextFactory = new DbContextFactory();

            using (UnitOfWork unitwork = new UnitOfWork(store, contextFactory))
            {
                IRepository<Demo,Guid> demoRepository = new Repository<Demo,Guid>(store);
                var list = demoRepository.GetAll();
                Assert.AreEqual(1, list.Count);
            }
        }
Example #29
0
        public void TestGetEmployeesOfPost()
        {
            using (UnitOfWork unitwork = new UnitOfWork(store, dbContextFactory))
            {
                IRepository<Party, Guid> partyRepository = new Repository<Party, Guid>(store);
                PartyService partyService = new PartyService();
                Party post = partyRepository.Query(s => s.Name == "總經理室主管").First();
                var employees = partyService.GetEmployeesIn(post.Id);

                Assert.AreEqual(1, employees.Count());
            }
        }