小编Dev*_*per的帖子

使用C#进行单元测试RabbitMQ推送 - .Net Core

我创建了一个.net核心API,它在RabbitMQ队列中推送一条消息.我曾经习惯IOptions.json文件中读取配置数据并将其添加为依赖项.

以下是我的控制器的代码:

[Route("api/[controller]")]
public class RestController : Controller
{
    private RabbitMQConnectionDetail _connectionDetail;

    public RestController(IOptions<RabbitMQConnectionDetail> connectionDetail)
    {
        _connectionDetail = connectionDetail.Value;
    }

    [HttpPost]
    public IActionResult Push([FromBody] OrderItem orderItem)
    {
        try
        {
            using (var rabbitMQConnection = new RabbitMQConnection(_connectionDetail.HostName,
                _connectionDetail.UserName, _connectionDetail.Password))
            {
                using (var connection = rabbitMQConnection.CreateConnection())
                {
                    var model = connection.CreateModel();
                    var helper = new RabbitMQHelper(model, "Topic_Exchange");
                    helper.PushMessageIntoQueue(orderItem.Serialize(), "Order_Queue");
                }
            }
        }
        catch (Exception)
        {
            return StatusCode((int)HttpStatusCode.BadRequest);
        }
        return Ok();
    }
 }
Run Code Online (Sandbox Code Playgroud)

连接详细信息类具有以下属性

public class RabbitMQConnectionDetail
{
    public string …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing rabbitmq .net-core asp.net-core

5
推荐指数
1
解决办法
3167
查看次数

使用 powershell 使用自定义参数运行 exe

我需要运行(安装)一个带有一些自定义参数(参数)的exe

install.exe --no-prompt -u username -p password
Run Code Online (Sandbox Code Playgroud)

上述命令由第 3 方团队提供,用于允许静默安装代理

由于我尝试通过 powershell 安装它,所以我想知道如何传递自定义参数。

注意:此 exe 是第 3 方组件。我可以运行命令来安装带有凭据对象的 exe。但在这种情况下同样不起作用。

powershell

4
推荐指数
1
解决办法
2万
查看次数

Wrapper around Polly Framework so that implementation can stay at a single place

I have gone through the documentation and examples of Polly Framework, and it's really awesome and simple to use !!

In my case, I want to classify all the exceptions into 3 types: temporary, permanent and log. Now, I want to have a single piece of code which will be responsible to handle errors which are temporary in nature by doing wait and retry using Polly Framework.

  WaitAndRetryAsync(new[]{
                    TimeSpan.FromSeconds(1),
                    TimeSpan.FromSeconds(2),
                    TimeSpan.FromSeconds(5)
                  })
Run Code Online (Sandbox Code Playgroud)

Same way, if something is permanent in nature …

c# oop polly

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

标签 统计

c# ×2

.net-core ×1

asp.net-core ×1

oop ×1

polly ×1

powershell ×1

rabbitmq ×1

unit-testing ×1