public void RemoveAllPictures()
        {
            var repo = new AdvertRepo(appContext);

            int changedRows = repo.RemoveAllPictures(7);

            Advert advert = repo.Find(7);
            int    count  = advert.Detail.AdPictures.Count();

            Assert.Equal(2, changedRows);
            Assert.Equal(0, count);
        }
        public void Repository_Update2()
        {
            var advertRepo = new AdvertRepo(appContext);

            AdvertDetail newAdDetail = new AdvertDetail
            {
                ID         = 8,
                Title      = "Black Toyota for sale in mogoditshane",
                Body       = "Black 4x4 Toyota cruiser",
                Email      = "*****@*****.**",
                Location   = "Mogoditshane",
                AdPictures = new List <AdPicture>
                {
                    new AdPicture
                    {
                        ID     = 3,
                        Uuid   = "new image",
                        CdnUrl = "new cdn url",
                        Name   = "about me sampl.PNG",
                        Size   = 135083
                    }
                }
            };

            Advert newAd = new Advert
            {
                ID         = 8,
                Status     = EnumTypes.AdvertStatus.SUBMITTED.ToString(),
                CategoryID = 6,
                Detail     = newAdDetail
            };

            string[] includes = new string[]
            {
                "Detail"
            };

            int changedRows = advertRepo.Update(newAd, keyValues: new object[] { newAd.ID },
                                                includes: includes);

            Advert editedAd = advertRepo.Find(8, new Expression <Func <Advert, object> >[] { x => x.Detail });

            //changedRows is 4, detail is null
            Assert.True(changedRows > 0);
            Assert.Equal("Black Toyota for sale in mogoditshane", editedAd.Detail.Title);
            Assert.Equal("*****@*****.**", editedAd.Detail.Email);
            Assert.Equal("Mogoditshane", editedAd.Detail.Location);
            Assert.Equal(new DateTime(2019, 05, 10), editedAd.PublishedDate);
            Assert.Equal("71406569", editedAd.Detail.Phone);
            Assert.Single(editedAd.Detail.AdPictures);
        }
        public void Repository_UpdateWithChildren()
        {
            var      advertRepo   = new AdvertRepo(appContext);
            var      categoryRepo = new CategoryRepo(appContext);
            Category category     = categoryRepo.Find(5);
            Advert   advert       = advertRepo.Find(8);

            advert.Detail.Email  = "*****@*****.**";
            advert.Detail.Body   = "4x4 for sale";
            advert.SubmittedDate = new DateTime(2019, 6, 10);
            advert.Category      = category;

            advertRepo.Update(advert);
            appContext.SaveChanges();

            Assert.Equal(new DateTime(2019, 6, 10), appContext.Adverts.Find(8L).SubmittedDate);
            Assert.Equal("4x4 for sale", appContext.Adverts.Find(8L).Detail.Body);
            Assert.Equal("*****@*****.**", appContext.Adverts.Find(8L).Detail.Email);
            Assert.Equal(5, appContext.Adverts.Find(8L).Category.ID);
            Assert.Equal(2, appContext.Adverts.Find(8L).Category.ParentID);
        }