コード例 #1
0
        public void AdvertCountByStatus()
        {
            var repo = new AdvertRepo(appContext);

            var result   = repo.AdvertCountByStatus();
            var expected = new List <CountPercentSummary>
            {
                new CountPercentSummary {
                    Column = "APPROVED", Count = 2, Percent = 28.57
                },
                new CountPercentSummary {
                    Column = "REJECTED", Count = 1, Percent = 14.29
                },
                new CountPercentSummary {
                    Column = "SUBMITTED", Count = 4, Percent = 57.14
                }
            };

            Console.WriteLine("Expected - " + expected[0].Column);
            Console.WriteLine("result - " + result[0].Column);

            Assert.Equal(expected[0].Column, result[0].Column);
            Assert.Equal(expected[1].Column, result[1].Column);
            Assert.Equal(expected[2].Column, result[2].Column);
            Assert.Equal(3, result.Count);
        }
コード例 #2
0
        public void AdvertCountByLocation()
        {
            var repo = new AdvertRepo(appContext);

            var result   = repo.AdvertCountByLocation();
            var expected = new List <CountPercentSummary>
            {
                new CountPercentSummary {
                    Column = "Gaborone", Count = 3, Percent = 42.86
                },
                new CountPercentSummary {
                    Column = "Lobatse", Count = 1, Percent = 14.29
                },
                new CountPercentSummary {
                    Column = "Mochudi", Count = 1, Percent = 14.29
                },
                new CountPercentSummary {
                    Column = "Mogoditshane", Count = 2, Percent = 28.57
                }
            };

            Assert.Equal(expected[0].Column, result[0].Column);
            Assert.Equal(expected[1].Column, result[1].Column);
            Assert.Equal(expected[2].Column, result[2].Column);
            Assert.Equal(4, result.Count);
        }
コード例 #3
0
        public void FindByCategory()
        {
            var repo = new AdvertRepo(appContext);
            IEnumerable <Advert> adverts = repo.FindByCategory(6);

            Assert.Equal(3, adverts.Count());
        }
コード例 #4
0
        } //Färdig form, se MakeNewAd

        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            if (advertWindow.SelectedIndex > -1)
            {
                AdvertRepo.EditAd(AdvertTable.Rows[advertWindow.SelectedIndex], CurrentUser);
            }
            PopulateDataGrid();
        }
コード例 #5
0
        public void PopulateDataGrid()
        {
            DataView dv = AdvertRepo.GetAllAds().DefaultView;

            dv.Sort     = SearchSort.SelectedValue.ToString();
            AdvertTable = dv.ToTable();
            advertWindow.ItemsSource = AdvertTable.DefaultView;
        }
コード例 #6
0
 private void btnDelete_Click(object sender, RoutedEventArgs e)
 {
     if (advertWindow.SelectedIndex > -1)
     {
         AdvertRepo.DeleteAd(Convert.ToInt32(
                                 AdvertTable.Rows[advertWindow.SelectedIndex]["AdID"]));
     }
     PopulateDataGrid();
 }
コード例 #7
0
        public void DeleteFile_BadRequest()
        {
            var repo = new AdvertRepo(appContext);

            JObject result = repo.DeleteFromStorage("98b9adf1-7019-4236-9d06-0bc7cecdc9e3");

            int status = (int)result.Property("status").Value;

            Assert.Equal(400, status);
        }
コード例 #8
0
ファイル: Ad.cs プロジェクト: ElinThrn/Annonser
        private void cmdSearch_Click(object sender, EventArgs e)
        {
            listBox1.DataSource = null;
            if (txtSearch.Text == "")
            {
                listBox1.DataSource = AdvertRepo.GetData();
            }
            AdvertRepo search = new AdvertRepo();

            search.Search(txtSearch.Text, cboCategori, listBox1);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        public void DeleteFile()
        {
            var repo = new AdvertRepo(appContext);

            JObject result = repo.DeleteFromStorage("57ef964b-6fa4-44f9-b019-f1622ace0587");

            string uuid   = result.Property("uuid").Value.ToString();
            string url    = result.Property("url").Value.ToString();
            int    status = (int)result.Property("status").Value;

            Assert.Equal(200, status);
            Assert.Equal("57ef964b-6fa4-44f9-b019-f1622ace0587", uuid);
            Assert.Equal("https://api.uploadcare.com/files/57ef964b-6fa4-44f9-b019-f1622ace0587/", url);
        }
コード例 #12
0
        public void Repository_DeleteCascade()
        {
            var advertRepo = new AdvertRepo(appContext);

            Assert.Equal(2, appContext.Adverts.Count());
            Assert.Equal(2, appContext.AdvertDetails.Count());
            Assert.Equal(4, appContext.AdPictures.Count());

            advertRepo.Delete(6);
            advertRepo.Save();

            Assert.Equal(1, appContext.Adverts.Count());
            Assert.Equal(1, appContext.AdvertDetails.Count());
            Assert.Equal(2, appContext.AdPictures.Count());
        }
コード例 #13
0
 private void btnCreateAd_Click(object sender, RoutedEventArgs e)
 {
     if (AdID == 0)
     {
         AdvertRepo.NewAd(txtNewTitle.Text, txtNewAdText.Text, float.Parse(txtPrice.Text),
                          Convert.ToInt32(cboCategoriesBox.SelectedValue), currentUserID);
     }
     else
     {
         AdvertRepo.DeleteAd(AdID);
         AdvertRepo.NewAd(txtNewTitle.Text, txtNewAdText.Text, float.Parse(txtPrice.Text),
                          Convert.ToInt32(cboCategoriesBox.SelectedValue), currentUserID);
     }
     ((MainWindow)Application.Current.MainWindow).PopulateDataGrid();
     this.Close();
 }
コード例 #14
0
        public void DeleteBatch_Successs()
        {
            var           repo  = new AdvertRepo(appContext);
            List <string> files = new List <string>
            {
                "07fac068-1eb8-4b32-92a4-96bf40d9f9d8",
                "624f9274-f568-484b-8f13-aed558d742b1"
            };

            JObject result = repo.DeleteFromStorage(files);

            string status  = result.Property("status").Value.ToString();
            JArray results = (JArray)result.Property("result").Value;

            Assert.Equal("ok", status);
            Assert.NotEmpty(results);
            Assert.Equal(2, results.Count);
        }
コード例 #15
0
        public void Create()
        {
            Advert advert = GetAdvert();

            AdvertRepo repo = new AdvertRepo(appContext);

            repo.Create(advert);
            repo.Save();

            IEnumerable <Advert> adverts = repo.FindAll();
            Advert ad = adverts.FirstOrDefault(x => x.ID == 8);



            Assert.Equal(8, adverts.Count());
            Assert.Equal("Black Toyota for sale", ad.Detail.Title);
            Assert.Equal(2, ad.Detail.AdPictures.Count());
        }
コード例 #16
0
        public void DeleteBatch_ErrorResponse()
        {
            var           repo  = new AdvertRepo(appContext);
            List <string> files = new List <string>
            {
                "307cbed4-2f11-46ce-a3a4-f1d6fc5c268b",
                "fbc85a6f-baf8-4aad-866e-79c52e017b71"
            };

            JObject result = repo.DeleteFromStorage(files);

            string  status   = result.Property("status").Value.ToString();
            JObject problems = (JObject)result.Property("problems").Value;


            Assert.Equal("ok", status);
            Assert.Equal("Missing in the project", problems.Property(files[0]).Value);
            Assert.Equal("Missing in the project", problems.Property(files[1]).Value);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
 public MainWindow()
 {
     InitializeComponent();
     AdvertTable = AdvertRepo.GetAllAds();
 }