public async Task AddBasketChangeEvent(BasketChangeEvent basketChangeEvent) { await using (var marketingDbContext = new MarketingDbContext(dbContextOptions)) { await marketingDbContext.BasketChangeEvents.AddAsync(basketChangeEvent); await marketingDbContext.SaveChangesAsync(); } }
private static MarketingDbContext MarketingDbContext() { var options = new DbContextOptionsBuilder <MarketingDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .EnableSensitiveDataLogging() .Options; var context = new MarketingDbContext(options); return(context); }
public void InsertTestDataToDb(MarketingDbContext db) { if (db.Advertisings.Any()) { return; } var advertisings = _testAdvertising.Generate(30); db.Advertisings.AddRange(advertisings); db.SaveChanges(); }
public async Task AdvertisingNotFound(MarketingDbContext db) { //arrange var id = _advertisingData.GetNoneExistingAdvertisingId(db); var token = _advertisingData.GetRandomToken(); //act var result = await Controller.GetById(id, token); //assert result.Result.Should().BeOfType <NotFoundResult>(); }
public Advertising GetRandomAdvertising(MarketingDbContext db) { var advertisings = db.Advertisings.ToArray(); var ad = advertisings.OrderBy(_ => Guid.NewGuid()).FirstOrDefault(); if (ad == null) { ad = _testAdvertising.Generate(1).FirstOrDefault(); db.Advertisings.Add(ad); db.SaveChanges(); } return(ad); }
public async Task AdvertisingShouldGetEntitesByIdandToken(MarketingDbContext db) { //arrange var ad = _advertisingData.GetRandomAdvertising(db); //act var result = await Controller.GetById(ad.AdvertisingId, ad.Token); //assert var advertising = result.ToModel <AdvertisingBase, OkObjectResult>(); advertising.AdvertisingId.Should().Be(ad.AdvertisingId); advertising.Token.Should().Be(ad.Token); }
public static void Initialize(MarketingDbContext context) { context.Database.EnsureCreated(); if (context.Advertisements.Any()) { return; } var advertisement = new Advertisement { Name = "New product", ClientId = 123 }; context.Advertisements.Add(advertisement); context.SaveChanges(); var digitalChannel = new Channel { Name = "Facebook", IsDigital = true }; var physicalChannel = new Channel { Name = "Magazine", IsDigital = false }; context.Channels.AddRange(new List <Channel> { digitalChannel, physicalChannel }); context.SaveChanges(); var advertisementChannels = new List <AdvertisementChannel> { new AdvertisementChannel { AdvertisementId = advertisement.Id, ChannelId = digitalChannel.Id }, new AdvertisementChannel { AdvertisementId = advertisement.Id, ChannelId = physicalChannel.Id } }; context.AdvertisementChannels.AddRange(advertisementChannels); context.SaveChanges(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure( IApplicationBuilder app, IHostingEnvironment env, AppContext appContext, BankingDbContext bankingDbContext, MarketingDbContext marketingDbContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); appContext.Seed().Wait(); // Normally I shouldn't need these extra Seed methods // But somehow UseInMemoryDatabase won't let me share data across contexts bankingDbContext.Seed().Wait(); marketingDbContext.Seed().Wait(); }
public int GetNoneExistingAdvertisingId(MarketingDbContext db) { return(db.Advertisings.Max(x => x.AdvertisingId) + 100); }
public BidRepository(MarketingDbContext marketingDbContext) { _marketingDbContext = marketingDbContext; }
public ChannelRepositoryTests(ClassTestFixture testFixture) { _dbContext = testFixture.Context; _channelRepository = new ChannelRepository(_dbContext, new ChannelMapper()); _fixture = new Fixture(); }
public PublishingService(IMapper mapper, MarketingDbContext db) { _mapper = mapper; _db = db; }
public BaseRepository(MarketingDbContext context) { this.context = context; }
public BankRepository(MarketingDbContext marketingDbContext) { _marketingDbContext = marketingDbContext; InitializeAsync(); }
public ChannelService(IMapper mapper, MarketingDbContext db) { _mapper = mapper; _db = db; }
public ChannelRepository(MarketingDbContext context, IChannelMapper mapper) { _context = context; _mapper = mapper; }
public AdvertisingService(IMapper mapper, MarketingDbContext db) { _mapper = mapper; _db = db; }
public Handler(MarketingDbContext context) { _context = context; }
public ApplicationRepository(MarketingDbContext marketingDbContext) { _marketingDbContext = marketingDbContext; InitializeAsync(); }
public AdvertisementRepositoryTests(ClassTestFixture testFixture) { _dbContext = testFixture.Context; _advertisementRepository = new AdvertisementRepository(_dbContext, new AdvertisementMapper()); _fixture = new Fixture(); }
public AdvertisementRepository(MarketingDbContext context, IAdvertisementMapper mapper) { _context = context; _mapper = mapper; }