public async Task Can_Get_Sms_Credits() { var response = new Faker <CreditModel>() .RuleFor(r => r.SmsCredits, _ => 1) .Generate(); var mockHttpMessageHandler = new Mock <HttpMessageHandler>(); mockHttpMessageHandler .Protected() .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(JsonConvert.SerializeObject(response)) }); var client = new HttpClient(mockHttpMessageHandler.Object) { BaseAddress = new Uri("https://jusibe.com/smsapi/"), }; var mockFactory = new Mock <IHttpClientFactory>(); mockFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client); var jusibeClient = new JusibeClient(mockFactory.Object); var result = await jusibeClient.GetCredits(); Assert.NotEqual(0, result.SmsCredits); }
public void Sms_Get_Credits() { this.LoadEnvironment(); JusibeClient client = new JusibeClient(new SMSConfig() { AccessToken = System.Environment.GetEnvironmentVariable("Jusibe_Token"), PublicKey = System.Environment.GetEnvironmentVariable("Jusibe_Key") }); var result = client.GetCredits().Result; Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented)); }