public void Test_CtorWithAd()
        {
            // Given
            SailingBoatAd ad = new SailingBoatAd
            {
                Title = "title",
                SailingBoatType = new Bea.Domain.Reference.SailingBoatType { Label = "type" },
                HullType = new Bea.Domain.Reference.SailingBoatHullType { Label = "hull" },
                Year = 2012,
                Length = 15.75000,
                City = new City(),
                CreatedBy = new User()
            };

            var helperMock = new Moq.Mock<IHelperService>();
            helperMock.Setup(x => x.GetCulture()).Returns(new System.Globalization.CultureInfo("Fr"));

            // When
            SailingBoatAdDetailsModel actual = new SailingBoatAdDetailsModel(ad, helperMock.Object);

            // Then
            Assert.AreEqual(ad.Title, actual.Title);
            Assert.AreEqual(ad.SailingBoatType.Label, actual.BoatType);
            Assert.AreEqual(ad.HullType.Label, actual.HullType);
            Assert.AreEqual(ad.Year, actual.Year);
            Assert.AreEqual("15,75 Mtr", actual.Length);
        }
 public SailingBoatAdDetailsModel(SailingBoatAd ad, IHelperService helper)
     : base(ad)
 {
     BoatType = ad.SailingBoatType != null ? ad.SailingBoatType.Label : String.Empty;
     HullType = ad.HullType != null ? ad.HullType.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;
 }
        public AdSailingBoatCreateModel(SailingBoatAd ad)
            : base(ad)
        {
            this.Length = ad.Length;

            if (ad.HullType != null)
                this.SelectedHullTypeId = ad.HullType.Id;
            if (ad.Type != null)
                this.SelectedTypeId = ad.Type.Id;

            if (ad.Year != 0)
                this.SelectedYearId = ad.Year;
            this.Type = (int)AdTypeEnum.SailingBoatAd;
        }
        public void Test_CtorWithAd_NoTypes()
        {
            // Given
            SailingBoatAd ad = new SailingBoatAd
            {
                Title = "title",
                City = new City(),
                CreatedBy = new User()
            };

            // When
            SailingBoatAdDetailsModel actual = new SailingBoatAdDetailsModel(ad, null);

            // Then
            Assert.AreEqual(ad.Title, actual.Title);
            Assert.AreEqual(String.Empty, actual.BoatType);
            Assert.AreEqual(String.Empty, actual.HullType);
            Assert.AreEqual(null, actual.Year);
            Assert.AreEqual(String.Empty, actual.Length);
        }
        public void AdvancedSearchAds_SailingBoatAd_SailingBoatProperties_ReturnSailingBoatAd()
        {
            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
                };

                SailingBoatHullType ht = new SailingBoatHullType()
                {
                    Label = "Bois"
                };

                SailingBoatType st = new SailingBoatType()
                {
                    Label = "Cata"
                };

                SailingBoatAd bat = new SailingBoatAd
                {
                    Id = 1,
                    Title = "bateau",
                    Body = "la desc du bateau",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat,
                    CreatedBy = u,
                    Length = 12,
                    Year = 2005,
                    HullType = ht,
                    SailingBoatType = st
                };

                repo.Save(ht);
                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
                {
                    SailingBoatTypeId = 1,
                    HullTypeId = 1,
                    MinLength = 10,
                    MaxLength = 12,
                    MinYear = 2004,
                    MaxYear = 2006
                };

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

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