Beispiel #1
0
        public When_Employer_SaveOpportunityCompanyName_Is_Submitted_Invalid_Employer()
        {
            var employerService = Substitute.For <IEmployerService>();

            employerService.ValidateCompanyNameAndCrmIdAsync(Arg.Any <Guid>(), Arg.Any <string>())
            .Returns(false);
            var opportunityService = Substitute.For <IOpportunityService>();

            var viewModel = new FindEmployerViewModel
            {
                CompanyName = "Invalid Business Name"
            };

            var config          = new MapperConfiguration(c => c.AddMaps(typeof(EmployerMapper).Assembly));
            var referralService = Substitute.For <IReferralService>();
            var mapper          = new Mapper(config);

            var employerController = new EmployerController(employerService, opportunityService, referralService, mapper);

            _employerController = new ClaimsBuilder <EmployerController>(employerController)
                                  .Add(ClaimTypes.Role, RolesExtensions.StandardUser)
                                  .AddUserName("Username")
                                  .Build();

            _result = _employerController.SaveOpportunityCompanyNameAsync(viewModel).GetAwaiter().GetResult();
        }
        public void Then_View_Result_Is_Returned_With_Model_State_Error_For_CompanyName(string companyName)
        {
            var result = _employerController.SaveOpportunityCompanyNameAsync(new FindEmployerViewModel {
                CompanyName = companyName, SelectedEmployerCrmId = new Guid("11111111-1111-1111-1111-111111111111")
            }).GetAwaiter().GetResult();

            result.Should().BeAssignableTo <ViewResult>();
            _employerController.ViewData.ModelState.Should().ContainSingle();
            _employerController.ViewData.ModelState.ContainsKey(nameof(FindEmployerViewModel.CompanyName)).Should().BeTrue();
            var modelStateEntry = _employerController.ViewData.ModelState[nameof(FindEmployerViewModel.CompanyName)];

            modelStateEntry.Errors[0].ErrorMessage.Should().Be("You must find and choose an employer");
        }