Ejemplo n.º 1
0
        public void GetAdPicturesFromModel_2Pictures_FetchThemFromRepoAndSetFirstAsMainImage()
        {
            // Given
            BaseAd ad = new Ad();
            String images = "b9da8b1e-aa77-401b-84e0-a1290130b7b7;b9da8b1e-aa77-401b-84e0-a1290130b999;";

            AdImage img1 = new AdImage() { Id = Guid.Parse("b9da8b1e-aa77-401b-84e0-a1290130b7b7") };
            AdImage img2 = new AdImage() { Id = Guid.Parse("b9da8b1e-aa77-401b-84e0-a1290130b999") };

            var repoMock = new Moq.Mock<IRepository>();
            repoMock.Setup(x => x.Get<AdImage>(Guid.Parse("b9da8b1e-aa77-401b-84e0-a1290130b7b7"))).Returns(img1);
            repoMock.Setup(x => x.Get<AdImage>(Guid.Parse("b9da8b1e-aa77-401b-84e0-a1290130b999"))).Returns(img2);

            AdServices service = new AdServices(null, repoMock.Object, null);

            // When
            BaseAd result = service.GetAdPicturesFromModel(ad, images);

            // Then
            Assert.AreEqual(ad, result);
            Assert.AreEqual(2, ad.Images.Count);
            Assert.AreEqual("b9da8b1e-aa77-401b-84e0-a1290130b7b7", ad.Images[0].Id.ToString());
            Assert.AreEqual(ad, ad.Images[0].BaseAd);
            Assert.IsTrue(ad.Images[0].IsPrimary);
            Assert.AreEqual("b9da8b1e-aa77-401b-84e0-a1290130b999", ad.Images[1].Id.ToString());
            Assert.AreEqual(ad, ad.Images[1].BaseAd);
            Assert.IsFalse(ad.Images[1].IsPrimary);
        }
Ejemplo n.º 2
0
        public AdImage StoreImage(Guid id, Boolean isPrimary)
        {
            AdImage image = null;

            using (TransactionScope scope = new TransactionScope())
            {
                image = new AdImage();
                image.Id = id;
                image.IsPrimary = isPrimary;
                image.UploadedDate = _helper.GetCurrentDateTime();

                _repository.Save<AdImage>(image);

                scope.Complete();
            }

            return image;
        }
Ejemplo n.º 3
0
        public void InsertInMemoryData()
        {
            //-------------------------------------------
            //         LOCATION REFERENCE TABLES
            //-------------------------------------------
            using (ITransaction transaction = _sessionFactory.GetCurrentSession().BeginTransaction())
            {
                //-------------------------------------------
                //         USER TABLE
                //-------------------------------------------

                //Create User 1
                User user = new User();
                user.Email = "*****@*****.**";
                user.Password = "******";
                user.Firstname = "Bruno";
                user.Lastname = "Secret";
                _sessionFactory.GetCurrentSession().Save(user);

                //Create User 2
                User user2 = new User();
                user2.Email = "*****@*****.**";
                user2.Password = "******";
                user2.Firstname = "Nicolas";
                user2.Lastname = "Secret";
                _sessionFactory.GetCurrentSession().Save(user2);

                //-------------------------------------------
                //         IMAGES
                //-------------------------------------------
                AdImage img1 = new AdImage();
                img1.Id = Guid.Parse("acd04523-f2fc-47b5-a7af-50b33c49694f");
                img1.IsPrimary = true;
                img1.UploadedDate = new DateTime();
                log.Info(_sessionFactory.GetCurrentSession().Save(img1));

                AdImage img2 = new AdImage();
                img2.Id = Guid.Parse("262dcc07-8c90-4af8-b99c-12e48afac89f");
                img2.IsPrimary = true;
                img2.UploadedDate = new DateTime();
                log.Info(_sessionFactory.GetCurrentSession().Save(img2));

                //-------------------------------------------
                //         AD TABLE
                //-------------------------------------------

                var normalCategories = _sessionFactory.GetCurrentSession().Query<Category>()
                    .Where(x => x.Type == AdTypeEnum.Ad)
                    .ToList();

                int nbCategories = normalCategories.Count;
                int nbCities = _repository.CountAll<City>();

                for (int i = 1; i < 31; i++)
                {
                    BaseAd ad = null;

                    ad = new Ad();
                    normalCategories[Faker.RandomNumber.Next(0, nbCategories - 1)].AddAd(ad);

                    Faker.Lorem.Words(3).ForEach(s => ad.Title += " " + s);
                    ad.Body = Faker.Lorem.Paragraph();
                    ad.IsOffer = true;

                    ad.CreationDate = DateTime.Now
                        .AddDays(Faker.RandomNumber.Next(-7, 0))
                        .AddHours(Faker.RandomNumber.Next(1, 23))
                        .AddMinutes(Faker.RandomNumber.Next(1, 59))
                        .AddSeconds(Faker.RandomNumber.Next(1, 59));
                    ad.Price = Faker.RandomNumber.Next(1, 300000);
                    ad.PhoneNumber = String.Format("{0}.{1}.{2}", Faker.RandomNumber.Next(20, 99), Faker.RandomNumber.Next(20, 99), Faker.RandomNumber.Next(20, 99));
                    if (i == 1)
                        ad.AddImage(img1);
                    if (i == 2)
                        ad.AddImage(img2);
                    ad.CreatedBy = user;

                    ad.IsActivated = false;
                    ad.ActivationToken = "activateme";

                    _repository.Get<City>(Faker.RandomNumber.Next(1, nbCities)).AddAd(ad);

                    _sessionFactory.GetCurrentSession().Save(ad);

                }

                _sessionFactory.GetCurrentSession().Update(img1);
                _sessionFactory.GetCurrentSession().Update(img2);

                //-------------------------------------------
                //         REFERENCE TABLES
                //-------------------------------------------

                transaction.Commit();
            }
        }