public void CanDeleteAd_AdExistsAndAlreadyDeleted_ReturnFalse()
        {
            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 = true
                };
                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.IsFalse(adRepo.CanDeleteAd(id));
            }
        }
Beispiel #2
0
        public void GetCoverAds_Pages()
        {
            var target = new AdRepository(_mockDataService);

            var result = target.GetCoverAds(_startDate, _endDate, "AdId", true, 2, 1);

            Assert.AreEqual(2, result.DisplayAds.Count());
            Assert.AreEqual(2, result.TotalPageCount);
            Assert.AreEqual(1, result.Page);
        }
Beispiel #3
0
        public void GetCoverAds_Normal_ReturnsCorrectNumberOfAds()
        {
            var target = new AdRepository(_mockDataService);

            var result = target.GetCoverAds(_startDate, _endDate, "AdId", true, 9000, 0);

            Assert.AreEqual(4, result.DisplayAds.Count());
            Assert.AreEqual(0, result.Page);
            Assert.AreEqual(1, result.TotalPageCount);
        }
        public void CanDeleteAd_AdDoesNotExists_ReturnFalse()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            AdRepository    adRepo         = new AdRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                Assert.IsFalse(adRepo.CanDeleteAd(56));
            }
        }
Beispiel #5
0
        public void GetTopAds_Normal_ReturnsCorrectLength()
        {
            const int maxLength = 5;

            var target = new AdRepository(_mockDataService);

            var result = target.GetTopAds(_startDate, _endDate, maxLength);

            Assert.AreEqual(maxLength, result.DisplayAds.Count());
        }
        public void CanDeleteAd_AdDoesNotExists_ReturnFalse()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            AdRepository adRepo = new AdRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                Assert.IsFalse(adRepo.CanDeleteAd(56));
            }
        }
        public void GetAdType_AdDoesNotExist_ReturnUndefined()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository      repo           = new Repository(sessionFactory);
            AdRepository    adRepo         = new AdRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                Assert.AreEqual(AdTypeEnum.Undefined, adRepo.GetAdType(18));
            }
        }
Beispiel #8
0
        static void Main()
        {
            IWindowFormsFactory WindowsFormsFactory = new WindowFormsFactory();

            UserRepository UserRepository = new UserRepository();
            AdRepository   AdRepository   = new AdRepository();

            MainFormController MainController = new MainFormController(WindowsFormsFactory, UserRepository, AdRepository);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new WalkMyDog.PresentationLayer.MainForm(MainController));
        }
Beispiel #9
0
        public void GetAllAds_SortsNestedDescending()
        {
            var target = new AdRepository(_mockDataService);

            var result = target.GetAllAds(_startDate, _endDate, "Brand.BrandId", false, 9000, 0);

            int lastBrandId = Int32.MaxValue;

            foreach (Ad ad in result.DisplayAds)
            {
                Assert.IsTrue(ad.Brand.BrandId <= lastBrandId);
                lastBrandId = ad.Brand.BrandId;
            }
        }
        public void GetTopBrands_Normal_SortedDescendingByPageCoverageAmount()
        {
            var target = new AdRepository(_mockDataService);

            var result = target.GetTopBrands(_startDate, _endDate, 5);

            decimal lastPageCoverageAmount = decimal.MaxValue;

            foreach (TopBrandViewModel vm in result)
            {
                Assert.IsTrue(vm.TotalPageCoverage <= lastPageCoverageAmount);
                lastPageCoverageAmount = vm.TotalPageCoverage;
            }
        }
Beispiel #11
0
        public ModelResult GetAdvertsings(ModelRequest request)
        {
            var modelResult = new ModelResult();

            modelResult.Data = AdRepository.GetAdvertisings().
                               Select(x => new AdResult
            {
                ID       = x.ID,
                Image    = x.Image,
                Position = x.Position,
                Url      = x.Url
            });
            return(modelResult);
        }
Beispiel #12
0
        public void GetTopAds_Normal_SortedDescendingByPageCoverageAmount()
        {
            var target = new AdRepository(_mockDataService);

            var result = target.GetTopAds(_startDate, _endDate, 5);

            decimal lastPageCoverageAmount = decimal.MaxValue;

            foreach (Ad ad in result.DisplayAds)
            {
                Assert.IsTrue(ad.NumPages <= lastPageCoverageAmount);
                lastPageCoverageAmount = ad.NumPages;
            }
        }
Beispiel #13
0
        public void GetTopAds_Normal_AreFiveLargest()
        {
            const int maxLength = 5;

            var target = new AdRepository(_mockDataService);

            var result = target.GetTopAds(_startDate, _endDate, maxLength);

            foreach (Ad ad in result.DisplayAds)
            {
                // This number was determined by looking at our sample set.  This should probably be determined programmatically.
                Assert.IsTrue(ad.NumPages >= 1);
            }
        }
Beispiel #14
0
        public void GetAllAds_SortsAscending()
        {
            var target = new AdRepository(_mockDataService);

            var result = target.GetAllAds(_startDate, _endDate, "AdId", true, 9000, 0);

            int lastAdId = Int32.MinValue;

            foreach (Ad ad in result.DisplayAds)
            {
                Assert.IsTrue(ad.AdId > lastAdId);
                lastAdId = ad.AdId;
            }
        }
        public override Tuple <Option <IEntityWrapper>, IEnumerable <ValidationRule> > Bootstrap(IReadableAtom <EA.Repository> repository)
        {
            var entityWrapper    = new AdEntityWrapper();
            var entityRepository = new AdRepository(repository, entityWrapper);

            var exportCmd = new ExportToADRepoCommand(entityRepository);

            Register(new Menu("AD Repo Connector",
                              new MenuItem("Export to AD Repo", exportCmd.ToMenuHandler())));

            return(Tuple.Create(
                       Options.Some(entityWrapper as IEntityWrapper),
                       Enumerable.Empty <ValidationRule>()));
        }
Beispiel #16
0
        public void GetTopAds_Normal_DistinctByBrand()
        {
            const int maxLength = 5;

            var target = new AdRepository(_mockDataService);

            var result = target.GetTopAds(_startDate, _endDate, maxLength);

            HashSet <int> brands = new HashSet <int>();

            foreach (Ad ad in result.DisplayAds)
            {
                Assert.IsTrue(brands.Add(ad.Brand.BrandId));
            }
        }
        public void GetTopBrands_Normal_DistinctByBrand()
        {
            const int maxLength = 5;

            var target = new AdRepository(_mockDataService);

            var result = target.GetTopBrands(_startDate, _endDate, maxLength);

            HashSet <string> brands = new HashSet <string>();

            foreach (TopBrandViewModel vm in result)
            {
                Assert.IsTrue(brands.Add(vm.BrandName));
            }
        }
Beispiel #18
0
        public void GetTopAds_Normal_SecondarySortBrandName()
        {
            var target = new AdRepository(_mockDataService);

            var result = target.GetTopAds(_startDate, _endDate, 5);

            decimal lastPageCoverageAmount = decimal.MaxValue;
            string  lastBrandName          = null;

            foreach (Ad ad in result.DisplayAds)
            {
                if (ad.NumPages == lastPageCoverageAmount)
                {
                    Assert.IsTrue(string.Compare(ad.Brand.BrandName, lastBrandName) > 0);
                }

                lastPageCoverageAmount = ad.NumPages;
                lastBrandName          = ad.Brand.BrandName;
            }
        }
        public void GetTopBrands_Normal_SecondarySortBrandName()
        {
            var target = new AdRepository(_mockDataService);

            var result = target.GetTopBrands(_startDate, _endDate, 5);

            decimal lastPageCoverageAmount = decimal.MaxValue;
            string  lastBrandName          = null;

            foreach (TopBrandViewModel vm in result)
            {
                if (vm.TotalPageCoverage == lastPageCoverageAmount)
                {
                    Assert.IsTrue(string.Compare(vm.BrandName, lastBrandName) > 0);
                }

                lastPageCoverageAmount = vm.TotalPageCoverage;
                lastBrandName          = vm.BrandName;
            }
        }
Beispiel #20
0
        public void Owner_UpdateOwnerAd()
        {
            Owner   Owner   = (Owner)UserFactory.CreateOwner("Owner123", "testnaLozinka", "Ivan", "Horvat", "123456789", "Unska 3", "Zagreb", 40, UserType.OWNER);
            OwnerAd OwnerAd = (OwnerAd)AdFactory.CreateOwnerAd(40.0, "Setam pse POVOLJNO", AdStatus.ACTIVE,
                                                               "Obozavam pse", new DateTime(2019, 8, 28, 12, 5, 0), 3, 4, Owner);

            Owner.AddAd((OwnerAd)OwnerAd);

            AdRepository AdRepository = new AdRepository();

            UserRepository repository = new UserRepository();

            repository.AddUser(Owner);

            OwnerAd.Title = "Setam pse POVOLJNO";
            AdRepository.UpdateAd(OwnerAd);
            repository.UpdateUser(Owner);

            Debug.Assert(Owner.Ads[0].Title.Equals("Setam pse POVOLJNO"));

            repository.DeleteUser(Owner);
        }
Beispiel #21
0
        public void Walker_UpdateWalkerAd()
        {
            Walker   Walker   = (Walker)UserFactory.CreateWalker("Walker123", "testnaLozinka", "Ivan", "Horvat", "123456789", "Unska 3", "Zagreb", 40, UserType.WALKER, true, false);
            WalkerAd WalkerAd = (WalkerAd)AdFactory.CreateWalkerAd(40.0, "Setam pse POVOLJNO", AdStatus.ACTIVE,
                                                                   "Obozavam pse", new DateTime(2019, 8, 28, 12, 5, 0), 3, 4, Walker);

            Walker.AddAd((WalkerAd)WalkerAd);

            AdRepository AdRepository = new AdRepository();

            UserRepository repository = new UserRepository();

            repository.AddUser(Walker);

            WalkerAd.Title = "Setam pse POVOLJNO";
            AdRepository.UpdateAd(WalkerAd);
            repository.UpdateUser(Walker);

            Debug.Assert(Walker.Ads[0].Title.Equals("Setam pse POVOLJNO"));

            repository.DeleteUser(Walker);
        }
Beispiel #22
0
        // A production app would also include an OnStop override to provide for
        // graceful shut-downs of worker-role VMs.  See
        // http://azure.microsoft.com/en-us/documentation/articles/cloud-services-dotnet-multi-tier-app-storage-3-web-role/#restarts
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections.
            ServicePointManager.DefaultConnectionLimit = 12;

            // Read database connection string and open database.
            var dbConnString = CloudConfigurationManager.GetSetting("AdsDbConnectionString");

            repository = new AdRepository(dbConnString);

            // Open storage account using credentials from .cscfg file.
            var storageAccount = CloudStorageAccount.Parse
                                     (RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));

            Trace.TraceInformation("Creating images blob container");
            var blobClient = storageAccount.CreateCloudBlobClient();

            imagesBlobContainer = blobClient.GetContainerReference("images");
            if (imagesBlobContainer.CreateIfNotExists())
            {
                // Enable public access on the newly created "images" container.
                imagesBlobContainer.SetPermissions(
                    new BlobContainerPermissions
                {
                    PublicAccess = BlobContainerPublicAccessType.Blob
                });
            }

            Trace.TraceInformation("Creating images queue");
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

            imagesQueue = queueClient.GetQueueReference("images");
            imagesQueue.CreateIfNotExists();

            Trace.TraceInformation("Storage initialized");
            return(base.OnStart());
        }
 public GoToClassifierCommand(AdRepository repo)
 {
     Repo = repo;
 }
Beispiel #24
0
 public ValidateProblemOptionCompositionCommand(AdRepository repo)
 {
     Repo = repo;
 }
Beispiel #25
0
        public void SearchAdsByTitle_SearchStringIsNull_ReturnEverythingOrderedByCreationDate()
        {
            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 = "Moto",
                    LabelUrlPart = "Moto"
                };

                Ad a = new Ad
                {
                    Title = "titre 1",
                    Body = "content",
                    CreatedBy = u,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 12)
                };
                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, 18)
                };
                c.AddAd(a2);
                cat.AddAd(a2);
                repo.Save<Ad>(a2);

                repo.Flush();

                #endregion

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

                // Then
                Assert.AreEqual(2, result.Count);
                Assert.AreEqual(a2, result[0]);
                Assert.AreEqual(a, result[1]);
            }
        }
Beispiel #26
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));
            }
        }
Beispiel #27
0
        public void GetAdType_AdDoesNotExist_ReturnUndefined()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository repo = new Repository(sessionFactory);
            AdRepository adRepo = new AdRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                Assert.AreEqual(AdTypeEnum.Undefined, adRepo.GetAdType(18));
            }
        }
Beispiel #28
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]);
            }
        }
Beispiel #29
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);
            }
        }
Beispiel #30
0
 public AdController(AdRepository adRepository)
 {
     _adRepository = adRepository;
 }
 public ValidateConflictingOptionsCommand(AdRepository repo)
 {
     Repo = repo;
 }
 public MultipleProblemsAddressedByAnOptionCommand(AdRepository repo)
 {
     Repo = repo;
 }
Beispiel #33
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));
            }
        }
Beispiel #34
0
        public IEnumerable <AdvertisingModel> GetAdvertising(int numberOfAd)
        {
            AdRepository repository = new AdRepository();

            return(repository.GetAdvertising(numberOfAd));
        }
Beispiel #35
0
 public void GetAdsByEmail_UnknownEmail_ReturnEmptyListOfAds()
 {
     ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
     AdRepository adRepo = new AdRepository(sessionFactory);
     List<BaseAd> ads = adRepo.GetAdsByEmail("unknown Email").ToList();
     Assert.AreEqual(0, ads.Count);
 }
Beispiel #36
0
        public void GetSpamRequestAd_AdNotSpam_ReturnTrue()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository      repo           = new Repository(sessionFactory);
            AdRepository    adRepo         = new AdRepository(sessionFactory);

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

                #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);

                #endregion

                SpamAdRequest adR = new SpamAdRequest(a);

                repo.Save(adR);

                repo.Flush();

                #endregion

                Assert.IsNull(adRepo.GetSpamRequestAd(999));
            }
        }
Beispiel #37
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);
            }
        }
Beispiel #38
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]);
            }
        }
Beispiel #39
0
 public AdService()
 {
     _adRepository = new AdRepository();
 }