Example #1
0
 private static void TestClientInsert()
 {
     MappingContext mappingContext = new MappingContext("ormExample");
     Client newClient = new Client {Name = "John malkovic", Address = "NY Brooklyn"};
     mappingContext.ClientMapper.Insert(newClient);
 }
 public void Setup()
 {
     sut = new MappingContext(ConnectionStringName);
 }
Example #3
0
 private static void TestProductInsert()
 {
     MappingContext mappingContext = new MappingContext("ormExample");
     Product kryptonite = new Product {Name = "Next generation blast", Price = 999.0m};
     mappingContext.ProductMapper.Insert(kryptonite);
 }
Example #4
0
 private static void TestProductUpdate()
 {
     MappingContext mappingContext = new MappingContext("ormExample");
     Product product = mappingContext.ProductMapper.GetById(2);
     product.Name += " improved!";
     mappingContext.ProductMapper.Update(product);
 }
Example #5
0
        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");
        }
Example #6
0
 private static void TestProductsGet()
 {
     MappingContext mappingContext = new MappingContext("ormExample");
     IEnumerable<Product> allProducts = mappingContext.ProductMapper.GetAll();
 }
Example #7
0
 private static void TestDelete()
 {
     MappingContext mappingContext = new MappingContext("ormExample");
     var productAt3 = mappingContext.ProductMapper.GetAll().Skip(2).First();
     //mappingContext.GetClientMapper().DeleteById(productAt3.Id);
     mappingContext.ClientMapper.DeleteById(10);
     var all = mappingContext.ClientMapper.GetAll();
 }
Example #8
0
 private static void TestUow()
 {
     MappingContext mappingContext = new MappingContext("ormExample");
     Client c1 = mappingContext.ClientMapper.GetById(1);
     c1.Name += "UOW modified";
     mappingContext.SaveChanges();
     Client c2 = mappingContext.ClientMapper.GetById(1);
     Debug.Assert(c2.Name.Contains("UOW modified"));
 }
Example #9
0
 private static void TestGetClients()
 {
     MappingContext mappingContext = new MappingContext("ormExample");
     Client client = mappingContext.ClientMapper.GetById(2);
     IEnumerable<Client> clients = mappingContext.ClientMapper.GetAll();
 }
Example #10
0
 private static void TestClientUpdate()
 {
     MappingContext mappingContext = new MappingContext("ormExample");
     Client clientToUpdate = mappingContext.ClientMapper.GetById(5);
     clientToUpdate.Name += " what?";
     mappingContext.ClientMapper.Update(clientToUpdate);
 }
Example #11
0
 public void DiscountShouldGetRelatedProduct()
 {
     Product discountedProduct = new Product { Name = "Oil", Price = 89.0m };
     mappingContext.ProductMapper.Insert(discountedProduct);
     mappingContext.SaveChanges();
     Discount discount = new Discount { Product = discountedProduct };
     mappingContext.DiscountsMapper.Insert(discount);
     mappingContext.SaveChanges();
     int idToGet = discount.Id;
     Discount sut = new MappingContext(ConnectionStringName).DiscountsMapper.GetById(idToGet);
     Assert.AreEqual(discountedProduct.Id, sut.Product.Id);
 }