public When_OpportunityItemRepository_CreateMany_Is_Called()
        {
            var logger = Substitute.For <ILogger <GenericRepository <Domain.Models.OpportunityItem> > >();

            using var dbContext = InMemoryDbContext.Create();
            var data = new ValidOpportunityItemListBuilder().Build();

            var repository = new GenericRepository <Domain.Models.OpportunityItem>(logger, dbContext);

            _result = repository.CreateManyAsync(data)
                      .GetAwaiter().GetResult();
        }
Exemplo n.º 2
0
        public When_ReferralEmailService_Is_Called_To_Send_Multiple_Provider_Emails_And_No_Remaining_Referrals_With_ProvisionGaps()
        {
            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 backgroundProcessHistoryRepo = Substitute.For <IRepository <BackgroundProcessHistory> >();
            var emailService    = Substitute.For <IEmailService>();
            var opportunityRepo = Substitute.For <IOpportunityRepository>();

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

            var opportunityItems = new ValidOpportunityItemListBuilder().Build();

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

            opportunityRepo.GetProviderReferralsAsync(Arg.Any <int>(), Arg.Any <IEnumerable <int> >())
            .Returns(new ValidOpportunityReferralDtoListBuilder()
                     .BuildWithMultipleReferrals());

            backgroundProcessHistoryRepo.GetSingleOrDefaultAsync(Arg.Any <Expression <Func <BackgroundProcessHistory, bool> > >()).Returns(new BackgroundProcessHistory
            {
                Id     = 1,
                Status = BackgroundProcessHistoryStatus.Pending.ToString()
            });

            var functionLogRepository = Substitute.For <IRepository <FunctionLog> >();

            var itemIds = opportunityItems
                          .Where(oi => oi.IsSaved && oi.IsSelectedForReferral)
                          .Select(oi => oi.Id)
                          .ToList();

            var referralService = new ReferralEmailService(mapper, dateTimeProvider, emailService,
                                                           opportunityRepo, _opportunityItemRepository, backgroundProcessHistoryRepo, functionLogRepository);

            referralService.SendProviderReferralEmailAsync(1, itemIds, 1, httpContextAccessor.HttpContext.User.GetUserName()).GetAwaiter().GetResult();
        }