コード例 #1
0
        public async Task AddBasketChangeEvent(BasketChangeEvent basketChangeEvent)
        {
            await using (var marketingDbContext = new MarketingDbContext(dbContextOptions))
            {
                await marketingDbContext.BasketChangeEvents.AddAsync(basketChangeEvent);

                await marketingDbContext.SaveChangesAsync();
            }
        }
コード例 #2
0
        private static MarketingDbContext MarketingDbContext()
        {
            var options = new DbContextOptionsBuilder <MarketingDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .EnableSensitiveDataLogging()
                          .Options;
            var context = new MarketingDbContext(options);

            return(context);
        }
コード例 #3
0
        public void InsertTestDataToDb(MarketingDbContext db)
        {
            if (db.Advertisings.Any())
            {
                return;
            }

            var advertisings = _testAdvertising.Generate(30);

            db.Advertisings.AddRange(advertisings);
            db.SaveChanges();
        }
コード例 #4
0
        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>();
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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();
        }
コード例 #8
0
        // 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();
        }
コード例 #9
0
 public int GetNoneExistingAdvertisingId(MarketingDbContext db)
 {
     return(db.Advertisings.Max(x => x.AdvertisingId) + 100);
 }
コード例 #10
0
 public BidRepository(MarketingDbContext marketingDbContext)
 {
     _marketingDbContext = marketingDbContext;
 }
コード例 #11
0
 public ChannelRepositoryTests(ClassTestFixture testFixture)
 {
     _dbContext         = testFixture.Context;
     _channelRepository = new ChannelRepository(_dbContext, new ChannelMapper());
     _fixture           = new Fixture();
 }
コード例 #12
0
 public PublishingService(IMapper mapper, MarketingDbContext db)
 {
     _mapper = mapper;
     _db     = db;
 }
コード例 #13
0
ファイル: BaseRepository.cs プロジェクト: abubasar/BDMS
 public BaseRepository(MarketingDbContext context)
 {
     this.context = context;
 }
コード例 #14
0
        public BankRepository(MarketingDbContext marketingDbContext)
        {
            _marketingDbContext = marketingDbContext;

            InitializeAsync();
        }
コード例 #15
0
 public ChannelService(IMapper mapper, MarketingDbContext db)
 {
     _mapper = mapper;
     _db     = db;
 }
コード例 #16
0
 public ChannelRepository(MarketingDbContext context, IChannelMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
コード例 #17
0
 public AdvertisingService(IMapper mapper, MarketingDbContext db)
 {
     _mapper = mapper;
     _db     = db;
 }
コード例 #18
0
 public Handler(MarketingDbContext context)
 {
     _context = context;
 }
コード例 #19
0
        public ApplicationRepository(MarketingDbContext marketingDbContext)
        {
            _marketingDbContext = marketingDbContext;

            InitializeAsync();
        }
 public AdvertisementRepositoryTests(ClassTestFixture testFixture)
 {
     _dbContext = testFixture.Context;
     _advertisementRepository = new AdvertisementRepository(_dbContext, new AdvertisementMapper());
     _fixture = new Fixture();
 }
コード例 #21
0
 public AdvertisementRepository(MarketingDbContext context, IAdvertisementMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }