public void DiscountPoliciesShouldBeStoredInTheSameTable()
        {
            DiscountUntilExpired discountUntilExpired = new DiscountUntilExpired
                {
                    DiscountPercentage = new Percentage(20),
                    FromTo = new DateSpan {StartDate = DateTime.Today, EndDate = DateTime.Today.AddDays(1)}
                };
            PromoDay promoDay = new PromoDay
                {
                    DiscountPercentage = new Percentage(10),
                    DayDate = DateTime.Today
                };

            mappingContext.DiscountPolicies.Insert(discountUntilExpired);
            mappingContext.DiscountPolicies.Insert(promoDay);
            mappingContext.SaveChanges();

            DiscountUntilExpired discountUntilExpiredReadFromDb = ReadDiscountUntilExpiredFromDatabase(discountUntilExpired.Id);
            Assert.AreEqual(discountUntilExpiredReadFromDb.Id, discountUntilExpired.Id);
            Assert.AreEqual(discountUntilExpiredReadFromDb.DiscountPercentage, discountUntilExpired.DiscountPercentage);
            Assert.AreEqual(discountUntilExpiredReadFromDb.FromTo, discountUntilExpired.FromTo);

            PromoDay promoDayReadFromDb = ReadPromoDayFromDatabase(promoDay.Id);
            Assert.AreEqual(promoDayReadFromDb.Id, promoDay.Id);
            Assert.AreEqual(promoDayReadFromDb.DiscountPercentage, promoDay.DiscountPercentage);
            Assert.AreEqual(promoDayReadFromDb.DayDate, promoDay.DayDate);
        }
 public IEntity Load(int id, SqlDataReader dataReader)
 {
     DiscountUntilExpired discountUntilExpired = new DiscountUntilExpired();
     discountUntilExpired.Id = id;
     // DateSpan mapping - Embedded Value
     DateTime dateSpanStart = (DateTime)dataReader["FromTo_Start"];
     DateTime dateSpanEnd = (DateTime)dataReader["FromTo_End"];
     discountUntilExpired.FromTo = new DateSpan { StartDate = dateSpanStart, EndDate = dateSpanEnd };
     return discountUntilExpired;
 }
 private DiscountUntilExpired ReadDiscountUntilExpiredFromDatabase(int id)
 {
     using (SqlConnection connection = new SqlConnection(connectionString))
     {
         connection.Open();
         using (SqlCommand command = new SqlCommand("SELECT * FROM DiscountPolicies WHERE ID = " + id, connection))
         {
             IDataReader dr = command.ExecuteReader();
             if (dr.Read())
             {
                 DiscountUntilExpired discountUntilExpired = new DiscountUntilExpired();
                 discountUntilExpired.Id = (int) dr["ID"];
                 DateTime from = (DateTime) dr["FromTo_Start"];
                 DateTime to = (DateTime) dr["FromTo_End"];
                 discountUntilExpired.FromTo = new DateSpan {StartDate = from, EndDate = to};
                 Percentage percentage = new Percentage((int)dr["DiscountPercentage"]);
                 discountUntilExpired.DiscountPercentage = percentage;
                 return discountUntilExpired;
             }
             throw new ArgumentException("no id " + id + " found");
         }
     }
 }