public IEntity Load(int id, SqlDataReader dataReader) { Client client = new Client(); client.Id = id; client.Address = (string)dataReader["Address"]; client.Name = (string)dataReader["Name"]; return client; }
static void Main(string[] args) { Database.SetInitializer(new DropCreateDatabaseAlways<PromoContext>()); Product rocketFuel = new Product { Name = "Rocket fuel", Price = 25.0m }; Product doubleBlast = new Product { Name = "Double blast", Price = 40.0m }; Product tripleBlast = new Product { Name = "Triple blast", Price = 40.0m }; PromoContext dbContext = new PromoContext(); IEnumerable<Product> products = dbContext.Products.ToArray(); var asd = products.ToArray(); //dbContext.Products.Add(rocketFuel); //dbContext.Products.Add(doubleBlast); dbContext.Products.Add(tripleBlast); Discount rocketFuelDiscount = new Discount { Product = rocketFuel, DiscountPolicy = new PromoDay { DayDate = DateTime.Today, DiscountPercentage = new Percentage(20) } }; Client josephDeer = new Client { Name = "Joseph Deer", Address = "Czerwone Maki 84", }; josephDeer.Offer(rocketFuelDiscount); Discount doubleBlastAccount = new Discount { Product = doubleBlast, DiscountPolicy = new DiscountUntilExpired { DiscountPercentage = new Percentage(50), FromTo = new DateSpan { StartDate = DateTime.Today, EndDate = DateTime.Today.AddDays(2) } } }; josephDeer.Offer(doubleBlastAccount); Client regularClient = new Client { Name = "Jack Ryan", Address = "Rynek 5" }; dbContext.Clients.Add(regularClient); dbContext.Clients.Add(josephDeer); Discount discount = new Discount { Product = new Product { Name = "discounted product", Price = 12.0m } }; dbContext.Discounts.Add(discount); dbContext.SaveChanges(); int relatedProductId = discount.Product.Id; Discount insertedDiscount = dbContext.Discounts.Single(d => d.Id == discount.Id); dbContext.Discounts.Remove(insertedDiscount); dbContext.SaveChanges(); Product releatedProduct = dbContext.Products.Single(p => p.Id == relatedProductId); insertedDiscount = dbContext.Discounts.Single(d => d.Id == discount.Id); }
public void SaveShouldInsertOnlyOnce() { Client newClient = new Client { Name = "Johnny Bravo", Address = "Czerwone Maki 84, Krakow" }; sut.ClientMapper.Insert(newClient); sut.SaveChanges(); sut.SaveChanges(); Assert.AreEqual(1, GetClientsCount()); }
public void SavedInsertShouldSetId() { Client newClient = new Client { Name = "Johnny Bravo", Address = "Czerwone Maki 84, Krakow" }; sut.ClientMapper.Insert(newClient); Assert.AreEqual(0, newClient.Id); sut.SaveChanges(); Assert.AreNotEqual(0, newClient.Id); }
private static void DomainTest() { Product rocketFuel = new Product {Id = 1, Name = "Rocket fuel", Price = 25.0m}; Product doubleBlast = new Product {Id = 2, Name = "Double blast", Price = 40.0m}; Discount rocketFuelDiscount = new Discount { Product = rocketFuel, DiscountPolicy = new PromoDay {DayDate = DateTime.Today, DiscountPercentage = new Percentage(20)} }; Client josephDeer = new Client { Name = "Joseph Deer", Address = "Czerwone Maki 84", }; josephDeer.Offer(rocketFuelDiscount); Discount doubleBlastAccount = new Discount { Product = doubleBlast, DiscountPolicy = new DiscountUntilExpired { DiscountPercentage = new Percentage(50), FromTo = new DateSpan {StartDate = DateTime.Today, EndDate = DateTime.Today.AddDays(2)} } }; josephDeer.Offer(doubleBlastAccount); Client regularClient = new Client { Name = "Jack Ryan", Address = "Rynek 5" }; decimal regularPrice = regularClient.GetPriceForThisClient(doubleBlast); decimal discountedPrice = josephDeer.GetPriceForThisClient(doubleBlast); Console.WriteLine("double Blast regular price ${0}, discounted price only ${1}!", regularPrice, discountedPrice); regularPrice = regularClient.GetPriceForThisClient(rocketFuel); discountedPrice = josephDeer.GetPriceForThisClient(rocketFuel); Console.WriteLine("rocket fuel regular price ${0}, discounted price only ${1}!", regularPrice, discountedPrice); Console.ReadKey(); }
public void ShouldInsertDataOnSaveChanges() { //given Client client = new Client { Name = "Jack Daniels", Address = "Rynek 5, Krakow" }; //when sut.ClientMapper.Insert(client); sut.SaveChanges(); //expect Client clientInDb = ReadClientFromDb(); Assert.AreEqual("Jack Daniels", clientInDb.Name); Assert.AreEqual("Rynek 5, Krakow", clientInDb.Address); }
private static void TestClientInsert() { MappingContext mappingContext = new MappingContext("ormExample"); Client newClient = new Client {Name = "John malkovic", Address = "NY Brooklyn"}; mappingContext.ClientMapper.Insert(newClient); }
private static void TestIdentityMap() { MappingContext mappingContext = new MappingContext("ormExample"); Client autocenter = new Client() {Address = "Garncarska 13 Krakow", Name = "Auto center"}; mappingContext.ClientMapper.Insert(autocenter); mappingContext.SaveChanges(); // TODO cannot use ID as the entity has not been inserted yet maybe mappingContext.SaveChanged() Client autoCenterFromDb = mappingContext.ClientMapper.GetById(autocenter.Id); Debug.Assert(autoCenterFromDb.GetHashCode() == autocenter.GetHashCode(), "identity map fails"); Client firstClientAt3 = mappingContext.ClientMapper.GetById(2); Client secondClientAt3 = mappingContext.ClientMapper.GetById(2); Debug.Assert(firstClientAt3.GetHashCode() == secondClientAt3.GetHashCode(), "identity map fails"); }