public MotorBoatAdDetailsModel(MotorBoatAd ad, IHelperService helper)
     : base(ad)
 {
     BoatType = ad.MotorBoatType != null ? ad.MotorBoatType.Label : String.Empty;
     MotorType = ad.MotorType != null ? ad.MotorType.Label : String.Empty;
     Year = ad.Year != 0 ? ad.Year : (int?) null;
     Length = ad.Length != 0 ? String.Format(helper.GetCulture(), "{0:F2} Mtr", ad.Length) : String.Empty;
     Hp = ad.Hp != 0 ? String.Format("{0} Cv", ad.Hp) : String.Empty;
 }
        public AdMotorBoatCreateModel(MotorBoatAd ad)
            : base(ad)
        {
            this.Hp = ad.Hp;
            this.Length = ad.Length;

            if (ad.Type != null)
                this.SelectedTypeId = ad.Type.Id;
            if (ad.MotorType != null)
                this.SelectedMotorTypeId = ad.MotorType.Id;

            if (ad.Year != 0)
                this.SelectedYearId = ad.Year;
            this.Type = (int)AdTypeEnum.MotorBoatAd;
        }
        public void AdvancedSearchAds_MotorBoatAd_MotorBoatProperties_ReturnMotorBoatAd()
        {
            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
                };

                MotorBoatType mbt = new MotorBoatType()
                {
                    Id = 5,
                    Label = "Bois"
                };

                MotorBoatEngineType mt = new MotorBoatEngineType()
                {
                    Id = 7,
                    Label = "4 temps"
                };

                MotorBoatAd bat = new MotorBoatAd
                {
                    Id = 1,
                    Title = "bateau",
                    Body = "la desc du bateau",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat,
                    CreatedBy = u,
                    Price = 1000,
                    Hp = 100,
                    Length = 6,
                    MotorBoatType = mbt,
                    MotorType = mt,
                    Year = 2005
                };

                repo.Save(mbt);
                repo.Save(mt);
                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
                {
                    MotorBoatTypeId = 1,
                    MotorEngineTypeId = 1,
                    MinHp = 99,
                    MaxHp = 100,
                    MinLength = 6,
                    MaxLength = 10,
                    MinYear = 2004,
                    MaxYear = 2006
                };

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

                // Then
                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(a, result[0]);
            }
        }
        public void GetAdDetails_MotorBoatAdExists_GetAdFromRepoAndReturnMotoAdModel()
        {
            // Given
            MotorBoatAd ad = new MotorBoatAd() { 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.MotorBoatAd);
            adRepoMock.Setup(r => r.GetAdById<MotorBoatAd>(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 MotorBoatAdDetailsModel);
        }