public void UnitTest7() { MockHttpSuccessResponse(); var ActualResult = msg91.SendOtpSms(new Msg91SmsOtpRequest() { mobile = "9876543214", otp = 123456, template_id = "temp Message" }); Assert.NotNull(ActualResult); Assert.True(ActualResult.StatusCode == 200); }
public SmsApiResponse SendOtpSms(SmsOtpRequest smsRequest) { SmsApiResponse smsApiResponse = new SmsApiResponse() { StatusCode = 200 }; if (smsRequest != null) { if (string.IsNullOrWhiteSpace(smsRequest.Mobile)) { smsApiResponse.StatusCode = 400; smsApiResponse.ErrorList = GetSmsApiValidationResponses(1001, nameof(smsRequest.Mobile) + " is required.", nameof(smsRequest.Mobile)); return(smsApiResponse); } if (!Regex.IsMatch(smsRequest.Mobile, RegexPattern.mobile_number_validation_Patterns.GetCombinedPattern())) { smsApiResponse.StatusCode = 400; smsApiResponse.ErrorList = GetSmsApiValidationResponses(1001, nameof(smsRequest.Mobile) + " should be valid. Format -: xxxxxxxxxx ", nameof(smsRequest.Mobile)); return(smsApiResponse); } if (smsRequest.CountryCode <= 0) { smsApiResponse.StatusCode = 400; smsApiResponse.ErrorList = GetSmsApiValidationResponses(1001, nameof(smsRequest.CountryCode) + " is required.", nameof(smsRequest.CountryCode)); return(smsApiResponse); } Msg91SmsOtpRequest smsOtpRequest = new Msg91SmsOtpRequest() { mobile = string.Format("{0}{1}", smsRequest.CountryCode, smsRequest.Mobile), template_id = string.IsNullOrWhiteSpace(smsRequest.MessageTemplate) ? "5dc5a276d6fc0553643c78b4" : smsRequest.MessageTemplate, otp = 12345 }; Msg91ApiResponse msg91ApiResponse = _msg91.SendOtpSms(smsOtpRequest); if (msg91ApiResponse.StatusCode == 200) { BaseResponse baseResponse = msg91ApiResponse.MessageResponse; if (string.Equals(baseResponse.Type, "error", StringComparison.OrdinalIgnoreCase)) { smsApiResponse.StatusCode = 400; smsApiResponse.ErrorList = GetSmsApiValidationResponses(1001, baseResponse.Message); } else { smsApiResponse.StatusCode = 200; smsApiResponse.Response = new SmsResponse() { Message = baseResponse.Message, RequestId = baseResponse.RequestId, Type = baseResponse.Type }; } } else { smsApiResponse.StatusCode = 400; smsApiResponse.ErrorList = GetSmsApiValidationResponses(1001, "otp not verified"); } } else { smsApiResponse.StatusCode = 400; smsApiResponse.ErrorList = new List <SmsApiValidationResponse>() { new SmsApiValidationResponse() { Code = 1001, FieldName = nameof(smsRequest), Message = "Request Data is Invlid." } }; } return(smsApiResponse); }