以下是我对这两种方法的代码 -
GatherCall正在返回 Twiml 仍然我得到 HTTP 415 和相同的StatusCallback方法。有人可以在这里帮忙吗?我什至无法使用 ngrok 对此进行测试,因为隧道工具在我的组织网络中不起作用。我正在使用 Azure 通过记录所有内容来测试这个。
public TwiMLResult GatherCall([FromRoute] string id, [FromBody] VoiceRequest voiceRequest )
{
_logger.LogInformation("*****************GatherCall - Start****************");
var response = new VoiceResponse();
try
{
_logger.LogInformation("Gather call back for -" + id);
_logger.LogInformation("VoiceRequest parameters-------------------------");
_logger.LogInformation("CallSid : " + voiceRequest.CallSid);
_logger.LogInformation("CallStatus : " + voiceRequest.CallStatus);
_logger.LogInformation("AccountSid : " + voiceRequest.AccountSid);
_logger.LogInformation("From : " + voiceRequest.From);
_logger.LogInformation("To : " + voiceRequest.To);
_logger.LogInformation("Digits : " + voiceRequest.Digits);
_logger.LogInformation("Direction : " + voiceRequest.Direction);
_logger.LogInformation("TranscriptionText …Run Code Online (Sandbox Code Playgroud) 我想通过模拟两个MailMessage和使用moq测试下面的方法SmptpClient
public void SendEmail(string emailAddress, string subject, string body)
{
using (var mail = new MailMessage(NoReplyEmailAddress, emailAddress))
{
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
using (var client = new SmtpClient())
{
client.Host = SmtpHost;
client.Port = SmtpPort;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(mail);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的测试方法是:
public void TestSendEmail()
{
Mock<MailMessage> mailMessageMock = new Mock<MailMessage>();
MailMessage message = (MailMessage)mailMessageMock.Setup(m => new MailMessage()).Returns(mailMessageMock.Object);
Mock<SmtpClient> smtpClientMock = new Mock<SmtpClient>();
smtpClientMock.Setup(s => new SmtpClient()).Returns(smtpClientMock.Object);
EmailService emailService = new …Run Code Online (Sandbox Code Playgroud) 在将字符串解析为双倍时,我们面临着一个问题.我们需要将18位数字符串(<123,456,789,012>.<123456>)转换为double.它只返回小数点后的5位数.当我们试图减少数字的数字时,它工作得很好.我们附上了三个不同场景的屏幕截图.变量'S'是输入,retValue是输出值.
请帮助我们将123,456,789,012.123456转换为123456789012.123456
string s = "123,456,789,012.123456";
double retVal;
System.Globalization.CultureInfo cInfo = new System.Globalization.CultureInfo(System.Web.HttpContext.Curr??ent.Session["culture??"].ToString());
retVal = double.Parse(s, NumberStyles.Any, cInfo);
Run Code Online (Sandbox Code Playgroud)
如何在此方法之外分配“ip”?这是我第一次在这里提问。
public async Task GetIPAsync()
{
var client = new HttpClient();
string response = await client.GetStringAsync(new Uri("https://www.meethue.com/api/nupnp"));
string ip = JArray.Parse(response).First["internalipaddress"].ToString();
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建ASP.NET Core Web API.我有Post/Get方法,如下所示:
[HttpGet]
[Route("api/getProffessionByID/{id}")]
public IHttpActionResult getProffessionByID(Int64 id)
{
AllProffession model = new AllProffession();
try
{
var result = model.GetAllProffession.Where(i => i.id == id).FirstOrDefault();
return Ok(result);
}
catch (Exception ex)
{
return InternalServerError("Something Went Wrong : " + ex.ToString());
}
}
[HttpPost]
[Route("api/savePerson")]
private IHttpActionResult savePerson(PersonModel model)
{
try
{
if (model.name != string.Empty || model.weight != 0 || model.height != 0 || model.proffession != 0)
{
Guid guid = Guid.NewGuid();
Random random = new Random();
int i …Run Code Online (Sandbox Code Playgroud) 嗨我正在尝试测试一个有异常的代码,但是当我尝试测试它时,它说预期的属性未定义为注释类型测试
package Lab1;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import junit.framework.Assert;
class MyMathTest {
MyMath m = new MyMath();
@Test
void testDiv() {
int actual = m.div(6, 2);
int expected = 3;
assertEquals(expected, actual);
}
/* the error is in the upcoming line*/
@Test (expected = IllegalArgumentException.class)
public void testDivException(){
m.div(5, 0);
}
}
Run Code Online (Sandbox Code Playgroud)
这是错误信息
对于注释类型测试,未定义预期属性
我有一个ISFactory如下界面.
namespace MyApp.ViewModels
{
public interface IStreamFactory
{
Stream CreateSPStream(string sPName);
}
}
Run Code Online (Sandbox Code Playgroud)
在Windows非通用版本上,上述功能实现如下.
public Stream CreateSerialPortStream(string serialPortName)
{
var p = new System.IO.Ports.SerialPort();
p.PortName = serialPortName;
p.BaudRate = 9600;
p.RtsEnable = true;
p.DtrEnable = true;
p.ReadTimeout = 150;
p.Open();
return p.BaseStream;
}
Run Code Online (Sandbox Code Playgroud)
Windows Universal中不再提供此实现.我尝试的内容如下所示.
public Stream CreateSerialPortStream(string serialPortName)
{
var selector = SerialDevice.GetDeviceSelector(serialPortName); //Get the serial port on port '3'
var devices = await DeviceInformation.FindAllAsync(selector);
if (devices.Any()) //if the device is found
{
var deviceInfo = devices.First(); …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个接口和一个具体的实现,其中Interface是泛型类型,其中一个方法有一个泛型参数.
我想保留GetPagedList方法参数resourceParams,这样我就可以为接口的不同实现传递不同的resourceParams对象.
使用下面显示的代码时,我收到错误;
方法'ShippingServicesRepository.GetPagedList(U)'的类型参数'U'的约束必须与接口方法IBaseRepository.GetPagedList(U)的类型参数'U'的约束匹配.请考虑使用显式接口实现
这是我的界面;
public interface IBaseRepository<T>
{
bool Save();
bool Exists(int recordId);
bool MarkForDeletion(int recordId);
PagedList<T> GetPagedList<U>(U resourceParams) where U : class;
T Get(int id);
void Add(T record);
void Update(T record);
}
Run Code Online (Sandbox Code Playgroud)
这是我的实施;
public class ShippingServicesRepository<T> : IBaseRepository<T>
{
// /--- GetPagedList is what is throwing the error
// |
public PagedList<T> GetPagedList<U> (U resourceParams) where U : ShippingServicesResourceParameters
{
try
{
var collectionBeforePaging =
_manifestContext.ShippingServices
.ApplySort(resourceParams.OrderBy, _propertyMappingService.GetPropertyMapping<ShippingServicesDto, ShippingServices>());
if (!string.IsNullOrEmpty(resourceParams.SearchQuery))
{
var searchQueryForWhereClause = resourceParams.SearchQuery.Trim().ToLowerInvariant();
collectionBeforePaging = …Run Code Online (Sandbox Code Playgroud) c# ×7
async-await ×2
unit-testing ×2
.net-core ×1
asp.net ×1
generics ×1
interface ×1
java ×1
moq ×1
twilio ×1
twilio-api ×1