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

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

            var dateTimeProvider = Substitute.For <IDateTimeProvider>();

            dateTimeProvider.UtcNow().Returns(new DateTime(2019, 1, 1));

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

            var opportunityRepository  = Substitute.For <IOpportunityRepository>();
            var provisionGapRepository = Substitute.For <IRepository <ProvisionGap> >();
            var referralRepository     = Substitute.For <IRepository <Domain.Models.Referral> >();

            _opportunityItemRepository = Substitute.For <IRepository <OpportunityItem> >();
            _opportunityItemRepository
            .GetManyAsync(Arg.Any <Expression <Func <OpportunityItem, bool> > >())
            .Returns(new OpportunityItemListBuilder().Build().AsQueryable());

            var googleMapApiClient = Substitute.For <IGoogleMapApiClient>();
            var opportunityPipelineReportWriter = Substitute.For <IFileWriter <OpportunityReportDto> >();

            var opportunityService = new OpportunityService(mapper, opportunityRepository, _opportunityItemRepository,
                                                            provisionGapRepository, referralRepository, googleMapApiClient,
                                                            opportunityPipelineReportWriter, dateTimeProvider);

            opportunityService.ClearOpportunityItemsSelectedForReferralAsync(OpportunityId).GetAwaiter().GetResult();
        }