小编Nko*_*osi的帖子

.NET Core API 中的 Twilio StatusCallBack & Gather POST 方法返回 HTTP 415 - 不支持的媒体类型

以下是我对这两种方法的代码 -

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)

c# twilio twilio-api asp.net-core-webapi

0
推荐指数
1
解决办法
520
查看次数

如何使用moq模拟新实例

我想通过模拟两个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)

c# unit-testing moq

-1
推荐指数
1
解决办法
5905
查看次数

输入铸造问题

在将字符串解析为双倍时,我们面临着一个问题.我们需要将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)

问题截屏

c#

-1
推荐指数
1
解决办法
74
查看次数

如何在异步任务方法之外使用局部变量?

如何在此方法之外分配“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)

c# async-await

-1
推荐指数
1
解决办法
1892
查看次数

Post方法在ASP.NET Core中不起作用

我正在尝试创建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)

c# asp.net asp.net-mvc-routing asp.net-web-api2

-1
推荐指数
1
解决办法
4254
查看次数

对于注释类型测试,未定义预期属性

嗨我正在尝试测试一个有异常的代码,但是当我尝试测试它时,它说预期的属性未定义为注释类型测试

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)

这是错误信息

对于注释类型测试,未定义预期属性

java unit-testing

-1
推荐指数
2
解决办法
4688
查看次数

await运算符只能在异步方法中使用

我有一个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)

c# async-await

-3
推荐指数
1
解决办法
4009
查看次数

c#7当使用泛型用于方法参数时我得到方法的类型参数'U'的约束必须匹配接口的约束

我正在尝试创建一个接口和一个具体的实现,其中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# generics interface .net-core asp.net-core-mvc-2.0

-3
推荐指数
1
解决办法
563
查看次数