예제 #1
0
        public void CreateAd_GivenAnAdWithTestName_NameMatchesTestName()
        {
            string testName = "TEST NAME FOR AD";

            var testAd = new Ad(testName);

            Assert.AreEqual("TEST NAME FOR AD", testAd.Name);
        }
예제 #2
0
        public void CreateAd_GivenAnAdWithNullName_NameDefaultsToEmptyString()
        {
            string testName = null;

            var testAd = new Ad(testName);

            Assert.AreEqual(String.Empty, testAd.Name);
        }
예제 #3
0
        public void PlaceAd_GivenANewNewspaperAndNewAd_CanAddAdToNewsPaper()
        {
            var newsPaper = new Newspaper();
            var testAd = new Ad();

            newsPaper.PlaceAd(testAd);

            Assert.AreEqual(1, newsPaper.AdList.Count);
        }
예제 #4
0
        public void PlaceAd_GivenThreeAds_NewspaperAdListCountIsThree()
        {
            var newsPaper = new Newspaper();
            var testAd1 = new Ad();
            var testAd2 = new Ad();
            var testAd3 = new Ad();

            newsPaper.PlaceAd(testAd1);
            newsPaper.PlaceAd(testAd2);
            newsPaper.PlaceAd(testAd3);

            Assert.AreEqual(3, newsPaper.AdList.Count);
        }
예제 #5
0
        public void SaveNewAd(int newspaperId, Ad ad)
        {
            using (var conn = new OleDbConnection(string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=False;", connStr)))
            {
                conn.Open();
                var adCmd = new OleDbCommand("", conn);
                adCmd.CommandText = @"INSERT INTO [Ads] (NewspaperId, Name) VALUES (@a, @b)";

                adCmd.Parameters.Add(new OleDbParameter("a", newspaperId));
                adCmd.Parameters.Add(new OleDbParameter("b", ad.Name));

                adCmd.ExecuteNonQuery();
            }
        }
예제 #6
0
        public ActionResult PlaceAd()
        {
            string adText = TempData["adText"].ToString();

            if (!string.IsNullOrEmpty(adText))
            {
                var adToPlace = new Ad(adText);
                var newspaperToGetNewAd = newspapers.FirstOrDefault(x => x.Id == Convert.ToInt32(TempData["newspaperId"].ToString()));

                if (newspaperToGetNewAd != null)
                {
                    //Persist New Ad in Database
                    newspaperToGetNewAd.PlaceAd(adToPlace);
                    writer.SaveNewAd(newspaperToGetNewAd.Id, adToPlace);
                }
            }

            return RedirectToAction("Index");
        }
예제 #7
0
 public void PlaceAd(Ad newAd)
 {
     AdList.Add(newAd);
 }
예제 #8
0
        public void CreateAd_GivenAdWithNoName_NameDefaultsToEmptyString()
        {
            var testAd = new Ad();

            Assert.AreEqual(String.Empty, testAd.Name);
        }
예제 #9
0
 public void PlaceAd(Ad newAd)
 {
     AdList.Add(newAd);
 }