I'm trying to learn how to do unit testing of MassTransit consumers (MassTransit version 3.3.1). I'm trying to use Visual Studio 2015's built-in Test Explorer to run my tests. Usually if you add the NUnit3TestAdapter NuGet package, all NUnit tests show up in the Test Explorer window in Visual Studio. However, they're not showing up in my solution that I've set up. The test class I'm using was lifted directly from the MassTransit source and is as follows:
// Copyright 2007-2015 Chris Patterson, Dru Sellers, Travis Smith, et. al.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at
//
// http://ift.tt/jtTJvY
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
namespace MassTransit.Tests
{
using System.Threading.Tasks;
using NUnit.Framework;
using TestFramework;
using TestFramework.Messages;
using Util;
[TestFixture]
public class Sending_a_message_to_a_consumer :
InMemoryTestFixture
{
[Test]
public async Task Should_be_received()
{
await _requestClient.Request(new PingMessage());
}
IRequestClient<PingMessage, PongMessage> _requestClient;
[OneTimeSetUp]
public void Setup()
{
_requestClient = CreateRequestClient<PingMessage, PongMessage>();
}
protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
{
configurator.Consumer<Consumer>(
x => x.UseConsoleLog(async (context, logContext) => string.Format("{1:u} {2:F0} Consumer: {0}", TypeMetadataCache<Consumer>.ShortName,
logContext.StartTime, logContext.Duration.TotalMilliseconds)));
}
class Consumer :
IConsumer<PingMessage>
{
public async Task Consume(ConsumeContext<PingMessage> context)
{
await context.RespondAsync(new PongMessage(context.Message.CorrelationId));
}
}
}
}
The strange thing is that if I open the MassTransit source solution and add the NUnit3TestAdapter NuGet package, all the tests appear in the window. Is there something special about the assembly "MassTransit.Tests" that enables Test Explorer to see the tests? I've verified that my test assembly's references are the same as MassTransit.Tests, and I've verified that if I add another test class, it does show up in the Test Explorer. The issue seems to be related to the test class inheriting from InMemoryTestFixture - if I don't inherit from that class, Test Explorer shows the tests.
Thanks,
Andy
Aucun commentaire:
Enregistrer un commentaire