public void When_CreateAdminUser_Then_root_site_for_users_company_is_retrieved_from_site_repository()
        {
            // Given
            const long clientId = 1234L;
            var request = new CreateAdminUserRequest()
                          {
                              ClientId = clientId
                          };
            var target = GetTarget();

            // When
            target.CreateAdminUser(request);

            // Then
            _siteRepo.Verify(x => x.GetRootSiteByCompanyId(clientId));
        }
        public void When_CreateAdminUser_Then_systemUser_is_retrieved_from_user_repository()
        {
            // Given
            const long clientId = 1234L;
            var request = new CreateAdminUserRequest()
            {
                ClientId = clientId
            };
            var target = GetTarget();

            // When
            target.CreateAdminUser(request);

            // Then
            _userForAuditingRepo.Verify(x => x.GetSystemUser());
        }
Пример #3
0
        public void CreateAdminUser(CreateAdminUserRequest request)
        {
            _log.Add();

            var systemUser = _auditedUserRepository.GetSystemUser();
            var site = _siteRepository.GetRootSiteByCompanyId(request.ClientId);
            var role = _roleRepository.GetAdminRole();

            var employee = Employee.Create(new AddUpdateEmployeeParameters
                {
                    ClientId = request.ClientId,
                    Forename = request.Forename,
                    Surname = request.Surname,
                    Site = site.Self as Site
                }, systemUser);

            var contactDetails = EmployeeContactDetail.Create(new AddUpdateEmployeeContactDetailsParameters { Email = request.Email }, systemUser, employee);
            employee.AddContactDetails(contactDetails);
            var user = _userRepository.GetById(request.UserId) ?? User.CreateUser(request.UserId, request.ClientId, role, site, employee, systemUser);
            _userRepository.Save(user);
        }
        public void When_CreateAdminUser_Then_admin_role_is_retrieved_from_role_repository()
        {
            // Given
            const long clientId = 1234L;
            var request = new CreateAdminUserRequest()
            {
                ClientId = clientId
            };
            var target = GetTarget();

            // When
            target.CreateAdminUser(request);

            // Then
            _roleRepo.Verify(x => x.GetAdminRole());
        }
        public void When_CreateAdminUser_Then_new_employee_is_created()
        {
            // Given
            var userId = Guid.NewGuid();
            const long companyId = 1234L;
            var request = new CreateAdminUserRequest()
            {
                ClientId = companyId,
                UserId = userId,
                Forename = "Maggie",
                Surname = "May",
                Email = "*****@*****.**"
            };

            User createdUser = null;
            _userRepo.Setup(x => x.Save(It.IsAny<User>()))
                .Callback<User>(x => createdUser = x);


            var target = GetTarget();

            // When
            target.CreateAdminUser(request);

            // Then
            Assert.IsNotNull(createdUser.Employee);
            Assert.AreEqual(request.Forename, createdUser.Employee.Forename);
            Assert.AreEqual(request.Surname, createdUser.Employee.Surname);
            Assert.AreEqual(request.Email, createdUser.Employee.ContactDetails.First().Email);
            
        }
        public void When_CreateAdminUser_Then_new_user_is_saved_to_user_repository()
        {
            // Given
            var userId = Guid.NewGuid();
            var companyId = 1234L;
            var request = new CreateAdminUserRequest()
            {
                ClientId = companyId,
                UserId = userId
            };
            var expectedUser = new User()
                               {
                                   Id = userId,
                                   CompanyId = companyId,
                                   Role = _adminRole,
                                   Site = _rootSite,
                                   CreatedBy = _nsbSystemUser
                               };
            var target = GetTarget();

            // When
            target.CreateAdminUser(request);

            // Then
            _userRepo.Verify(x => x.Save(expectedUser));
        }