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

            employerService.ValidateCompanyNameAndCrmIdAsync(Arg.Any <Guid>(), Arg.Any <string>())
            .Returns(true);
            employerService.GetEmployerOpportunityOwnerAsync(Arg.Any <Guid>())
            .Returns("Another User");
            var opportunityService = Substitute.For <IOpportunityService>();
            var referralService    = Substitute.For <IReferralService>();

            var viewModel = new FindEmployerViewModel
            {
                OpportunityId = 1,
                CompanyName   = "Company Name"
            };

            var config = new MapperConfiguration(c => c.AddMaps(typeof(EmployerMapper).Assembly));
            var mapper = new Mapper(config);

            _employerController = new EmployerController(employerService, opportunityService, referralService, mapper);
            var controllerWithClaims = new ClaimsBuilder <EmployerController>(_employerController)
                                       .Add(ClaimTypes.Role, RolesExtensions.StandardUser)
                                       .AddUserName("Current User")
                                       .Build();

            _result = controllerWithClaims.SaveOpportunityCompanyNameAsync(viewModel).GetAwaiter().GetResult();
        }
        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();
        }