public static async Task SetTestData(MatchingDbContext dbContext, Provider provider, ProviderVenue venue, Opportunity opportunity, BackgroundProcessHistory backgroundProcessHistory, bool isSaved = true, bool isSelectedForReferral = true) { backgroundProcessHistory.Status = BackgroundProcessHistoryStatus.Pending.ToString(); await dbContext.AddAsync(provider); await dbContext.AddAsync(venue); await dbContext.AddAsync(opportunity); await dbContext.AddAsync(backgroundProcessHistory); await dbContext.SaveChangesAsync(); dbContext.DetachAllEntities(); var items = dbContext.OpportunityItem .AsNoTracking() .Where(oi => oi.OpportunityId == opportunity.Id) .ToList(); foreach (var opportunityItem in items) { opportunityItem.IsSaved = isSaved; opportunityItem.IsCompleted = false; opportunityItem.OpportunityType = "Referral"; opportunityItem.IsSelectedForReferral = isSelectedForReferral; dbContext.Entry(opportunityItem).Property("IsSaved").IsModified = true; dbContext.Entry(opportunityItem).Property("IsCompleted").IsModified = true; dbContext.Entry(opportunityItem).Property("IsSelectedForReferral").IsModified = true; dbContext.Entry(opportunityItem).Property("OpportunityType").IsModified = true; } await dbContext.SaveChangesAsync(); dbContext.DetachAllEntities(); }
public static async Task SetEmailTemplate( MatchingDbContext dbContext, EmailTemplate emailTemplate) { await dbContext.AddAsync(emailTemplate); await dbContext.SaveChangesAsync(); dbContext.DetachAllEntities(); }
public static async Task SetEmailHistory( MatchingDbContext dbContext, EmailHistory emailHistory) { emailHistory.Status = null; emailHistory.ModifiedBy = null; emailHistory.ModifiedOn = null; await dbContext.AddAsync(emailHistory); await dbContext.SaveChangesAsync(); dbContext.DetachAllEntities(); }
public virtual async Task <int> CreateAsync(T entity) { await _dbContext.AddAsync(entity); try { await _dbContext.SaveChangesAsync(); } catch (DbUpdateException due) { _logger.LogError(due.Message, due.InnerException); throw; } return(entity.Id); }
public async Task Then_Make_TLevel_Provider_Flag_To_True( MatchingDbContext dbContext, Domain.Models.Provider provider, List <ProviderVenueViewModel> venueViewModels, MatchingConfiguration config, ILogger <GenericRepository <Domain.Models.Provider> > providerLogger, ILogger <GenericRepository <ProviderReference> > providerReferenceLogger, IHttpContextAccessor httpContextAccessor, IDateTimeProvider dateTimeProvider ) { //Arrange provider.IsTLevelProvider = false; await dbContext.AddAsync(provider); await dbContext.SaveChangesAsync(); dbContext.Entry(provider).State = EntityState.Detached; var viewModel = new ProviderDetailViewModel { Id = provider.Id, IsTLevelProvider = true, ProviderVenues = venueViewModels }; httpContextAccessor.HttpContext.Returns(new DefaultHttpContext { User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.GivenName, "System") })) }); var mapperConfig = new MapperConfiguration(c => { c.AddMaps(typeof(ProviderMapper).Assembly); c.ConstructServicesUsing(type => type.Name.Contains("LoggedInUserNameResolver") ? (object)new LoggedInUserNameResolver <ProviderDetailViewModel, Domain.Models.Provider>(httpContextAccessor) : type.Name.Contains("UtcNowResolver") ? new UtcNowResolver <ProviderDetailViewModel, Domain.Models.Provider>(dateTimeProvider) : null); }); var mapper = new Mapper(mapperConfig); var providerReferenceRepo = new GenericRepository <ProviderReference>(providerReferenceLogger, dbContext); var repo = new GenericRepository <Domain.Models.Provider>(providerLogger, dbContext); var providerService = new ProviderService(mapper, repo, providerReferenceRepo); var sut = new ProviderController(providerService, config); //Act await sut.SaveProviderDetailAsync(viewModel); //Assert var result = await repo.GetSingleOrDefaultAsync(x => x.Id == provider.Id); provider.IsTLevelProvider.Should().BeFalse(); result.IsTLevelProvider.Should().BeTrue(); }