Beispiel #1
0
        public void Test_CtorWithAd()
        {
            // Given
            MotorBoatAd ad = new MotorBoatAd
            {
                Title         = "title",
                MotorBoatType = new Bea.Domain.Reference.MotorBoatType {
                    Label = "type"
                },
                MotorType = new Bea.Domain.Reference.MotorBoatEngineType {
                    Label = "motor type"
                },
                Year      = 2012,
                Length    = 15.80000d,
                Hp        = 89,
                City      = new City(),
                CreatedBy = new User()
            };

            var helperMock = new Moq.Mock <IHelperService>();

            helperMock.Setup(x => x.GetCulture()).Returns(new System.Globalization.CultureInfo("Fr"));

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

            // Then
            Assert.AreEqual(ad.Title, actual.Title);
            Assert.AreEqual(ad.MotorBoatType.Label, actual.BoatType);
            Assert.AreEqual(ad.MotorType.Label, actual.MotorType);
            Assert.AreEqual(ad.Year, actual.Year);
            Assert.AreEqual("15,80 Mtr", actual.Length);
            Assert.AreEqual("89 Cv", actual.Hp);
        }
Beispiel #2
0
 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;
 }
Beispiel #3
0
        public void Test_CtorWithAd_NoTypes()
        {
            // Given
            MotorBoatAd ad = new MotorBoatAd
            {
                Title     = "title",
                City      = new City(),
                CreatedBy = new User()
            };

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

            // Then
            Assert.AreEqual(ad.Title, actual.Title);
            Assert.AreEqual(String.Empty, actual.BoatType);
            Assert.AreEqual(String.Empty, actual.MotorType);
            Assert.AreEqual(null, actual.Year);
            Assert.AreEqual(String.Empty, actual.Length);
            Assert.AreEqual(String.Empty, actual.Hp);
        }
Beispiel #4
0
        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 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);
        }
Beispiel #6
0
        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]);
            }
        }