Exemple #1
0
        public void Save_Updates_Existing_Order_Record()
        {
            var updatedDate = DateTime.Now;

            using (var testData = new NHTestDataGenerator(Factory.OpenSession()))
            {
                testData.Batch(actions =>
                               actions.CreateOrderForCustomer(actions.CreateCustomer()));

                int orderId;
                using (var scope = new UnitOfWorkScope())
                {
                    var orderRepository = new NHRepository <Order>();
                    var order           = orderRepository.FirstOrDefault();
                    Assert.That(order, Is.Not.Null);
                    orderId         = order.OrderID;
                    order.OrderDate = updatedDate;

                    scope.Commit();
                }

                using (new UnitOfWorkScope())
                {
                    var orderRepository = new NHRepository <Order>();
                    var order           = (from o in orderRepository
                                           where o.OrderID == orderId
                                           select o).FirstOrDefault();

                    Assert.That(order, Is.Not.Null);
                    Assert.That(order.OrderDate.Date, Is.EqualTo(updatedDate.Date));
                    Assert.That(order.OrderDate.Hour, Is.EqualTo(updatedDate.Hour));
                    Assert.That(order.OrderDate.Minute, Is.EqualTo(updatedDate.Minute));
                    Assert.That(order.OrderDate.Second, Is.EqualTo(updatedDate.Second));
                }
            }
        }
        public void Save_Updates_Existing_Order_Record()
        {
            var updatedDate = DateTime.Now;

            using (var testData = new NHTestDataGenerator(Factory.OpenSession()))
            {
                testData.Batch(actions =>
                               actions.CreateOrderForCustomer(actions.CreateCustomer()));

                int orderId;
                using (var scope = new UnitOfWorkScope())
                {
                    var orderRepository = new NHRepository<Order>();
                    var order = orderRepository.FirstOrDefault();
                    Assert.That(order, Is.Not.Null);
                    orderId = order.OrderID;
                    order.OrderDate = updatedDate;

                    scope.Commit();
                }

                using (new UnitOfWorkScope())
                {
                    var orderRepository = new NHRepository<Order>();
                    var order = (from o in orderRepository
                                 where o.OrderID == orderId
                                 select o).FirstOrDefault();

                    Assert.That(order, Is.Not.Null);
                    Assert.That(order.OrderDate.Date, Is.EqualTo(updatedDate.Date));
                    Assert.That(order.OrderDate.Hour, Is.EqualTo(updatedDate.Hour));
                    Assert.That(order.OrderDate.Minute, Is.EqualTo(updatedDate.Minute));
                    Assert.That(order.OrderDate.Second, Is.EqualTo(updatedDate.Second));
                }
            }
        }