示例#1
0
        private void RenderSingleItem(StringBuilder sb, Promotion p)
        {

            string destinationLink = "Promotions_edit.aspx?id=" + p.Id + "&page=" + currentPage + "&showdisabled=" 
                              + (this.chkShowDisabled.Checked ? "1":"0") +
                              "&keyword=" + System.Web.HttpUtility.UrlEncode(keyword);
            string deleteLink = destinationLink.Replace("_edit", "_delete");

            sb.Append("<tr><td><a href=\"" + destinationLink + "\">" + p.Name + "</a></td>");
            sb.Append("<td><a href=\"" + destinationLink + "\">");
            switch (p.GetStatus(DateTime.UtcNow))
            {
                case PromotionStatus.Active:
                    sb.Append("<span style=\"color:#060\">Active</span>");
                    break;
                case PromotionStatus.Disabled:
                    sb.Append("<span style=\"color:#999\">Disabled</span>");                    
                    break;
                case PromotionStatus.Expired:
                    sb.Append("<span style=\"color:#600\">Expired</span>");                    
                    break;
                case PromotionStatus.Unknown:
                    sb.Append("<span style=\"color:#999;\">Unknown</span>");                    
                    break;
                case PromotionStatus.Upcoming:
                    sb.Append("<span style=\"color:#d4d40e;\">Upcoming</span>");                    
                    break;
            }                    
            sb.Append("</a></td>");
            sb.Append("<td><a href=\"" + destinationLink + "\">" + (p.IsEnabled ? "<span style=\"color:#060\">Yes</span" : "<span style=\"color:#999\">No</span>") + "</a></td>");
            sb.Append("<td><a onclick=\"return window.confirm('Delete this item?');\" href=\"" + deleteLink + "\" class=\"btn\"><b>Delete</b></a></td>");
            sb.Append("<td><a href=\"" + destinationLink + "\" class=\"btn\"><b>Edit</b></a></td></tr>");
        }
        public void CanGetUpcomingStatus()
        {
            Promotion target = new Promotion();
            target.IsEnabled = true;
            target.StartDateUtc = new DateTime(2010, 09, 1, 0, 0, 0); // Sept 1st, 2010
            target.EndDateUtc = new DateTime(2010, 11, 1, 23, 59, 59); // Nov. 1, 2010

            DateTime currentUtcTime = new DateTime(2010, 08, 1, 0, 0, 0);
            PromotionStatus expected = PromotionStatus.Upcoming;
            PromotionStatus actual;
            actual = target.GetStatus(currentUtcTime);
            Assert.AreEqual(expected, actual, "Augst 1st should return upcoming status");

            DateTime currentUtcTime2 = new DateTime(2010, 8, 31, 23, 59, 59); // August 31st
            PromotionStatus expected2 = PromotionStatus.Upcoming;
            PromotionStatus actual2;
            actual2 = target.GetStatus(currentUtcTime2);
            Assert.AreEqual(expected2, actual2, "August 31th should return Upcoming status");
        }
        public void CanGetDisabledStatus()
        {
            Promotion target = new Promotion();
            target.IsEnabled = false;
            target.StartDateUtc = new DateTime(2010, 09, 1, 0, 0, 0); // Sept 1st, 2010
            target.EndDateUtc = new DateTime(2010, 11, 1, 23, 59, 59); // Nov. 1, 2010

            DateTime currentUtcTime = new DateTime(2010, 9, 15, 23, 59, 59); // Sept. 15th, 11:59:59 pm
            PromotionStatus expected = PromotionStatus.Disabled;
            PromotionStatus actual;
            actual = target.GetStatus(currentUtcTime);
            Assert.AreEqual(expected, actual, "Sept 15th should return disabled");

            DateTime currentUtcTime2 = new DateTime(2009, 9, 1, 0, 0, 0); // Sept. 1th, 2009
            PromotionStatus expected2 = PromotionStatus.Disabled;
            PromotionStatus actual2;
            actual2 = target.GetStatus(currentUtcTime2);
            Assert.AreEqual(expected2, actual2, "Sept 1st from one year ago should return disabled status");

            DateTime currentUtcTime3 = new DateTime(2012, 11, 1, 23, 59, 59); // Sept. 1th, 2012
            PromotionStatus expected3 = PromotionStatus.Disabled;
            PromotionStatus actual3;
            actual3 = target.GetStatus(currentUtcTime3);
            Assert.AreEqual(expected3, actual3, "Nov 1st from 2012 should return disabled status");
        }
        public void CanGetExpiredStatus()
        {
            Promotion target = new Promotion();
            target.IsEnabled = true;
            target.StartDateUtc = new DateTime(2010, 09, 1, 0, 0, 0); // Sept 1st, 2010
            target.EndDateUtc = new DateTime(2010, 11, 1, 23, 59, 59); // Nov. 1, 2010

            DateTime currentUtcTime = new DateTime(2010, 11, 2, 0, 0, 0); // Nov. 2nd
            PromotionStatus expected = PromotionStatus.Expired;
            PromotionStatus actual;
            actual = target.GetStatus(currentUtcTime);
            Assert.AreEqual(expected, actual, "Nov 2nd should return Expired status");

            DateTime currentUtcTime2 = new DateTime(2011, 9, 1, 0, 0, 0); // Sept. 1th, 2011
            PromotionStatus expected2 = PromotionStatus.Expired;
            PromotionStatus actual2;
            actual2 = target.GetStatus(currentUtcTime2);
            Assert.AreEqual(expected2, actual2, "Sept 1st should return Expired status");
        }
        public void CanGetActiveStatus()
        {
            Promotion target = new Promotion();
            target.IsEnabled = true;
            target.StartDateUtc = new DateTime(2010, 09, 1, 0, 0, 0); // Sept 1st, 2010
            target.EndDateUtc = new DateTime(2010, 11, 1, 23, 59, 59); // Nov. 1, 2010

            DateTime currentUtcTime = new DateTime(2010,9,15,23,59,59); // Sept. 15th, 11:59:59 pm
            PromotionStatus expected = PromotionStatus.Active;
            PromotionStatus actual;
            actual = target.GetStatus(currentUtcTime);
            Assert.AreEqual(expected, actual, "Sept 15th should return active status");

            DateTime currentUtcTime2 = new DateTime(2010, 9, 1, 0, 0, 0); // Sept. 1th, 2010
            PromotionStatus expected2 = PromotionStatus.Active;
            PromotionStatus actual2;
            actual2 = target.GetStatus(currentUtcTime2);
            Assert.AreEqual(expected2, actual2, "Sept 1st should return active status");

            DateTime currentUtcTime3 = new DateTime(2010, 11, 1, 23, 59, 59); // Sept. 1th, 2010
            PromotionStatus expected3 = PromotionStatus.Active;
            PromotionStatus actual3;
            actual3 = target.GetStatus(currentUtcTime3);
            Assert.AreEqual(expected3, actual3, "Nov 1st should return active status");
        }