Ejemplo n.º 1
0
        public ActionResult CreateNewspaper(DateTime? issueDate)
        {
            DateTime dateToUse = issueDate == null ? DateTime.Today.Date : (DateTime)issueDate;

            var newPaper = new Newspaper(dateToUse, reader.GetMaxId());
            newspapers.Add(newPaper);
            writer.SaveNewNewspaper(newPaper);
            return RedirectToAction("Index");
        }
Ejemplo n.º 2
0
        public void PlaceAd_GivenANewNewspaperAndNewAd_CanAddAdToNewsPaper()
        {
            var newsPaper = new Newspaper();
            var testAd = new Ad();

            newsPaper.PlaceAd(testAd);

            Assert.AreEqual(1, newsPaper.AdList.Count);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public void SaveNewNewspaper(Newspaper newspaper)
        {
            using (var conn = new OleDbConnection(string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=False;", connStr)))
            {
                conn.Open();
                var cmd = new OleDbCommand("", conn);
                cmd.CommandText = @"INSERT INTO [Newspapers] (IssueDate) VALUES (@a)";
                cmd.Parameters.Add(new OleDbParameter("a", newspaper.IssueDate.ToOADate()));

                cmd.ExecuteNonQuery();

                foreach (var ad in newspaper.AdList)
                {
                    var adCmd = new OleDbCommand("", conn);
                    adCmd.CommandText = @"INSERT INTO [Ads] (NewspaperId, Name) VALUES (@a, @b)";

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

                    adCmd.ExecuteNonQuery();
                }
            }
        }
Ejemplo n.º 5
0
        public void CreateNewspaper_GivenNewspaperWithTestDateAndNoId_IssueDateAndTestDateMatch()
        {
            var newsPaper = new Newspaper(new DateTime(2012, 2, 28));

            Assert.AreEqual(new DateTime(2012, 2, 28), newsPaper.IssueDate);
        }
Ejemplo n.º 6
0
        public void CreateNewspaper_GivenNewspaperWithNullIssueDateAndId_ReturnsNewspaperWithTodaysDate()
        {
            var newsPaper = new Newspaper(null, 1);

            Assert.AreEqual(DateTime.Now.Date, newsPaper.IssueDate);
        }
Ejemplo n.º 7
0
        public void CreateNewspaper_GivenNewspaperWithNoIssueDate_DefaultToTodaysDate()
        {
            var newsPaper = new Newspaper();

            Assert.AreEqual(DateTime.Now.Date, newsPaper.IssueDate);
        }
Ejemplo n.º 8
0
        public void CreateNewspaper_GivenNewspaperWithNoAds_AdListIsNonNullWithCountZero()
        {
            var newsPaper = new Newspaper();

            Assert.AreEqual(0, newsPaper.AdList.Count);
        }