//[TestCleanup]
 public void TearDown()
 {
     var context = new SportsbookContext();//_connectionString);
     context.Database.ExecuteSqlCommand(string.Format("DELETE FROM {0}", "tbl_market"));
     context.Database.ExecuteSqlCommand(string.Format("DELETE FROM {0}", "tbl_event"));
     context.SaveChanges();
 }
        public void Setup()
        {
            EntityFrameworkProfiler.Initialize();

            var context = new SportsbookContext();//_connectionString);

            var matchWinner = new MarketTypeEntity
            {
                Name = "Match Winner"
            };

            var newEvent = new EventWithMarketEntity
            {
                Name = "Manchester United - Real Madrid",
            };

            var newMaket = new MarketEntity
            {
                Type = matchWinner,
                Event = newEvent
            };

            context.Entry(newMaket).State = EntityState.Added;
            var result = context.SaveChanges();
            Assert.IsTrue(result > 0);
        }
        public void TimestampConversion()
        {
            var context = new SportsbookContext();//_connectionString);

            var ev = context.EventEntities.First();

            var timestampString = ev.Timestamp.ToHexString();
            byte[] timestamp = timestampString.ToByteArray();

            context = new SportsbookContext();//_connectionString);

            var modified = new EventReferenceEntity
            {
                Id = ev.Id,
                Name = "AC Milan - New Castle",
                Timestamp = timestamp
            };

            context.Entry(modified).State = EntityState.Modified;
            var result = context.SaveChanges();
            Assert.AreEqual(1, result);
        }
        public void SavingWithNavigationalProperty()
        {
            var context = new SportsbookContext();//_connectionString);

            var matchWinner = new MarketTypeEntity
            {
                Name = "Match Winner"
            };

            var ev = new EventWithMarketEntity
            {
                Name = "AC Milan - New Castle"
            };

            var market = new MarketEntity
            {
                Type = matchWinner,
                Event = ev
            };

            context.Entry(market).State = EntityState.Added;
            var result = context.SaveChanges();
            Assert.IsTrue(result > 0);
        }
        public void UpdatingBothEventAndMarketsSimultaneouly()
        {
            var context = new SportsbookContext();//_connectionString);

            var market = context.Set<MarketEntity>()
                .Include("Event").First();

            market.Type = new MarketTypeEntity
            {
                Id = 1
            };
            market.Event.Name = "Modified Event Name";

            context.SaveChanges();
        }
        public void AddMarketToEventWithMarket()
        {
            var context = new SportsbookContext();//_connectionString);

            var matchWinner = new MarketTypeEntity
            {
                Name = "Match Winner"
            };

            var eventId = context.Set<MarketEntity>()
                .Select(m => m.Event.Id)
                .FirstOrDefault();

            var existingEvent = new EventWithMarketEntity
            {
                Id = eventId,
            };

            var newMarket = new MarketEntity
            {
                Event = existingEvent,
                Type = matchWinner,
            };

            context.Entry(existingEvent).State = EntityState.Unchanged;
            context.Entry(newMarket).State = EntityState.Added;
            context.SaveChanges();
        }
        public void OneEventToManyMarketsRelationship()
        {
            var context = new SportsbookContext();//_connectionString);

            var matchWinner = new MarketTypeEntity
            {
                Name = "Match Winner"
            };

            var overUnder = new MarketTypeEntity
            {
                Name = "Match Winner"
            };

            var ev = new EventWithMarketEntity
            {
                Name = "Manchester City - Barcelona FC"
            };

            var market1 = new MarketEntity
            {
                Type = matchWinner,
                Event = ev
            };

            var market2 = new MarketEntity
            {
                Type = overUnder,
                Event = ev
            };

            context.Entry(market1).State = EntityState.Added;
            context.Entry(market2).State = EntityState.Added;
            context.SaveChanges();
        }