【发布时间】:2016-09-12 02:43:41
【问题描述】:
我需要测试正在使用 MassTransit 的订阅者。
下面是示例代码:
using System;
using MassTransit;
public class AnimalSubscriber : Consumes<Animal>.Context
{
public void Consume(IConsumeContext<Animal> message)
{
//.. my code here..
}
}
现在我不知道如何测试订阅者。如果有人可以让我知道一些细节;这将非常有帮助!
到目前为止,我愚蠢地想创建一个 AnimalSubscriber 的 Object 并调用 Consume 方法。
[TestFixture]
public class Test
{
[Test]
public void SearchAnimals()
{
AnimalSubscriber subscriber = new AnimalSubscriber();
Animal request = new Animal
{
Id : 1,
Name : "Tiger"
};
//Not sure how to mock this IReceiveContext.
IReceiveContext context = new ReceiveContext();
IConsumeContext<Animal> message =new ConsumeContext<Animal>(context, request);
subscriber.Consume(null);
}
}
但我被下面的代码行卡住了:
IConsumeContext<Animal> message =new ConsumeContext<Animal>(context, request); //<- Not sure how to mock this IReceiveContext.
错误:“MassTransit.Context.ReceiveContext”类型没有 构造函数定义
需要一些建议!
【问题讨论】:
标签: c# unit-testing nunit masstransit