private async Task ValidateAsync(FindEmployerViewModel viewModel, string currentUser)
        {
            var isValidEmployer =
                await _employerService.ValidateCompanyNameAndCrmIdAsync(viewModel.SelectedEmployerCrmId, viewModel.CompanyName);

            if (!isValidEmployer)
            {
                ModelState.AddModelError(nameof(viewModel.CompanyName), "You must find and choose an employer");
            }
            else
            {
                var lockedByUser = await _employerService
                                   .GetEmployerOpportunityOwnerAsync(viewModel.SelectedEmployerCrmId);

                if (!string.IsNullOrEmpty(lockedByUser))
                {
                    if (lockedByUser == currentUser)
                    {
                        ModelState.AddModelError(nameof(viewModel.CompanyName),
                                                 "You are already working on this employer’s opportunities. Please start again and find this employer in your saved opportunities.");
                    }
                    else
                    {
                        ModelState.AddModelError(nameof(viewModel.CompanyName),
                                                 "Your colleague, " + $"{lockedByUser}, is already working on this employer’s opportunities. " +
                                                 "Please choose a different employer.");
                    }
                }
            }
        }
        public When_Employer_SaveOpportunityCompanyName_Is_Submitted_Successfully()
        {
            _viewModel.OpportunityId = OpportunityId;
            _viewModel.OpportunityItemId = OpportunityItemId;
            _viewModel.CompanyName = CompanyName;
            _viewModel.SelectedEmployerCrmId = new Guid("33333333-3333-3333-3333-333333333333");

            _employerService = Substitute.For<IEmployerService>();
            _employerService.ValidateCompanyNameAndCrmIdAsync(_employerCrmId, CompanyName).Returns(true);
            _employerService.GetEmployerOpportunityOwnerAsync(Arg.Any<Guid>())
                .Returns((string)null);

            _opportunityService = Substitute.For<IOpportunityService>();
            var referralService = Substitute.For<IReferralService>();

            var httpContextAccessor = Substitute.For<IHttpContextAccessor>();

            var config = new MapperConfiguration(c =>
            {
                c.AddMaps(typeof(EmployerDtoMapper).Assembly);
                c.ConstructServicesUsing(type =>
                    type.Name.Contains("LoggedInUserEmailResolver") ?
                        new LoggedInUserEmailResolver<FindEmployerViewModel, CompanyNameDto>(httpContextAccessor) :
                            type.Name.Contains("LoggedInUserNameResolver") ?
                                (object)new LoggedInUserNameResolver<FindEmployerViewModel, CompanyNameDto>(httpContextAccessor) :
                                    type.Name.Contains("UtcNowResolver") ?
                                        new UtcNowResolver<FindEmployerViewModel, CompanyNameDto>(new DateTimeProvider()) :
                                            null);
            });

            var mapper = new Mapper(config);

            var employerController = new EmployerController(_employerService, _opportunityService, referralService, mapper);
            var controllerWithClaims = new ClaimsBuilder<EmployerController>(employerController)
                .AddUserName(ModifiedBy)
                .Build();

            httpContextAccessor.HttpContext.Returns(controllerWithClaims.HttpContext);

            _result = controllerWithClaims.SaveOpportunityCompanyNameAsync(_viewModel).GetAwaiter().GetResult();
        }