public void FindEmployeeById_Action_Fails() { // Arrange GenericServiceResponse <EmployeeDto> fakeResponse = null; mockClientServicesProvider.Setup(x => x.Logger).Returns(mockLogger.Object).Verifiable(); mockClientServicesProvider.Setup(x => x.EmployeeService.FindEmployeeById(It.IsAny <int>())).Returns(fakeResponse).Verifiable(); var viewModel = new GenericItemViewModel <EmployeeDto>(); var action = new FindEmployeeById <GenericItemViewModel <EmployeeDto> >(mockClientServicesProvider.Object) { OnComplete = model => viewModel = model }; // Act var result = action.Invoke(1); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(GenericItemViewModel <EmployeeDto>)); Assert.IsNotNull(result.Notifications); Assert.IsInstanceOfType(result.Notifications, typeof(NotificationCollection)); Assert.IsTrue(result.Notifications.Count() == 1); Assert.IsTrue(result.HasErrors); Assert.IsNull(result.Item); }
public void CreatePhoneNumber_Action_Fails() { // Arrange var phoneNumberDto = TestHelper.PhoneNumberDto(); GenericServiceResponse <bool> fakeResponse = null; mockClientServicesProvider.Setup(x => x.Logger).Returns(mockLogger.Object).Verifiable(); mockClientServicesProvider.Setup(x => x.PhoneNumberService.CreatePhoneNumber(phoneNumberDto)).Returns(fakeResponse).Verifiable(); var viewModel = new GenericViewModel(); var action = new CreatePhoneNumber <GenericViewModel>(mockClientServicesProvider.Object) { OnComplete = model => viewModel = model }; // Act var result = action.Invoke(phoneNumberDto); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(GenericViewModel)); Assert.IsNotNull(result.Notifications); Assert.IsInstanceOfType(result.Notifications, typeof(NotificationCollection)); Assert.IsTrue(result.Notifications.Count() == 1); Assert.IsTrue(result.HasErrors); Assert.IsNotNull(result.Success); Assert.IsInstanceOfType(result.Success, typeof(bool)); Assert.IsFalse(result.Success); }
public void GetAllCities_Action_Success() { // Arrange var fakeResponse = new GenericServiceResponse <IEnumerable <CityDto> > { Result = TestHelper.CityDtos() }; mockClientServicesProvider.Setup(x => x.Logger).Returns(mockLogger.Object).Verifiable(); mockClientServicesProvider.Setup(x => x.CityService.GetAllCities()).Returns(fakeResponse).Verifiable(); var viewModel = new GenericListViewModel <CityDto>(); var action = new GetAllCities <GenericListViewModel <CityDto> >(mockClientServicesProvider.Object) { OnComplete = model => viewModel = model }; // Act var result = action.Invoke(); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(GenericListViewModel <CityDto>)); Assert.IsNotNull(result.Notifications); Assert.IsInstanceOfType(result.Notifications, typeof(NotificationCollection)); Assert.IsTrue(result.Notifications.Count() == 0); Assert.IsFalse(result.HasErrors); Assert.IsNotNull(result.Items); Assert.IsInstanceOfType(result.Items, typeof(IEnumerable <CityDto>)); Assert.IsTrue(result.Items.ToList().Count() == TestHelper.CityDtos().Count()); }
public void GetAllPhoneNumbers_Action_Fails() { // Arrange GenericServiceResponse <IEnumerable <PhoneNumberDto> > fakeResponse = null; mockClientServicesProvider.Setup(x => x.Logger).Returns(mockLogger.Object).Verifiable(); mockClientServicesProvider.Setup(x => x.PhoneNumberService.GetAllPhoneNumbers()).Returns(fakeResponse).Verifiable(); var viewModel = new GenericListViewModel <PhoneNumberDto>(); var action = new GetAllPhoneNumbers <GenericListViewModel <PhoneNumberDto> >(mockClientServicesProvider.Object) { OnComplete = model => viewModel = model }; // Act var result = action.Invoke(); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(GenericListViewModel <PhoneNumberDto>)); Assert.IsNotNull(result.Notifications); Assert.IsInstanceOfType(result.Notifications, typeof(NotificationCollection)); Assert.IsTrue(result.Notifications.Count() == 1); Assert.IsTrue(result.HasErrors); Assert.IsNotNull(result.Items); Assert.IsTrue(result.Items.Count() == 0); Assert.IsInstanceOfType(result.Items, typeof(IEnumerable <PhoneNumberDto>)); Assert.IsTrue(result.Items.ToList().Count() == 0); }
public void DeleteWorkflowById_Action_Fails() { // Arrange GenericServiceResponse <bool> fakeResponse = null; mockClientServicesProvider.Setup(x => x.Logger).Returns(mockLogger.Object).Verifiable(); mockClientServicesProvider.Setup(x => x.WorkflowService.DeleteWorkflow(It.IsAny <int>())).Returns(fakeResponse).Verifiable(); var viewModel = new GenericViewModel(); var action = new DeleteWorkflowById <GenericViewModel>(mockClientServicesProvider.Object) { OnComplete = model => viewModel = model }; // Act var result = action.Invoke(1); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(GenericViewModel)); Assert.IsNotNull(result.Notifications); Assert.IsInstanceOfType(result.Notifications, typeof(NotificationCollection)); Assert.IsTrue(result.Notifications.Count() == 1); Assert.IsTrue(result.HasErrors); Assert.IsNotNull(result.Success); Assert.IsInstanceOfType(result.Success, typeof(bool)); Assert.IsFalse(result.Success); }
public void FindNotificationTemplateById_Action_Success() { // Arrange var fakeResponse = new GenericServiceResponse<NotificationTemplateDto> { Result = TestHelper.NotificationTemplateDto() }; mockClientServicesProvider.Setup(x => x.Logger).Returns(mockLogger.Object).Verifiable(); mockClientServicesProvider.Setup(x => x.NotificationTemplateService.FindNotificationTemplateById(It.IsAny<int>())).Returns(fakeResponse).Verifiable(); var viewModel = new GenericItemViewModel<NotificationTemplateDto>(); var action = new FindNotificationTemplateById<GenericItemViewModel<NotificationTemplateDto>>(mockClientServicesProvider.Object) { OnComplete = model => viewModel = model }; // Act var result = action.Invoke(1); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(GenericItemViewModel<NotificationTemplateDto>)); Assert.IsNotNull(result.Notifications); Assert.IsInstanceOfType(result.Notifications, typeof(NotificationCollection)); Assert.IsTrue(result.Notifications.Count() == 0); Assert.IsFalse(result.HasErrors); Assert.IsNotNull(result.Item); Assert.IsInstanceOfType(result.Item, typeof(NotificationTemplateDto)); }
public void DeleteCustomer_Action_Success() { // Arrange var customerDto = TestHelper.CustomerDto(); var fakeResponse = new GenericServiceResponse <bool> { Result = true }; mockClientServicesProvider.Setup(x => x.Logger).Returns(mockLogger.Object).Verifiable(); mockClientServicesProvider.Setup(x => x.CustomerService.DeleteCustomer(customerDto)).Returns(fakeResponse).Verifiable(); var viewModel = new GenericViewModel(); var action = new DeleteCustomer <GenericViewModel>(mockClientServicesProvider.Object) { OnComplete = model => viewModel = model }; // Act var result = action.Invoke(customerDto); // Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(GenericViewModel)); Assert.IsNotNull(result.Notifications); Assert.IsInstanceOfType(result.Notifications, typeof(NotificationCollection)); Assert.IsTrue(result.Notifications.Count() == 0); Assert.IsFalse(result.HasErrors); Assert.IsNotNull(result.Success); Assert.IsInstanceOfType(result.Success, typeof(bool)); Assert.IsTrue(result.Success); }
public HttpActionResult(HttpStatusCode statusCode, string errorMsg) { StatusCode = statusCode; if (CommandResult == null) { CommandResult = new GenericServiceResponse(); } CommandResult.OperationException = new Exception(errorMsg); CommandResult.Success = false; }
/// <summary> /// Echo generic request. /// </summary> /// <param name="input">service request</param> /// <returns>the echo response</returns> public GenericServiceResponse EchoGeneric(GenericServiceRequest input) { Debug.WriteLine(input.Data); Console.WriteLine(input.Data); ServiceContext.Logger.TraceInformation("EchoGeneric: Generic service request data = {0}", input.Data); GenericServiceResponse resp = new GenericServiceResponse(); resp.Data = Environment.MachineName + " (GenericService): " + input.Data; return(resp); }
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); }
internal IHttpActionResult ReturnFormattedResults(GenericServiceResponse results) { if (results == null) { results = new GenericServiceResponse { Success = false, RestResponseStatus = GenericServiceResponse.RestStatus.Error, OperationException = new Exception("Not Found") }; } if (results.Success) { return(Ok(results)); } return(ResponseMessage(results.OperationException.Message == "Not Found" ? Request.CreateResponse(HttpStatusCode.NotFound, results) : Request.CreateResponse(HttpStatusCode.InternalServerError, results))); }
public static async Task <GenericServiceResponse> InsertAuditRecordAsync(LogCommand logCommand, PayloadParent payload, string objectFullName, string lastModifiedBy, ICdcRepository auditRepository) { var response = new GenericServiceResponse(); var cdcAuditEntity = new CdcAuditEntity { AuditLogGuid = Guid.NewGuid(), CreatedById = payload.CreatedById, CreatedDate = payload.CreatedDate, EventType = payload.EventTypeC, ObjectType = objectFullName, LastModifiedById = lastModifiedBy, LastModifiedDate = DateTime.Now, RecordId = payload.RecordIdC, }; var auditResponse = await auditRepository.InsertAuditRecord(cdcAuditEntity, logCommand); if (auditResponse == 1) { response.Success = true; } return(response); }
public HttpActionResult(HttpStatusCode statusCode, GenericServiceResponse commandResult) { StatusCode = statusCode; CommandResult = commandResult; }
public static void AddTestContextFromServiceResponse <TEntity>(TEntity expectedEntity, GenericServiceResponse actualServiceResponse, TestContext testContext, bool expectedSuccess = true, string expectedException = "no Exception") { testContext.Properties.Add("ServiceResponse.Success", $"Expected to be: {expectedSuccess}, Actual Value = {actualServiceResponse.Success.ToString()}"); var respEntity = actualServiceResponse.Entity == null ? "null" : JsonConvert.SerializeObject(actualServiceResponse.Entity); if (expectedSuccess && expectedException == "no Exception") { testContext.Properties.Add(Environment.NewLine + "Results", string.Format("{1}Expected Results: {1}{0}{1}{1}Actual Value:{1}{2}", JsonConvert.SerializeObject(expectedEntity), Environment.NewLine, respEntity)); } else { testContext.Properties.Add(Environment.NewLine + "Results", string.Format("{1}Expected Results: {1}{0}{1}{1}Actual Value:{1}{2}", "null", Environment.NewLine, respEntity)); } testContext.Properties.Add(Environment.NewLine + "Exception", string.Format("{0}Expected to be: {1}{0}Actual Value = {2}", Environment.NewLine, expectedException, actualServiceResponse.OperationException)); }
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()); }