public void Arrange() { _mediator = new Mock <IMediator>(); _coursesResponse = new GetCoursesResponse { Courses = new List <Domain.ApprenticeshipCourse.Course>() }; _mediator.Setup(x => x.Send(It.IsAny <GetCoursesQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(_coursesResponse); _coursesController = new CoursesController(_mediator.Object); }
public GetCoursesResponse GetCourses() { var response = new GetCoursesResponse(); try { response.Courses = _coursesRepository.GetAllCourses().ToList(); } catch (Exception ex) { response.IsSuccessful = false; response.Errors.Add("An error has occurred while getting all courses!"); _logger.LogException(ex); } return(response); }
public async Task <IEnumerable <CourseDto> > GetAll() { GetCoursesResponse response = await _courseService.GetAll(new BasicRequest()); return(response.Courses); }
public void GetCourses_InValid() { #region Local var GetCoursesRequest getCoursesRequest = new GetCoursesRequest(); GetCoursesResponse getCoursesResponse = new GetCoursesResponse(); CourseResponse courseResponse = new CourseResponse(); Course[] Course = null; StringBuilder sbError = new StringBuilder(); string Test_Result_Upsert = String.Empty; string validationMessage = string.Empty; #endregion try { for (int i = 0; i < 8; i++) { if (i == 0)//if we are not providing any value in input field { validationMessage = ""; getCoursesRequest.contactCrmId = null; getCoursesRequest.productCrmId = null; } else if (i == 1)//contactCrmId field is optional { validationMessage = ""; getCoursesRequest.contactCrmId = null; getCoursesRequest.productCrmId = ProductCrmId; } else if (i == 2)//ProductCrmId field is mandatory { validationMessage = ""; getCoursesRequest.contactCrmId = ValidNonCebUser[0]; getCoursesRequest.productCrmId = null; } else if (i == 3)//invalid contactCrmId { validationMessage = ""; getCoursesRequest.contactCrmId = ValidNonCebUser[0] + "Invalid"; getCoursesRequest.productCrmId = ProductCrmId; } else if (i == 4)//invalid ProductCrmId { validationMessage = ""; getCoursesRequest.contactCrmId = ValidNonCebUser[0]; getCoursesRequest.productCrmId = ProductCrmId + "Invalid"; } else if (i == 5)//if we provide a contactCrmId of Unregistered or Ghost User { validationMessage = ""; getCoursesRequest.contactCrmId = ValidNonCebUser[0]; getCoursesRequest.productCrmId = ProductCrmId; } else if (i == 6)//IsEntitled is false in response object, if provided ProductCrmId and ContactCrmId not associated with each other { validationMessage = ""; getCoursesRequest.contactCrmId = ValidCebUser[0]; getCoursesRequest.productCrmId = ProductCrmId; } else if (i == 7)//ProductCrmID is Inactive { validationMessage = ""; getCoursesRequest.contactCrmId = ValidNonCebUser[0]; getCoursesRequest.productCrmId = ProductCrmId; } try { getCoursesResponse = target.GetCourses(getCoursesRequest); courseResponse = getCoursesResponse.GetCoursesResult; if (courseResponse.Courses.Length > 0) { Course = courseResponse.Courses; } bool IsEntitledChk = true; if (i == 0 || i == 1) { //Validate Course having isentite true for (int j = 0; j < Course.Length; j++) { if (Course[j].IsEntitled == false) { IsEntitledChk = false; } } } } catch (Exception ex0) { Test_Result_Upsert = _Assert.Execute( () => _Assert.AssertTrue(ex0.Message.Contains(validationMessage), "Validation message is not matched", root)); if (Test_Result_Upsert == "") { _writer.WriteLog(serviceName, "GetCourses_InValid|contactCrmId::" + getCoursesRequest.contactCrmId + "|productCrmId::" + getCoursesRequest.productCrmId, DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString(), "Call GetCourses method ", SBWSCommon.StatusLevelOptions.PASS.ToString(), "To Verify validation messages|Expected validation message:" + ex0.Message, root); } else { _writer.WriteLog(serviceName, "GetCourses_InValid|contactCrmId::" + getCoursesRequest.contactCrmId + "|productCrmId::" + getCoursesRequest.productCrmId, DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString(), "Call GetCourses method ", SBWSCommon.StatusLevelOptions.PASS.ToString(), "To Verify validation messages|Expected validation message:" + ex0.Message + "|Error:" + Test_Result_Upsert, root); } } } } catch (Exception ex) { throw; } finally { getCoursesRequest = null; getCoursesResponse = null; } }
public void GetCourses_valid() { #region Local var GetCoursesRequest getCoursesRequest = new GetCoursesRequest(); GetCoursesResponse getCoursesResponse = new GetCoursesResponse(); CourseResponse courseResponse = new CourseResponse(); Course[] Course = null; StringBuilder sbError = new StringBuilder(); string Test_Result_Upsert = String.Empty; #endregion try { for (int i = 0; i < 5; i++) { if (i == 0)//If Provided ContactCrmId has entitlement for the given ProductCrmId { getCoursesRequest.contactCrmId = ValidNonCebUser[0]; getCoursesRequest.productCrmId = ProductCrmId; } else if (i == 1)//method should return all the courses with in a given ProductCrmId(Course bundle) { getCoursesRequest.contactCrmId = null; getCoursesRequest.productCrmId = ProductCrmId; } else if (i == 2)//number of courses returned in response object of method is mapped with SFDC data { getCoursesRequest.contactCrmId = ValidNonCebUser[0]; getCoursesRequest.productCrmId = ProductCrmId; } try { getCoursesResponse = target.GetCourses(getCoursesRequest); courseResponse = getCoursesResponse.GetCoursesResult; if (courseResponse.Courses.Length > 0) { Course = courseResponse.Courses; } bool IsEntitledChk = true; if (i == 0 || i == 1) { //Validate Course having isentite true for (int j = 0; j < Course.Length; j++) { if (Course[j].IsEntitled == false) { IsEntitledChk = false; } } } //TODO: Call SFDC replica for validation of return courses if (i == 0) { Test_Result_Upsert = _Assert.Execute( () => _Assert.AssertTrue(getCoursesResponse != null, "getCoursesResponse return null", root), () => _Assert.AssertTrue(courseResponse.Courses.Length > 0, "courseResponse return count 0", root), () => _Assert.AssertTrue(IsEntitledChk == true, "IsEntitledChk return false against getcourse", root), () => _Assert.AssertTrue(Course[0].CourseCategory != null, "CourseCategory is null", root), () => _Assert.AssertTrue(Course[0].CourseCrmId != null, "CourseCrmId is null", root), () => _Assert.AssertTrue(Course[0].CourseName != null, "CourseName is null", root), () => _Assert.AssertTrue(Course[0].CourseNumber != null, "CourseNumber is null", root) ); if (Test_Result_Upsert == "") { if (i == 0) { _writer.WriteLog(serviceName, "GetCourses_valid|ContactCrmId::" + getCoursesRequest.contactCrmId + "|ProductCrmId::" + getCoursesRequest.productCrmId, DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString(), "Call GetCourses method If Provided ContactCrmId has entitlement for the given ProductCrmId than, IsEntitled response object is true ", SBWSCommon.StatusLevelOptions.PASS.ToString(), "To Verify that fields available while calling GetCourses Method CourseCategory[0]:" + Course[0].CourseCategory + "|CourseCrmId[0]:" + Course[0].CourseCrmId + "|CourseName[0]:" + Course[0].CourseName + "|CourseNumber[0]:" + Course[0].CourseNumber + "|IsEntitled response object is true", root); } } else { _writer.WriteLog(serviceName, "GetCourses_valid|ContactCrmId::" + getCoursesRequest.contactCrmId + "|ProductCrmId::" + getCoursesRequest.productCrmId, DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString(), "Call GetCourses method If Provided ContactCrmId has entitlement for the given ProductCrmId than, IsEntitled response object is true ", SBWSCommon.StatusLevelOptions.FAIL.ToString(), "To Verify that fields available while calling GetCourses Method CourseCategory[0]:" + Course[0].CourseCategory + "|CourseCrmId[0]:" + Course[0].CourseCrmId + "|CourseName[0]:" + Course[0].CourseName + "|CourseNumber[0]:" + Course[0].CourseNumber + "|IsEntitled response object is true|Error:" + Test_Result_Upsert, root); } } else if (i == 1) { Test_Result_Upsert = _Assert.Execute( () => _Assert.AssertTrue(getCoursesResponse != null, "getCoursesResponse return null", root), () => _Assert.AssertTrue(courseResponse.Courses.Length > 0, "courseResponse return count 0", root), () => _Assert.AssertTrue(IsEntitledChk == true, "IsEntitledChk return false against getcourse", root) ); if (Test_Result_Upsert == "") { _writer.WriteLog(serviceName, "GetCourses_valid|ContactCrmId::" + getCoursesRequest.contactCrmId + "|ProductCrmId::" + getCoursesRequest.productCrmId, DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString(), "Call GetCourses method should return all the courses with in a given ProductCrmId(Course bundle) ", SBWSCommon.StatusLevelOptions.PASS.ToString(), "To Verify that fields available while calling GetCourses Method | Course lenth:" + Course.Length, root); } else { _writer.WriteLog(serviceName, "GetCourses_valid|ContactCrmId::" + getCoursesRequest.contactCrmId + "|ProductCrmId::" + getCoursesRequest.productCrmId, DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString(), "Call GetCourses method should return all the courses with in a given ProductCrmId(Course bundle) ", SBWSCommon.StatusLevelOptions.FAIL.ToString(), "To Verify that fields available while calling GetCourses Method | Course lenth:" + Course.Length + "+Error:" + Test_Result_Upsert, root); } } else if (i == 2) { Test_Result_Upsert = _Assert.Execute( () => _Assert.AssertTrue(getCoursesResponse != null, "getCoursesResponse return null", root), () => _Assert.AssertTrue(courseResponse.Courses.Length > 0, "courseResponse return count 0", root), () => _Assert.AssertTrue(IsEntitledChk == true, "IsEntitledChk return false against getcourse", root) ); if (Test_Result_Upsert == "") { _writer.WriteLog(serviceName, "GetCourses_valid|ContactCrmId::" + getCoursesRequest.contactCrmId + "|ProductCrmId::" + getCoursesRequest.productCrmId, DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString(), "Call GetCourses method should return all the courses with in a given ProductCrmId(Course bundle) ", SBWSCommon.StatusLevelOptions.PASS.ToString(), "To Verify that fields available while calling GetCourses Method | Course lenth:" + Course.Length, root); } else { _writer.WriteLog(serviceName, "GetCourses_valid|ContactCrmId::" + getCoursesRequest.contactCrmId + "|ProductCrmId::" + getCoursesRequest.productCrmId, DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString(), "Call GetCourses method should return all the courses with in a given ProductCrmId(Course bundle) ", SBWSCommon.StatusLevelOptions.FAIL.ToString(), "To Verify that fields available while calling GetCourses Method | Course lenth:" + Course.Length + "+Error:" + Test_Result_Upsert, root); } } } catch (Exception ex0) { throw; } } } catch (Exception ex) { throw; } finally { getCoursesRequest = null; getCoursesResponse = null; } }