Пример #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);
 }
Пример #2
0
 public void Setup()
 {
     sut = new MappingContext(ConnectionStringName);
 }
Пример #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);
 }
Пример #4
0
 private static void TestProductUpdate()
 {
     MappingContext mappingContext = new MappingContext("ormExample");
     Product product = mappingContext.ProductMapper.GetById(2);
     product.Name += " improved!";
     mappingContext.ProductMapper.Update(product);
 }
Пример #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");
        }
Пример #6
0
 private static void TestProductsGet()
 {
     MappingContext mappingContext = new MappingContext("ormExample");
     IEnumerable<Product> allProducts = mappingContext.ProductMapper.GetAll();
 }
Пример #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();
 }
Пример #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"));
 }
Пример #9
0
 private static void TestGetClients()
 {
     MappingContext mappingContext = new MappingContext("ormExample");
     Client client = mappingContext.ClientMapper.GetById(2);
     IEnumerable<Client> clients = mappingContext.ClientMapper.GetAll();
 }
Пример #10
0
 private static void TestClientUpdate()
 {
     MappingContext mappingContext = new MappingContext("ormExample");
     Client clientToUpdate = mappingContext.ClientMapper.GetById(5);
     clientToUpdate.Name += " what?";
     mappingContext.ClientMapper.Update(clientToUpdate);
 }
Пример #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);
 }