public void when_campaign_has_been_sent_then_show_error()
 {
     int campaignId = 88;
     var campaignService = new Mock<ICampaignService>();
     campaignService.Expect(cs => cs.RetrieveById(campaignId)).Returns(new CampaignBuilder().WithId(campaignId).WithSent(DateTime.Now).Build());
     var controller = new CampaignController(campaignService.Object, null, null, null, null, null);
     var result = (RedirectToRouteResult)controller.Send(campaignId);
     AssertRedirectToRoute(result, "Preview");
     Assert.AreEqual(88, result.RouteValues["campaignId"]);
 }
        public void RemoveMessageItemAndPreview()
        {
            const int messageItemId = 62;
            var campaignService = new Mock<ICampaignService>();
            var controller = new CampaignController(campaignService.Object, null, null, null, null, ServiceBuilder.Saver.Object);
            var messageItem = new MessageItemBuilder().WithId(messageItemId).Build();

            campaignService.Expect(cs => cs.RetrieveMessageItemById(messageItemId))
                .Returns(messageItem);
            campaignService.Expect(cs => cs.MarkMessageItemForDeletion(messageItem));

            var result = (RedirectToRouteResult)controller.RemoveMessageItemAndPreview(messageItemId, 1);
            AssertRedirectToRoute(result, "Preview");
            campaignService.VerifyAll();
        }
        public void Index()
        {
            var campaignService = new Mock<ICampaignService>();
            campaignService.Expect(cs => cs.RetrieveAll()).Returns(new List<Campaign>
                   {
                       new CampaignBuilder().Build(),
                       new CampaignBuilder().WithName("July mail run").Build(),
                       new CampaignBuilder().WithName("End of financial year").Build()
                   }.AsQueryable());

            var controller = new CampaignController(campaignService.Object, null, null, null, null, ServiceBuilder.Saver.Object);
            var result = (ViewResult)controller.Index();
            var data = (List<Campaign>)result.ViewData.Model;

            Assert.AreEqual(result.ViewName, "Index");
            Assert.AreEqual(3, data.Count);
        }
 public void EstablishContext()
 {
     EstablishAgencyContext();
     saver = new Mock<ICanSave>();
     saver
         .Expect(s => s.AddToContext(It.IsAny<Campaign>()))
         .Callback((Campaign c) => c.Id = SAVED_CAMPAIGN_ID) // This is a bit of a hack. I'm setting the Id here because Campaign is not passed to SaveAll where the Id should be set.
         .Verifiable();
     saver.Expect(s => s.SaveAll()).Verifiable();
     calendar = new Mock<ICalendarService>();
     calendar.Expect(c => c.CurrentDateTime).Returns(new DateTime(2009, 1, 25, 11, 48, 12));
     matchResult = new MatchResult(new BuyerBuilder().Build(), new List<Product> {new ProductBuilder().Build()});
     campaignService = new Mock<ICampaignService>();
     campaignService.Expect(cs => cs.Match(It.IsAny<Campaign>())).Callback((Campaign c) => c.Matches = new List<MatchResult> {matchResult});
     campaignService.Expect(cs => cs.RetrieveById(SAVED_CAMPAIGN_ID)).Returns(
         new CampaignBuilder().WithId(SAVED_CAMPAIGN_ID).WithMessage(new MessageBuilder().Build()).Build());
     messageService = new Mock<IMessagingService>();
     controller = new CampaignController(campaignService.Object, messageService.Object,calendar.Object,null,null,saver.Object);
 }