Example #1
0
 //最多设置两级部门名称
 private void SetDepartmentNames(EmployeeListOutput s, EmployeeListVm d)
 {
     d.DepartmentNames = new List <string>();
     if (_departmentListCache.ContainsKey(s.PrimaryDepartmentId))
     {
         var item = _departmentListCache[s.PrimaryDepartmentId];
         d.DepartmentNames.Add(item.Name);
         if (item.ParentId.HasValue && _departmentListCache.ContainsKey(item.ParentId.Value))
         {
             d.DepartmentNames.Add(_departmentListCache[item.ParentId.Value].Name);
         }
     }
 }
Example #2
0
        public async Task TestGetMy()
        {
            var dep0 = new DepartmentListOutput
            {
                Id   = Guid.NewGuid(),
                Name = "sclq",
            };
            var dep1 = new DepartmentListOutput
            {
                Id       = Guid.NewGuid(),
                Name     = "sclq-jt",
                ParentId = dep0.Id,
            };
            var dep2 = new DepartmentListOutput
            {
                Id       = Guid.NewGuid(),
                Name     = "sclq-gs",
                ParentId = dep0.Id,
            };
            var pos1 = new PositionListOutput
            {
                Id           = Guid.NewGuid(),
                Name         = "pos1",
                DepartmentId = dep1.Id,
            };
            var pos2 = new PositionListOutput
            {
                Id           = Guid.NewGuid(),
                Name         = "pos2",
                DepartmentId = dep2.Id,
            };
            var emp0 = new EmployeeListOutput
            {
                Id   = Guid.NewGuid(),
                Name = "aaa",
                PrimaryDepartmentId = dep1.Id,
                PrimaryPositionId   = pos1.Id,
            };
            var emp1 = new EmployeeListOutput
            {
                Id   = Guid.NewGuid(),
                Name = "aabb",
                PrimaryDepartmentId = dep1.Id,
                PrimaryPositionId   = pos1.Id,
            };
            var emp2 = new EmployeeListOutput
            {
                Id   = Guid.NewGuid(),
                Name = "bbcc",
                PrimaryDepartmentId = dep2.Id,
                PrimaryPositionId   = pos2.Id,
            };

            var departmentAppService = Substitute.For <IDepartmentAppService>();

            departmentAppService.GetAllListAsync()
            .Returns(Task.FromResult((new[] { dep0, dep1, dep2 }).ToList()));

            var positionAppService = Substitute.For <IPositionAppService>();

            positionAppService.GetAllListAsync()
            .Returns(Task.FromResult((new[] { pos1, pos2 }).ToList()));

            var employeeIds        = new[] { emp0.Id, emp1.Id, emp2.Id };
            var employeeAppService = Substitute.For <IEmployeeAppService>();

            employeeAppService.GetListByIdsAsync(employeeIds)
            .Returns(Task.FromResult((new[] { emp0, emp1, emp2 }).ToList()));

            var userFavoriteAppService = Substitute.For <IUserFavoriteAppService>();

            userFavoriteAppService.GetEmployeesAsync(User_Id)
            .Returns(Task.FromResult(employeeIds));

            var target = new EmployeeController(
                CreateMemoryCache(),
                CreateMapper(),
                departmentAppService,
                positionAppService,
                employeeAppService,
                Substitute.For <IGroupAppService>(),
                _ => userFavoriteAppService,
                _ => Substitute.For <IUserSettingAppService>());

            target.ControllerContext = CreateMockContext();

            var result = await target.GetMy();

            var data = result.Value;

            data.Count.Should().Be(3);
        }
Example #3
0
        public async Task TestSearch()
        {
            var dep0 = new DepartmentListOutput
            {
                Id   = Guid.NewGuid(),
                Name = "sclq",
            };
            var dep1 = new DepartmentListOutput
            {
                Id       = Guid.NewGuid(),
                Name     = "sclq-jt",
                ParentId = dep0.Id,
            };
            var dep2 = new DepartmentListOutput
            {
                Id       = Guid.NewGuid(),
                Name     = "sclq-gs",
                ParentId = dep0.Id,
            };
            var pos1 = new PositionListOutput
            {
                Id           = Guid.NewGuid(),
                Name         = "pos1",
                DepartmentId = dep1.Id,
            };
            var pos2 = new PositionListOutput
            {
                Id           = Guid.NewGuid(),
                Name         = "pos2",
                DepartmentId = dep2.Id,
            };
            var emp0 = new EmployeeListOutput
            {
                Id   = Guid.NewGuid(),
                Name = "aaa",
                PrimaryDepartmentId = dep1.Id,
                PrimaryPositionId   = pos1.Id,
            };
            var emp1 = new EmployeeListOutput
            {
                Id   = Guid.NewGuid(),
                Name = "aabb",
                PrimaryDepartmentId = dep1.Id,
                PrimaryPositionId   = pos1.Id,
            };
            var emp2 = new EmployeeListOutput
            {
                Id   = Guid.NewGuid(),
                Name = "bbcc",
                PrimaryDepartmentId = dep2.Id,
                PrimaryPositionId   = pos2.Id,
            };

            var departmentAppService = Substitute.For <IDepartmentAppService>();

            departmentAppService.GetAllListAsync()
            .Returns(Task.FromResult((new[] { dep0, dep1, dep2 }).ToList()));

            var positionAppService = Substitute.For <IPositionAppService>();

            positionAppService.GetAllListAsync()
            .Returns(Task.FromResult((new[] { pos1, pos2 }).ToList()));

            var employeeAppService = Substitute.For <IEmployeeAppService>();

            employeeAppService.SearchByKeywordAsync("aa")
            .Returns(Task.FromResult((new[] { emp0, emp1 }).ToList()));
            employeeAppService.SearchByKeywordAsync("bb")
            .Returns(Task.FromResult((new[] { emp1, emp2 }).ToList()));

            var target = new EmployeeController(
                CreateMemoryCache(),
                CreateMapper(),
                departmentAppService,
                positionAppService,
                employeeAppService,
                Substitute.For <IGroupAppService>(),
                _ => Substitute.For <IUserFavoriteAppService>(),
                _ => Substitute.For <IUserSettingAppService>());

            var result = await target.Search("aa");

            var data = result.Value;

            data.Count.Should().Be(2);
            data[0].Id.Should().Be(emp0.Id);
            data[0].PositionName.Should().Be(pos1.Name);
            data[0].DepartmentNames.Count.Should().Be(2);
            data[0].DepartmentNames[0].Should().Be(dep1.Name);
            data[0].DepartmentNames[1].Should().Be(dep0.Name);

            result = await target.Search("bb");

            data = result.Value;
            data.Count.Should().Be(2);
            data[1].Id.Should().Be(emp2.Id);
            data[1].PositionName.Should().Be(pos2.Name);
            data[1].DepartmentNames.Count.Should().Be(2);
            data[1].DepartmentNames[0].Should().Be(dep2.Name);
            data[1].DepartmentNames[1].Should().Be(dep0.Name);
        }