public void Setup() { //Create Repo _fakeSmsRepo = new Mock <IGenericRepository <Int32, Sms> >(); //Create unitOfWork and add Repo _fakeUnitOfWork = new Mock <IUnitOfWork>(); _fakeUnitOfWork.Setup(x => x.Repositories).Returns(new Dictionary <string, Object>()); _fakeUnitOfWork.Object.Repositories.Add(typeof(Sms).Name, _fakeSmsRepo.Object); //Repositories mapped by entity names in unitOfWork(for detail check UnitOfWork.cs) _fakeUnitOfWork.Object.Repositories.Add(typeof(Country).Name, _fakeCountryRepo.Object); //Repositories mapped by entity names in unitOfWork(for detail check UnitOfWork.cs) //Will work for first line of SendSms List <Country> countries; using (var op = new CountryOperations()) { countries = op.GetAll(); _fakeCountryRepo.Setup(r => r.FindBy(x => x.Cc == toParameter.Substring(1, 2))).Returns(countries.Find(x => x.Cc == toParameter)); } //get real smses from db and add it to repo memory //unit tests should not go to database, all logic should be in memory. using (var op = new SmsOperations()) { _realGetSentSmsResult = op.GetSentSms(dateFrom, dateTo, skip, take); _fakeSmsRepo.Setup(r => r.FilterBy(x => x.DateTime >= dateFrom && x.DateTime <= dateTo).ToList()) .Returns(op.GetAll().FindAll(x => x.DateTime >= dateFrom && x.DateTime <= dateTo).ToList()); } //put mocked unitOfWork to the operation _smsOperations = new SmsOperations(_fakeUnitOfWork.Object); }
public void GetStatistic() { using (var op = new SmsOperations()) { var res = op.GetStatistics(dateFrom, dateTo, mccList); Assert.AreEqual(res.Count, 1); } }
public async Task <List <Statistic> > GetStatistics(DateTime dateFrom, DateTime dateTo, string mccList) { return(await Task <List <Statistic> > .Run(() => { using (var op = new SmsOperations()) { return op.GetStatistics(dateFrom, dateTo, mccList.Split(',').ToList()); } })); }
public async Task <SentSms> GetSentSms(DateTime dateTimeFrom, DateTime dateTimeTo, int skip, int take) { //Added non-blocking code for scalability return(await Task <SentSms> .Run(() => { using (var op = new SmsOperations()) { return op.GetSentSms(dateTimeFrom, dateTimeTo, skip, take); } })); }
public async Task <State> SendSms(string from, string to, string text) { //Added non-blocking code for scalability return(await Task <State> .Run(() => { using (var op = new SmsOperations()) { return op.SendSms(from, to, text); } })); }
public IActionResult SendSms(string [] _selectedPhoneNumbers, string _message) { try { var smsResult = SmsOperations.SendSms(_selectedPhoneNumbers, _message); return(smsResult == true?Json(true) : Json(false)); } catch (Exception exc) { throw exc; } }
/// <summary> /// Initializes client properties. /// </summary> private void Initialize() { Common = new CommonOperations(this); Sms = new SmsOperations(this); Email = new EmailOperations(this); BaseUri = new System.Uri("https://dev.cef.chinacloudapi.cn"); ApiVersion = "1.0"; AcceptLanguage = "en-US"; LongRunningOperationRetryTimeout = 30; GenerateClientRequestId = true; SerializationSettings = new JsonSerializerSettings { Formatting = Newtonsoft.Json.Formatting.Indented, DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List <JsonConverter> { new Iso8601TimeSpanConverter() } }; DeserializationSettings = new JsonSerializerSettings { DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List <JsonConverter> { new Iso8601TimeSpanConverter() } }; CustomInitialize(); DeserializationSettings.Converters.Add(new CloudErrorJsonConverter()); }