public void Create_WcfThrowsFaultException_ThrowsServiceValidationException() { var exception = new FaultException(new FaultReason("reason"), new FaultCode("code")); var subject = "FOO"; var inModel = new HelpDeskModel { Subject = subject }; var request = MappingEngine.Map <InsHelpDeskNotificationRequest>(inModel); var sinf = new List <RelatedCodeModel> { new RelatedCodeModel { Dominant = true, SubordinateCode = subject } }; var sula = new RelatedCodeModel { Dominant = true, SubordinateCode = subject, SubordinateDescription = "LAPCODE" }; mockAdwService.Setup(m => m.GetRelatedCodes("SINF", inModel.Subject)).Returns(sinf); mockAdwService.Setup(m => m.GetRelatedCode("SULA", request.subjectArea, string.Empty)).Returns(sula); mockMappingEngine.Setup(m => m.Map <InsHelpDeskNotificationRequest>(inModel)).Returns(request); mockHelpDeskWcf.Setup(m => m.Insert(request)).Throws(exception); SystemUnderTest().Create(inModel); }
public void Create_WithoutLapCode_Valid() { var subject = "FOO"; var inModel = new HelpDeskModel { Subject = subject }; var request = MappingEngine.Map <InsHelpDeskNotificationRequest>(inModel); var response = new InsHelpDeskNotificationResponse { requestID = 123, ExecutionResult = new ExecutionResult { Status = ExecuteStatus.Success } }; var sinf = new List <RelatedCodeModel> { new RelatedCodeModel { Dominant = true, SubordinateCode = subject } }; var sula = new RelatedCodeModel { Dominant = true, SubordinateCode = subject, SubordinateDescription = string.Empty }; mockAdwService.Setup(m => m.GetRelatedCodes("SINF", inModel.Subject)).Returns(sinf); mockAdwService.Setup(m => m.GetRelatedCode("SULA", request.subjectArea, "TODO")).Returns(sula); mockMappingEngine.Setup(m => m.Map <InsHelpDeskNotificationRequest>(inModel)).Returns(request); mockHelpDeskWcf.Setup(m => m.Insert(request)).Returns(response); var result = SystemUnderTest().Create(inModel); Assert.IsTrue(result == response.requestID); mockMappingEngine.Verify(m => m.Map <InsHelpDeskNotificationRequest>(inModel), Times.Once()); mockHelpDeskWcf.Verify(m => m.Insert(request), Times.Once()); }
/// <summary> /// Insert a Help desk notification /// </summary> /// <param name="model"></param> /// <returns>ID of the record inserted</returns> public int Create(HelpDeskModel model) { var request = model.ToInsHelpDeskNotificationRequest(); ValidateRequest(request); try { var ret = AdwService.GetRelatedCodes("SINF", model.Subject).ToCodeModelList(); request.subjectArea = ret[0].Code; string lapCode = AdwService.GetRelatedCodeDescription("SULA", request.subjectArea, "TODO");//TODO:Fix if (!string.IsNullOrEmpty(lapCode)) { request.description = string.Format("{0}: {1} ", lapCode, model.Description); } else { request.description = string.Format("{0} ", model.Description); } var service = Client.Create <IHelpDeskNotification>("HelpDeskNotification.svc"); request.userType = "Remote Services Client"; request.callTakenBy = "Remote Services Web Form"; request.status = "New"; request.module = "HelpDeskService"; request.priority = "1-Super User"; request.summary = "a"; request.subjectArea = request.subjectArea; var response = service.Insert(request); // Only responses with IResponseWithExecutionResult need to call ValidateResponse ValidateResponse(response); return(response.requestID); } catch (FaultException <ValidationFault> vf) { throw vf.ToServiceValidationException(); } catch (FaultException fe) { throw fe.ToServiceValidationException(); } }
/// <summary> /// Convert to the ins help desk notification request. /// </summary> /// <param name="src">The source.</param> /// <returns></returns> public static InsHelpDeskNotificationRequest ToInsHelpDeskNotificationRequest(this HelpDeskModel src) { var dest = new InsHelpDeskNotificationRequest(); dest.application = src.Application; dest.callTakenBy = src.UserId; dest.dateLogged = src.Date; dest.email = src.Email; dest.identifier = src.Identifier; dest.name = src.Name; dest.org = src.Organisation; dest.phone = src.Phone; dest.site = src.Site; dest.subjectArea = src.Subject; dest.userID = src.UserId; dest.description = src.Description; return(dest); }