public void LeadsBySource_returns_leads_grouped_by_source()
        {
            var leadSource = new LeadSource {Id = 1, Name = "Downtown"};
            var leads = new List<Lead>
            {
                new Lead {LeadSource = leadSource},
                new Lead {LeadSource = leadSource}
            };

            var mockRepository = new Mock<IRepository<Lead>>();
            mockRepository.Setup(x => x.All()).Returns(leads);

            var controller = new StatisticsController(mockRepository.Object);
            var result = controller.LeadsBySource();

            var sb = new StringBuilder();
            var mockResponse = new Mock<HttpResponseBase>();
            mockResponse.Setup(s => s.Write(It.IsAny<string>())).Callback<string>(c => sb.Append(c));

            var mockControllerContext = new Mock<ControllerContext>();
            mockControllerContext.Setup(x => x.HttpContext.Response).Returns(mockResponse.Object);

            result.ExecuteResult(mockControllerContext.Object);
            Assert.AreEqual(@"[{""label"":""Downtown"",""value"":2}]", sb.ToString());
        }
        public void Edit_edits_a_lead_source()
        {
            var controller = GetLeadSourcesController(_mockRepository.Object, _mockRestClient.Object);

            var leadSource = new LeadSource();
            controller.Edit(leadSource);
            _mockRepository.Verify(r => r.Update(It.IsAny<LeadSource>()), Times.Once);
        }
        public ActionResult Create(string phoneNumber)
        {
            var twilMLApplicationSid = Credentials.TwiMLApplicationSid ?? _restClient.GetApplicationSid();
            var twilioNumber = _restClient.PurchasePhoneNumber(phoneNumber, twilMLApplicationSid);
            var leadSource = new LeadSource
            {
                IncomingNumberNational = twilioNumber.FriendlyName,
                IncomingNumberInternational = twilioNumber.PhoneNumber
            };

            _repository.Create(leadSource);

            return RedirectToAction("Edit", new {id = leadSource.Id});
        }