Exemple #1
0
        public When_OpportunityService_Is_Called_To_Update_ProvisionGap()
        {
            var httpContextAccessor = Substitute.For <IHttpContextAccessor>();

            httpContextAccessor.HttpContext.Returns(new DefaultHttpContext
            {
                User = new ClaimsPrincipal(new ClaimsIdentity(new[]
                {
                    new Claim(ClaimTypes.GivenName, "adminUserName")
                }))
            });

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

            var mapper = new Mapper(config);

            var opportunityRepository     = Substitute.For <IOpportunityRepository>();
            var opportunityItemRepository = Substitute.For <IRepository <OpportunityItem> >();

            _provisionGapRepository = Substitute.For <IRepository <ProvisionGap> >();
            var referralRepository = Substitute.For <IRepository <Domain.Models.Referral> >();
            var googleMapApiClient = Substitute.For <IGoogleMapApiClient>();
            var opportunityPipelineReportWriter = Substitute.For <IFileWriter <OpportunityReportDto> >();
            var dateTimeProvider = Substitute.For <IDateTimeProvider>();

            _provisionGapRepository
            .GetSingleOrDefaultAsync(Arg.Any <Expression <Func <ProvisionGap, bool> > >())
            .Returns(new ValidProvisionGapBuilder().Build());

            var opportunityService = new OpportunityService(mapper, opportunityRepository, opportunityItemRepository,
                                                            _provisionGapRepository, referralRepository, googleMapApiClient,
                                                            opportunityPipelineReportWriter, dateTimeProvider);

            var dto = new PlacementInformationSaveDto
            {
                OpportunityId             = 1,
                OpportunityItemId         = 1,
                OpportunityType           = OpportunityType.ProvisionGap,
                SearchResultProviderCount = 0,
                JobRole             = "Junior Tester",
                PlacementsKnown     = false,
                NoSuitableStudent   = true,
                HadBadExperience    = true,
                ProvidersTooFarAway = true,
                ModifiedBy          = "TestUser",
                ModifiedOn          = new DateTime(2019, 1, 1)
            };

            opportunityService.UpdateProvisionGapAsync(dto).GetAwaiter().GetResult();
        }