public async Task GetLeadsReturnsExpectedExceptionMessage() { //Arrange var entity = new SFSimpleLeadResults() { LeadGuid = new Guid(), CustomerGuid = Guid.NewGuid(), CAPTier = "CAP", BillAccount = "123456789", CMCCustomerID = 1, CustomerName = "Test Customer", PhoneNumber = "9999999999", Email = "*****@*****.**", County = "TestCounty", STAddress = "999 Test st.", ZipCode = "99999" }; List <SFSimpleLeadResults> entityList = new List <SFSimpleLeadResults> { entity }; MoqLeadRepository.Setup(s => s.GetSfLeads(It.IsAny <SearchLeadSimple>(), It.IsAny <LogCommand>())).ThrowsAsync(new Exception("Lead Repository Exception")); var leadService = new LeadService(MoqLeadRepository.Object , MoqERMSCustomer.Object , MoqcontactRepository.Object //, MoqphoneRepository.Object //, MoqemailRepository.Object , MoqaddressRepository.Object , MoqusageRepository.Object , MoqprogramRepository.Object , MoqcustomerRepository.Object , MoqcdcRepository.Object , MoqLogInstance.Object , MoqLogCommandHandlerDecorator.Object); //Act GenericServiceResponse serviceResponse = await leadService.GetLead(new SearchLeadSimple() { CustomerName = "Test Customer" }, LogCommand); UnitTestHelpers.AddTestContextFromServiceResponse(entityList, serviceResponse, TestContext, false, "Lead Repository Exception"); //Verify services repo is called one time MoqLeadRepository.Verify(s => s.GetSfLeads(It.IsAny <SearchLeadSimple>(), It.IsAny <LogCommand>()), Times.AtLeastOnce); Assert.IsFalse(serviceResponse.Success); Assert.IsNotNull(serviceResponse.OperationException); Assert.AreEqual("Lead Repository Exception", serviceResponse.OperationException.Message); Assert.IsNull(serviceResponse.Entity); }
public async Task GetLeadsReturnsAListOfLeads() { //Arrange var entity = new SFSimpleLeadResults() { LeadGuid = new Guid(), CustomerGuid = Guid.NewGuid(), CAPTier = "CAP", BillAccount = "123456789", CMCCustomerID = 1, CustomerName = "Test Customer", PhoneNumber = "9999999999", Email = "*****@*****.**", County = "TestCounty", STAddress = "999 Test st.", ZipCode = "99999" }; var entityList = new List <SFSimpleLeadResults> { entity }; /* * What I learned: So.. the setup has a fun little thing of a moq return... so you get to pick what it returns. * Then we just check to make sure that it returned something... However, this seems redundant and I should check with howard. */ MoqLeadRepository.Setup(s => s.GetSfLeads(It.IsAny <SearchLeadSimple>(), It.IsAny <LogCommand>())).ReturnsAsync(entityList); var leadService = new LeadService( MoqLeadRepository.Object , MoqERMSCustomer.Object , MoqcontactRepository.Object // , MoqphoneRepository.Object // , MoqemailRepository.Object , MoqaddressRepository.Object , MoqusageRepository.Object , MoqprogramRepository.Object , MoqcustomerRepository.Object , MoqcdcRepository.Object , MoqLogInstance.Object, MoqLogCommandHandlerDecorator.Object); //Act GenericServiceResponse serviceResponse = await leadService.GetLead(new SearchLeadSimple() { NumberOfRecords = 100, CMCCustomerID = 1, CustomerName = "", BillAccount = "", StAddress = "", ZipCode = "", PhoneNumber = "", EmailAddress = "", ProgramGuid = Guid.Empty, }, LogCommand); UnitTestHelpers.AddTestContextFromServiceResponse(entityList, serviceResponse, TestContext); //Verify services repo is called one time MoqLeadRepository.Verify(s => s.GetSfLeads(It.IsAny <SearchLeadSimple>(), It.IsAny <LogCommand>()), Times.AtLeastOnce); Assert.IsNotNull(serviceResponse); Assert.IsTrue(serviceResponse.Success); Assert.IsNull(serviceResponse.OperationException); var leadEntityList = (List <SFSimpleLeadResults>)serviceResponse.Entity; //Assert Assert.IsTrue(leadEntityList.Any()); }