예제 #1
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]);
            }
        }
예제 #2
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]);
            }
        }