public AdWaterSportCreateModel(WaterSportAd ad)
            : base(ad)
        {
            if (ad.Type != null)
                this.SelectedTypeId = ad.Type.Id;

            this.Type = (int)AdTypeEnum.WaterSportAd;
        }
        public void Test_CtorWithAd_NoType()
        {
            // Given
            WaterSportAd ad = new WaterSportAd
            {
                Title = "title",
                City = new City(),
                CreatedBy = new User()
            };

            // When
            WaterSportAdDetailsModel actual = new WaterSportAdDetailsModel(ad);

            // Then
            Assert.AreEqual(ad.Title, actual.Title);
            Assert.AreEqual(String.Empty, actual.SportType);
        }
        public void Test_CtorWithAd()
        {
            // Given
            WaterSportAd ad = new WaterSportAd
            {
                Title = "title",
                Type = new WaterSportType { Label = "Kite" },
                City = new City(),
                CreatedBy = new User()
            };

            // When
            WaterSportAdDetailsModel actual = new WaterSportAdDetailsModel(ad);

            // Then
            Assert.AreEqual(ad.Title, actual.Title);
            Assert.AreEqual(ad.Type.Label, actual.SportType);
        }
예제 #4
0
        public void AdvancedSearchAds_WaterSportAd_WaterSportProperties_ReturnWaterSportAd()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository repo = new Repository(sessionFactory);
            SearchRepository adRepo = new SearchRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                // Given
                #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 = "Bateau à moteur",
                    LabelUrlPart = "Bateau"
                };

                SearchAdCache a = new SearchAdCache
                {
                    AdId = 1,
                    Title = "bateau",
                    Body = "la desc du bateau",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat
                };

                WaterSportType st = new WaterSportType()
                {
                    Label = "pmt"
                };

                WaterSportAd bat = new WaterSportAd
                {
                    Id = 1,
                    Title = "bateau",
                    Body = "la desc du bateau",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat,
                    CreatedBy = u,
                    Type = st
                };

                repo.Save(st);
                repo.Save(p1);
                repo.Save(c);
                repo.Save(cat);
                repo.Save(u);
                repo.Save(bat);
                repo.Save(a);

                repo.Flush();

                #endregion

                AdSearchParameters param = new AdSearchParameters
                {
                    WaterTypeId = 1
                };

                // When
                IList<SearchAdCache> result = adRepo.AdvancedSearchAds<WaterSportAd>(param);

                // Then
                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(a, result[0]);
            }
        }
 public WaterSportAdDetailsModel(WaterSportAd ad)
     : base(ad)
 {
     this.SportType = ad.Type == null ? String.Empty : ad.Type.Label;
 }
예제 #6
0
        public void GetAdDetails_WaterSportAdExists_GetAdFromRepoAndReturnMotoAdModel()
        {
            // Given
            WaterSportAd ad = new WaterSportAd() { Id = 17 };
            ad.CreationDate = new DateTime(2012, 02, 18);
            ad.CreatedBy = new User { Firstname = "Michel" };
            ad.City = new City { Label = "Ville" };

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(x => x.Get<BaseAd>(17)).Returns(ad as BaseAd);

            var adRepoMock = new Moq.Mock<IAdRepository>();
            adRepoMock.Setup(r => r.GetAdType(17)).Returns(AdTypeEnum.WaterSportAd);
            adRepoMock.Setup(r => r.GetAdById<WaterSportAd>(17)).Returns(ad);

            var helperMock = new Moq.Mock<IHelperService>();
            helperMock.Setup(s => s.GetCurrentDateTime()).Returns(new DateTime(2012, 02, 20));

            AdDetailsServices service = new AdDetailsServices(adRepoMock.Object, helperMock.Object);

            // When
            AdDetailsModel actual = service.GetAdDetails(17);

            // Then
            Assert.AreEqual(17, actual.AdId);
            Assert.IsTrue(actual is WaterSportAdDetailsModel);
        }