Esempio n. 1
0
        public void GetAdType_CarAdExists_ReturnType()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository      repo           = new Repository(sessionFactory);
            AdRepository    adRepo         = new AdRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                #region test data
                Province p1 = new Province
                {
                    Label = "p1"
                };

                User u = new User
                {
                    Email    = "*****@*****.**",
                    Password = "******"
                };
                repo.Save <User>(u);

                City c = new City
                {
                    Label        = "city",
                    LabelUrlPart = "city"
                };
                p1.AddCity(c);

                Category cat = new Category
                {
                    Label        = "Auto",
                    LabelUrlPart = "Auto",
                    Type         = AdTypeEnum.CarAd
                };

                CarAd a = new CarAd
                {
                    Title        = "honda civic type R",
                    Body         = "the best!!",
                    CreatedBy    = u,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category     = cat,
                    Kilometers   = 25000,
                    Year         = 1998
                };
                c.AddAd(a);
                cat.AddAd(a);
                repo.Save <Province>(p1);
                repo.Save <City>(c);
                repo.Save <Category>(cat);
                long id = repo.Save <CarAd, long>(a);

                repo.Flush();

                #endregion

                Assert.AreEqual(AdTypeEnum.CarAd, adRepo.GetAdType(id));
            }
        }
Esempio n. 2
0
        public void CanDeleteAd_AdExistsAndNotDeleted_ReturnTrue()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository      repo           = new Repository(sessionFactory);
            AdRepository    adRepo         = new AdRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                #region test data
                Province p1 = new Province
                {
                    Label = "p1"
                };

                User u = new User
                {
                    Email    = "*****@*****.**",
                    Password = "******"
                };
                repo.Save <User>(u);

                City c = new City
                {
                    Label        = "city",
                    LabelUrlPart = "city"
                };
                p1.AddCity(c);

                Category cat = new Category
                {
                    Label        = "Informatique",
                    LabelUrlPart = "Informatique",
                    Type         = AdTypeEnum.Ad
                };

                Ad a = new Ad
                {
                    Title        = "video game",
                    Body         = "the best!!",
                    CreatedBy    = u,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category     = cat,
                    IsDeleted    = false
                };
                c.AddAd(a);
                cat.AddAd(a);
                repo.Save <Province>(p1);
                repo.Save <City>(c);
                repo.Save <Category>(cat);
                long id = repo.Save <Ad, long>(a);

                repo.Flush();

                #endregion

                Assert.IsTrue(adRepo.CanDeleteAd(id));
            }
        }
Esempio n. 3
0
        public void GetAdById_GetAd_ReturnAdObject()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository      repo           = new Repository(sessionFactory);
            AdRepository    adRepo         = new AdRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                #region test data
                Province p1 = new Province
                {
                    Label = "p1"
                };

                User u = new User
                {
                    Email    = "*****@*****.**",
                    Password = "******"
                };
                repo.Save <User>(u);

                City c = new City
                {
                    Label        = "city",
                    LabelUrlPart = "city"
                };
                p1.AddCity(c);

                Category cat = new Category
                {
                    Label        = "Moto",
                    LabelUrlPart = "Moto"
                };

                Ad a = new Ad
                {
                    Title        = "ship",
                    Body         = "computer",
                    CreatedBy    = u,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category     = cat
                };
                c.AddAd(a);
                cat.AddAd(a);
                repo.Save <Province>(p1);
                repo.Save <City>(c);
                repo.Save <Category>(cat);
                long id = repo.Save <Ad, long>(a);

                repo.Flush();

                #endregion

                Assert.AreEqual(a, adRepo.GetAdById <Ad>(id));
            }
        }
Esempio n. 4
0
        public void GetAdsByEmail_ReturnListOfAds_WithUserAndCategoryFetched()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            AdRepository    adRepo         = new AdRepository(sessionFactory);
            Repository      repo           = new Repository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                #region test data
                Province p1 = new Province
                {
                    Label = "p1"
                };

                User u = new User
                {
                    Email    = "*****@*****.**",
                    Password = "******"
                };
                repo.Save <User>(u);

                User u2 = new User
                {
                    Email    = "*****@*****.**",
                    Password = "******"
                };
                repo.Save <User>(u2);

                City c = new City
                {
                    Label        = "city",
                    LabelUrlPart = "city",
                };
                p1.AddCity(c);

                Category cat = new Category
                {
                    Label        = "Informatique",
                    LabelUrlPart = "Informatique",
                    Type         = AdTypeEnum.Ad
                };

                Category cat2 = new Category
                {
                    Label        = "Voiture",
                    LabelUrlPart = "Voiture",
                    Type         = AdTypeEnum.Ad
                };



                Ad a = new Ad
                {
                    Title        = "video game",
                    Body         = "the best!!",
                    CreatedBy    = u,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category     = cat,
                    IsDeleted    = false,
                    IsActivated  = true
                };

                Ad a2 = new Ad
                {
                    Title        = "Ferrari F430",
                    Body         = "Valab'",
                    CreatedBy    = u,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category     = cat2,
                    IsDeleted    = false,
                    IsActivated  = true
                };

                Ad a3 = new Ad
                {
                    Title        = "Ferrari F430",
                    Body         = "Valab'",
                    CreatedBy    = u2,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category     = cat2,
                    IsDeleted    = false,
                    IsActivated  = true
                };
                c.AddAd(a);
                c.AddAd(a2);
                c.AddAd(a3);
                cat.AddAd(a);
                cat2.AddAd(a2);
                cat2.AddAd(a3);
                repo.Save <Province>(p1);
                repo.Save <City>(c);
                repo.Save <Category>(cat);
                repo.Save <Category>(cat2);
                repo.Save <Ad, long>(a);
                repo.Save <Ad, long>(a2);
                repo.Save <Ad, long>(a3);
                repo.Flush();
                #endregion

                List <BaseAd> adsUser1 = adRepo.GetAdsByEmail(u.Email).ToList();
                List <BaseAd> adsUser2 = adRepo.GetAdsByEmail(u2.Email).ToList();
                Assert.AreEqual(2, adsUser1.Count);
                Assert.AreEqual(u.Email, adsUser1[0].CreatedBy.Email);
                Assert.AreEqual(1, adsUser2.Count);
                Assert.AreEqual(u2.Email, adsUser2[0].CreatedBy.Email);
            }
        }
Esempio n. 5
0
        public void SearchAdsByTitle_SearchStringIsNotNullOrEmpty_ReturnMatchedAd()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository      repo           = new Repository(sessionFactory);
            AdRepository    adRepo         = new AdRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                // Given
                #region test data

                User u = new User
                {
                    Email    = "*****@*****.**",
                    Password = "******"
                };
                repo.Save <User>(u);

                City c = new City
                {
                    Label        = "CherzmOi",
                    LabelUrlPart = "city"
                };

                Category cat = new Category
                {
                    Label        = "Voiture",
                    LabelUrlPart = "Voiture"
                };

                Ad a = new Ad
                {
                    Title        = "titre 1",
                    Body         = "content",
                    CreatedBy    = u,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18)
                };
                c.AddAd(a);
                cat.AddAd(a);
                repo.Save <City>(c);
                repo.Save <Category>(cat);
                repo.Save <Ad>(a);

                Ad a2 = new Ad
                {
                    Title        = "title 2",
                    Body         = "content",
                    CreatedBy    = u,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 17)
                };
                c.AddAd(a2);
                cat.AddAd(a2);
                repo.Save <Ad>(a2);


                repo.Flush();

                #endregion

                // When
                IList <Ad> result = adRepo.SearchAdsByTitle("tre");

                // Then
                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(a, result[0]);
            }
        }
Esempio n. 6
0
        public void CountAdsByCity_2Citiesand3Ad_Return2elements()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository      repo           = new Repository(sessionFactory);
            AdRepository    adRepo         = new AdRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                // Given
                #region test data

                User u = new User
                {
                    Email    = "*****@*****.**",
                    Password = "******"
                };
                repo.Save <User>(u);

                City c = new City
                {
                    Label        = "CherzmOi",
                    LabelUrlPart = "city"
                };

                Category cat = new Category
                {
                    Label        = "Bateau",
                    LabelUrlPart = "Bateau"
                };

                Ad a = new Ad
                {
                    Title     = "titre",
                    Body      = "content",
                    CreatedBy = u,
                    City      = c,
                    Category  = cat
                };
                c.AddAd(a);
                cat.AddAd(a);
                repo.Save <City>(c);
                repo.Save <Category>(cat);
                repo.Save <Ad>(a);

                Ad a2 = new Ad
                {
                    Title     = "titre",
                    Body      = "content",
                    CreatedBy = u,
                    City      = c,
                    Category  = cat
                };
                c.AddAd(a2);
                repo.Save <Ad>(a2);

                City c2 = new City
                {
                    Label        = "CherzmOi 2",
                    LabelUrlPart = "city2",
                };
                Ad a3 = new Ad
                {
                    Title     = "titre",
                    Body      = "content",
                    CreatedBy = u,
                    City      = c2,
                    Category  = cat
                };
                c2.AddAd(a3);
                repo.Save <City>(c2);
                repo.Save <Ad>(a3);

                repo.Flush();

                #endregion

                // When
                IDictionary <City, int> result = adRepo.CountAdsByCity();

                // Then
                Assert.AreEqual(2, result.Count);
                Assert.AreEqual(2, result[c]);
                Assert.AreEqual(1, result[c2]);
            }
        }