Пример #1
0
        public void CanSave()
        {
            int itemID = SaveAnItem("savedItem", null);

            Assert.AreNotEqual(0, itemID);

            using (repository)
            {
                ContentItem item = repository.Get(itemID);
                Assert.AreEqual(item.ID, itemID);
                repository.Delete(item);
                repository.Flush();
            }
        }
Пример #2
0
        public object Delete(int id)
        {
            var repo = new NHRepository <AcademicProgram>();

            repo.Delete(id);

            return(0);
        }
        public object Delete(int id)
        {
            var repo = new NHRepository <SchoolType>();

            repo.Delete(id);

            return(0);
        }
Пример #4
0
        public object Delete(int id)
        {
            var repo = new NHRepository <Address>();

            repo.Delete(id);

            return(0);
        }
Пример #5
0
        public object Delete(int id)
        {
            var repo = new NHRepository <Volunteer>();

            repo.Delete(id);

            return(0);
        }
        public object Delete(int id)
        {
            var repo = new NHRepository <Department>();

            repo.Delete(id);

            return(0);
        }
Пример #7
0
        public void Delete_Deletes_Record()
        {
            //Adding a dummy record.
            var newAddress = new Address
            {
                StreetAddress1 = "This record was inserted for deletion",
                City           = "Fictional city",
                State          = "LA",
                ZipCode        = "12345"
            };

            var newCustomer = new Customer
            {
                FirstName = ("John_DELETE_ME_" + DateTime.Now),
                LastName  = ("Doe_DELETE_ME_" + DateTime.Now),
                Address   = newAddress
            };

            //Re-usable query to query for the matching record.
            var queryForCustomer = new Func <NHRepository <Customer>, Customer>
                                       (x => (from cust in x
                                              where cust.FirstName == newCustomer.FirstName && cust.LastName == newCustomer.LastName
                                              select cust).FirstOrDefault()
                                       );

            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new NHRepository <Customer>();
                var recordCheckResult  = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Null);

                customerRepository.Add(newCustomer);
                scope.Commit();
            }

            //Retrieve the record for deletion.
            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new NHRepository <Customer>();
                var customerToDelete   = queryForCustomer(customerRepository);
                Assert.That(customerToDelete, Is.Not.Null);
                customerRepository.Delete(customerToDelete);
                scope.Commit();
            }

            //Ensure customer record is deleted.
            using (new UnitOfWorkScope())
            {
                var customerRepository = new NHRepository <Customer>();
                var recordCheckResult  = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Null);
            }
        }
        public void when_ambient_transaction_is_running_and_a_previous_scope_rollsback_new_scope_still_works()
        {
            using (var testData = new NHTestDataGenerator(Factory.OpenSession()))
            {
                testData.Batch(actions => actions.CreateCustomer());

                string oldCustomerName;
                var    newCustomerName = "NewCustomer" + new Random().Next(0, int.MaxValue);
                var    newCustomer     = new Customer
                {
                    FirstName = newCustomerName,
                    LastName  = "Save",
                    Address   = new Address
                    {
                        StreetAddress1 = "This record was inserted via a test",
                        City           = "Fictional City",
                        State          = "LA",
                        ZipCode        = "00000"
                    }
                };

                using (var ambientScope = new TransactionScope())
                {
                    using (var firstUOW = new UnitOfWorkScope())
                    {
                        var customer = new NHRepository <Customer>().First();
                        oldCustomerName    = customer.FirstName;
                        customer.FirstName = "Changed";
                    }  //Rollback

                    using (var secondUOW = new UnitOfWorkScope())
                    {
                        new NHRepository <Customer>().Add(newCustomer);
                        secondUOW.Commit();
                    }
                }

                using (var scope = new UnitOfWorkScope())
                {
                    var repository = new NHRepository <Customer>();
                    Assert.That(repository.First().FirstName, Is.EqualTo(oldCustomerName));
                    Assert.That(repository.Where(x => x.FirstName == newCustomerName).Count(), Is.GreaterThan(0));
                    repository.Attach(newCustomer);
                    repository.Delete(newCustomer);
                    scope.Commit();
                }
            }
        }
Пример #9
0
 public void Delete(Calculation calculation)
 {
     session.CreateQuery("DELETE FROM JobIndexPoint o WHERE o.CalculationId = :id")
     .SetParameter("id", calculation.Id)
     .ExecuteUpdate();
     session.CreateQuery("DELETE FROM SummaryJobPositionPoint o WHERE o.CalculationId = :id")
     .SetParameter("id", calculation.Id)
     .ExecuteUpdate();
     session.CreateQuery("DELETE FROM SummaryEmployeePoint o WHERE o.CalculationId = :id")
     .SetParameter("id", calculation.Id)
     .ExecuteUpdate();
     session.CreateQuery("DELETE FROM SummaryCalculationPoint o WHERE o.CalculationId = :id")
     .SetParameter("id", calculation.Id)
     .ExecuteUpdate();
     session.CreateQuery("DELETE FROM EmployeeCalculationException o WHERE o.CalculationId = :id")
     .SetParameter("id", calculation.Id)
     .ExecuteUpdate();
     rep.Delete(calculation);
 }
Пример #10
0
 public void Delete(JobPosition jobPostion)
 {
     rep.Delete(jobPostion);
 }
Пример #11
0
 public void DeleteJob(Job job)
 {
     rep.Delete(job);
 }
Пример #12
0
 public void Delete(Period period)
 {
     rep.Delete(period);
 }
Пример #13
0
 public void Delete(Log log)
 {
     rep.Delete(log);
 }
Пример #14
0
 public void Delete(Claim claim)
 {
     rep.Delete(claim);
 }
Пример #15
0
        public void Delete(AbstractJobIndexId jobIndexId)
        {
            var abstractJobIndex = GetById(jobIndexId);

            rep.Delete(abstractJobIndex);
        }
Пример #16
0
 public void Delete(Employee employee)
 {
     rep.Delete(employee);
 }
Пример #17
0
 public void DeletePolicy(Policy policy)
 {
     rep.Delete(policy);
 }
Пример #18
0
        public void Delete(AbstractUnitIndexId unitIndexId)
        {
            var abstractIndex = GetById(unitIndexId);

            rep.Delete(abstractIndex);
        }
        public void Can_delete()
        {
            var customer = new Customer
            {
                FirstName = "John",
                LastName = "Doe",
            };
            using (var scope = new UnitOfWorkScope())
            {
                new NHRepository<Customer, int>().Add(customer);
                scope.Commit();
            }
            Assert.IsTrue(customer.CustomerID > 0);
            using (var scope = new UnitOfWorkScope())
            {
                var repository = new NHRepository<Customer, int>();
                var savedCustomer = repository.Query.Where(x => x.CustomerID == customer.CustomerID).First();
                repository.Delete(savedCustomer);
                scope.Commit();
            }

            //Making sure customer is deleted
            using (var testData = new NHTestData(NHTestUtil.OrdersDomainFactory.OpenSession()))
            {
                Customer savedCustomer = null;
                testData.Batch(x => savedCustomer = x.GetCustomerById(customer.CustomerID));
                Assert.IsNull(savedCustomer);
            }
        }
Пример #20
0
 public void DeleteUnit(Unit unit)
 {
     rep.Delete(unit);
 }
        public void when_ambient_transaction_is_running_and_a_previous_scope_rollsback_new_scope_still_works()
        {
            using (var testData = new NHTestDataGenerator(Factory.OpenSession()))
            {
                testData.Batch(actions => actions.CreateCustomer());

                string oldCustomerName;
                var newCustomerName = "NewCustomer" + new Random().Next(0, int.MaxValue);
                var newCustomer = new Customer
                {
                    FirstName = newCustomerName,
                    LastName = "Save",
                    Address = new Address
                    {
                        StreetAddress1 = "This record was inserted via a test",
                        City = "Fictional City",
                        State = "LA",
                        ZipCode = "00000"
                    }
                };

                using (var ambientScope = new TransactionScope())
                {
                    using (var firstUOW = new UnitOfWorkScope())
                    {
                        var customer = new NHRepository<Customer>().First();
                        oldCustomerName = customer.FirstName;
                        customer.FirstName = "Changed";
                    }  //Rollback

                    using (var secondUOW = new UnitOfWorkScope())
                    {

                        new NHRepository<Customer>().Add(newCustomer);
                        secondUOW.Commit();
                    }
                }

                using (var scope = new UnitOfWorkScope())
                {
                    var repository = new NHRepository<Customer>();
                    Assert.That(repository.First().FirstName, Is.EqualTo(oldCustomerName));
                    Assert.That(repository.Where(x => x.FirstName == newCustomerName).Count(), Is.GreaterThan(0));
                    repository.Attach(newCustomer);
                    repository.Delete(newCustomer);
                    scope.Commit();
                }
            }
        }
Пример #22
0
        public void Delete_Deletes_Record()
        {
            //Adding a dummy record.
            var newAddress = new Address
            {
                StreetAddress1 = "This record was inserted for deletion",
                City = "Fictional city",
                State = "LA",
                ZipCode = "12345"
            };

            var newCustomer = new Customer
            {
                FirstName = ("John_DELETE_ME_" + DateTime.Now),
                LastName = ("Doe_DELETE_ME_" + DateTime.Now),
                Address = newAddress
            };

            //Re-usable query to query for the matching record.
            var queryForCustomer = new Func<NHRepository<Customer>, Customer>
                (x => (from cust in x
                       where cust.FirstName == newCustomer.FirstName && cust.LastName == newCustomer.LastName
                       select cust).FirstOrDefault()
                );

            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new NHRepository<Customer>();
                var recordCheckResult = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Null);

                customerRepository.Add(newCustomer);
                scope.Commit();
            }

            //Retrieve the record for deletion.
            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new NHRepository<Customer>();
                var customerToDelete = queryForCustomer(customerRepository);
                Assert.That(customerToDelete, Is.Not.Null);
                customerRepository.Delete(customerToDelete);
                scope.Commit();
            }

            //Ensure customer record is deleted.
            using (new UnitOfWorkScope())
            {
                var customerRepository = new NHRepository<Customer>();
                var recordCheckResult = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Null);
            }
        }
Пример #23
0
        public void NHRepositoryOperationsTest()
        {
            // IMPORTANT NOTE Never use Repository inside a UnitOfWork!!!
            // Never! The Curse of Deadlock will be upon you!!!

            //Instantiate
            var repLoc = new NHRepository<Location>(_sessionFactory);

            // CREATE = Save
            // populate the database
            var input = new List<IMeasure> { new SimpleMeasure("ReteA", 10U) };
            var loc = _entitiesFactory.CreateLocation("Location1", input);
            loc.TotalTime = TimeVal;

            var input2 = new List<IMeasure> { new SimpleMeasure("ReteB", 50U), new SimpleMeasure("ReteC", 100U) };
            var loc2 = _entitiesFactory.CreateLocation("Location2", input2);
            loc2.TotalTime = TimeVal1;

            //this saves everything else via cascading
            repLoc.Save(loc);
            repLoc.Save(loc2);

            // READ = Get and GetAll
            Location locA = null;
            IList<Location> locations = repLoc.GetAll();
            Assert.AreEqual(locations.Count, 2);
            foreach (var location in locations)
            {
                //For a visual feedback
                Console.WriteLine(location.ToString());
                if (location.Name == "Location1")
                {
                    Assert.AreEqual(location.TotalTime, TimeVal);
                    locA = location;
                }
                else if (location.Name == "Location2")
                {
                    Assert.AreEqual(location.TotalTime, TimeVal1);
                }
                else
                {
                    Log.Debug(location.Name);
                    Assert.Fail("Location name not matching");
                }
            }

            Assert.IsNotNull(locA);
            var locB = repLoc.Get(locA.Id);
            Assert.AreEqual(locB.Name, "Location1");
            Assert.AreEqual(locB.TotalTime, TimeVal);

            var repNet = new NHRepository<Network>(_sessionFactory);
            var networks = repNet.GetAll();
            Assert.AreEqual(networks.Count, 3);

            //Dirty Get (without waiting for transactions)
            var locDirty = repLoc.Get(locA.Id, dirty: true);
            Assert.AreEqual(locDirty.Name, "Location1");
            Assert.AreEqual(locDirty.TotalTime, TimeVal);

            var locDirties = repLoc.GetAll(dirty: true);
            Assert.AreEqual(locDirties.Count, 2);
            foreach (var location in locDirties)
            {
                if (location.Name == "Location1")
                {
                    Assert.AreEqual(location.TotalTime, TimeVal);
                }
                else if (location.Name == "Location2")
                {
                    Assert.AreEqual(location.TotalTime, TimeVal1);
                }
                else
                {
                    Log.Debug(location.Name);
                    Assert.Fail("Location name not matching");
                }
            }

            // UPDATE = Update
            // BEWARE OF DIRTY WRITES!!! THEY ARE STILL DIFFERENT TRANSACTIONS!!!
            Location locUpdated = locA;
            locUpdated.TotalTime = TimeVal2;
            repLoc.Update(locUpdated);

            Location tmp = repLoc.Get(locUpdated.Id);
            Assert.AreEqual(tmp.TotalTime, TimeVal2);

            // DELETE = Delete
            locations = repLoc.GetAll();

            foreach (var location in locations)
            {
                repLoc.Delete(location);
            }

            //check cascading deletion
            locations = repLoc.GetAll();
            Assert.AreEqual(locations.Count, 0);

            networks = repNet.GetAll();
            Assert.AreEqual(networks.Count, 0);
        }
Пример #24
0
 public void Delete(Party party)
 {
     rep.Delete(party);
 }
 public void Delete(InquiryJobIndexPoint inquiryJobIndexPoint)
 {
     rep.Delete(inquiryJobIndexPoint);
 }
Пример #26
0
 public void DeleteCustomField(CustomFieldType customField)
 {
     rep.Delete(customField);
 }