Example #1
0
        public void GetSharedInfoDto()
        {
            IEnumerable <DepartmentDto> department = new[] { new DepartmentDto {
                                                                 DepartmentDtoId = 1
                                                             } };
            IEnumerable <CategoryDto> category = new[] { new CategoryDto {
                                                             CategoryDtoId = 1
                                                         } };
            IEnumerable <PositionDto> position = new[] { new PositionDto {
                                                             PositionDtoId = 1
                                                         } };
            IEnumerable <PositionLevelDto> positionLevel = new[] { new PositionLevelDto {
                                                                       PositionLevelDtoId = 1
                                                                   } };
            IEnumerable <RoleDto> role = new[] { new RoleDto {
                                                     RoleDtoId = 1
                                                 } };

            var expectedDepartmentIds    = new[] { 1 };
            var expectedCategoryIds      = new[] { 1 };
            var expectedPositionIds      = new[] { 1 };
            var expectedPositionLevelIds = new[] { 1 };
            var expectedRoleIds          = new[] { 1 };

            A.CallTo(() => _department.GetAll <DepartmentDto>()).Returns(department);
            A.CallTo(() => _category.GetAll <CategoryDto>()).Returns(category);
            A.CallTo(() => _position.GetAll <PositionDto>()).Returns(position);
            A.CallTo(() => _positionLevel.GetAll <PositionLevelDto>()).Returns(positionLevel);
            A.CallTo(() => _role.GetAll <RoleDto>()).Returns(role);

            var sharedInfo = _upsertUserService.GetSharedInfoDto();

            for (var i = 0; i < expectedDepartmentIds.Length; i++)
            {
                Assert.Equal((sharedInfo.DepartmentDtos.ToList())[i].DepartmentDtoId, expectedDepartmentIds[i]);
            }

            for (var i = 0; i < expectedCategoryIds.Length; i++)
            {
                Assert.Equal((sharedInfo.CategoryDtos.ToList())[i].CategoryDtoId, expectedCategoryIds[i]);
            }

            for (var i = 0; i < expectedPositionIds.Length; i++)
            {
                Assert.Equal((sharedInfo.PositionDtos.ToList())[i].PositionDtoId, expectedPositionIds[i]);
            }

            for (var i = 0; i < expectedPositionLevelIds.Length; i++)
            {
                Assert.Equal((sharedInfo.PositionLevelDtos.ToList())[i].PositionLevelDtoId, expectedPositionLevelIds[i]);
            }

            for (var i = 0; i < expectedRoleIds.Length; i++)
            {
                Assert.Equal((sharedInfo.RoleDtos.ToList())[i].RoleDtoId, expectedRoleIds[i]);
            }
        }
        public ActionResult UpdateUser(int userId)
        {
            var info              = _upsertUserService.GetSharedInfoDto();
            var departmentList    = new SelectList(info.DepartmentDtos, "DepartmentDtoId", "Name");
            var categoryList      = new SelectList(info.CategoryDtos, "CategoryDtoId", "Name");
            var positionList      = new SelectList(info.PositionDtos, "PositionDtoId", "Name");
            var positionLevelList = new SelectList(info.PositionLevelDtos, "PositionLevelDtoId", "Name");
            var roleList          = new SelectList(info.RoleDtos, "RoleDtoId", "Name");

            ViewBag.Departments   = departmentList;
            ViewBag.Category      = categoryList;
            ViewBag.Position      = positionList;
            ViewBag.PositionLevel = positionLevelList;
            ViewBag.Role          = roleList;
            var user = Mapper.Map <UserDto, UpsertUser>(_service.GetById(userId));

            return(View("UpsertUser", user));
        }