public void WriteListToDb()
        {
            var repository = new NHibernateRepository <Artist>();

            NHibernateHelper.CreateDatabaseIfNeeded();
            var testData = @"[{
            ""Id"": 760,
            ""Name"": ""\""Weird Al\"" Yankovic""
              }, {
            ""Id"": 3,
            ""Name"": "".38 Special""
                }, {
            ""Id"": 1,
            ""Name"": ""3 Doors Down""
            }]"    ;

            var testObject    = JSONToDatabaseReader.JSON.Serialization.Deserialize <List <Artist> >(testData);
            var resultingList = ReadJSONAndWriteToDb.FilterEnumerable(testObject, x => x.Name.Contains("3"));

            foreach (var item in resultingList)
            {
                repository.Save(item);
            }
            var nrOfArtists = repository.GetAll().Count;

            Assert.IsTrue(nrOfArtists == 2);
        }
Example #2
0
        public void CheckNumberOfEntities(int numberOfEntities)
        {
            var testEntityRepository = new NHibernateRepository <TestEntity>();
            var testEntities         = testEntityRepository.GetAll();

            testEntities.Count.ShouldEqual(numberOfEntities);
        }
Example #3
0
        static void Main(string[] args)
        {
            var flagRepostory= new NHibernateRepository<Flag>();
            var langRepository = new NHibernateRepository<Language>();
            var langInfoRepository= new NHibernateRepository<LanguageInfo>();

            //var langInfo = langInfoRepository.GetAll();
            var flags = flagRepostory.GetAll();

            //var lang = langRepository.Get(2);
            //LanguageInfo langInfo = new LanguageInfo();
            //langInfo.LongPath = "test";
            //langInfo.ShortPath = "test1";
            //langInfo.AddLanguage(lang);
            //lang.AddLanguageIcon(langInfo);
            //langRepository.Save(lang);
            //langInfoRepository.Save(langInfo);

            Flag flag = new Flag();
            flag.Name = " F*****g programe";
            flag.Description = " Flag Descrption2";
            var lang = langRepository.Get(2);
            var languageInfo = new LanguageInfoNew { LongPath = "@C:Test1", ShortPath = "@d:tet2" };
            languageInfo.AddLanguage(lang);
            //lang.AddLanguageIcon(new LanguageInfo { LongPath = "Test1", ShortPath = "test1" });
            flag.AddLanguage(languageInfo);
            flagRepostory.Save(flag);
        }
        public void IntegrationTest()
        {
            IList<Banana> bananas = new List<Banana>();
            bananas.Add(new Banana() { Color = "Brown" });
            bananas.Add(new Banana() { Color = "Yellow" });

            IRepository<Banana> bRepo = new NHibernateRepository<Banana>();
            foreach (Banana b in bananas)
                bRepo.Save(b);

            Assert.IsTrue(bRepo.GetAll().Count == bananas.Count);

            IList<Monkey> monkeys = new List<Monkey>();
            monkeys.Add(new Monkey() { Name = "George", FlingsPoo = true, Bananas = bananas });
            monkeys.Add(new Monkey() { Name = "Magilla", FlingsPoo = false });

            IRepository<Monkey> mRepo = new NHibernateRepository<Monkey>();
            foreach (Monkey m in monkeys)
                mRepo.Save(m);

            Assert.IsTrue(mRepo.GetAll().Count == monkeys.Count);

            Monkey tempMonkey;
            tempMonkey = mRepo.Get(monkeys[0].Id);
            Assert.IsNotNull(tempMonkey);
            tempMonkey = mRepo.Get(-1);
            Assert.IsNull(tempMonkey);

            IMonkeyRepository imRepo = new MonkeyRepository();
            Assert.IsTrue(imRepo.GetPooFlingingMonkeys().Count == 1);

            foreach (Banana b in bananas)
                bRepo.Delete(b);

            Assert.IsTrue(bRepo.GetAll().Count == 0);

            foreach (Monkey m in monkeys)
                mRepo.Delete(m);

            Assert.IsTrue(mRepo.GetAll().Count == 0);
        }
        public void MappingTest()
        {
            var testObject = new Artist
            {
                Id   = 123,
                Name = "TestBoodschap"
            };
            var repository = new NHibernateRepository <Artist>();

            NHibernateHelper.CreateDatabaseIfNeeded();
            repository.Save(testObject);
            var result = repository.Get(123);

            Assert.IsTrue(testObject == result);
            Assert.IsTrue(repository.GetAll().Count > 0);
        }
Example #6
0
        /// <summary>
        /// Método para obtener un usuario.
        /// </summary>
        /// <returns></returns>
        public IList <Usuario> ObtenerUsuarios()
        {
            IList <Usuario> usuario;

            try
            {
                IRepository <Usuario> uRepo = new NHibernateRepository <Usuario>();
                usuario = uRepo.GetAll();

                return(usuario);
            }
            catch (Exception e)
            {
                log.Error(e.Message, e);
                throw new DataAccessException(DataAccessException.EXCEPTION, e);
            }
        }
Example #7
0
        /// <summary>
        /// Método para obtener una lista de proveedores.
        /// </summary>
        /// <returns></returns>
        public IList <Proveedor> ObtenerProveedores()
        {
            IList <Proveedor> proveedor;

            try
            {
                IRepository <Proveedor> pRepo = new NHibernateRepository <Proveedor>();
                proveedor = pRepo.GetAll();

                return(proveedor);
            }
            catch (Exception e)
            {
                log.Error(e.Message, e);
                throw new DataAccessException(DataAccessException.EXCEPTION, e);
            }
        }
 public void getall_should_get_a_list_of_customers()
 {
     var repository = new NHibernateRepository<Customer>();
     var customers = repository.GetAll<Customer>();
     Assert.That(customers, Is.Not.Empty);
 }
 public void CheckNumberOfEntities(int numberOfEntities)
 {
     var testEntityRepository = new NHibernateRepository<TestEntity>();
     var testEntities = testEntityRepository.GetAll();
     testEntities.Count.ShouldEqual(numberOfEntities);
 }
Example #10
0
        static void Main(string[] args)
        {
            //create tables from mapping
            new SchemaExport(NHibernateHelper.Configuration).Create(false, true);
            #region use_inline
            //open connection to db
            using (ISession session = NHibernateHelper.SessionFactory.OpenSession())
            {
                #region add
                using (ITransaction tx = session.BeginTransaction())
                {
                    for (int i = 0; i < 30; i++)
                    {
                        var employee = new Employee {
                            Name = new Name {
                                FirstName = "Employee", LastName = string.Format("{0}", i)
                            }
                        };
                        var employer = new Employer {
                            Name = string.Format("Employer {0}", i)
                        };
                        var employment = new Employment
                        {
                            Employee  = employee,
                            Employer  = employer,
                            StartDate = System.DateTime.Now,
                            EndDate   = System.DateTime.Now.AddDays(i)
                        };
                        session.Save(employee);
                        session.Save(employer);
                        session.Save(employment);
                    }
                    tx.Commit();
                }
                #endregion
                #region list
                using (var tx = session.BeginTransaction())
                {
                    //dont forget ToList()
                    var employments = session.Query <Employment>().ToList();
                    foreach (var employment in employments)
                    {
                        Console.Out.WriteLine("Employee: " + employment.Employee.Name.LastName + " end date " + employment.EndDate + " at employer " + employment.Employer.Name);
                    }

                    tx.Commit();
                }
                #endregion
            }
            #endregion
            #region using_repository
            IRepository <Employment> EmploymentRepository = new NHibernateRepository <Employment>();
            IRepository <Employee>   EmployeeRepository   = new NHibernateRepository <Employee>();
            IRepository <Employer>   EmployerRepository   = new NHibernateRepository <Employer>();
            #region add
            for (int i = 0; i < 30; i++)
            {
                var employee = new Employee {
                    Name = new Name {
                        FirstName = "Employee", LastName = string.Format("{0}", i)
                    }
                };
                var employer = new Employer {
                    Name = string.Format("Employer {0}", i)
                };
                var employment = new Employment
                {
                    Employee  = employee,
                    Employer  = employer,
                    StartDate = System.DateTime.Now,
                    EndDate   = System.DateTime.Now.AddDays(i)
                };
                EmployeeRepository.Save(employee);
                EmployerRepository.Save(employer);
                EmploymentRepository.Save(employment);
            }
            #endregion
            #region show
            foreach (var employment in EmploymentRepository.GetAll())
            {
                Console.Out.WriteLine("Employee: " + employment.Employee.Name.LastName + " end date " + employment.EndDate + " at employer " + employment.Employer.Name);
            }


            #endregion
            #endregion
        }