Procházet zdrojové kódy

modify unit tests.

master
Savorboard před 7 roky
rodič
revize
3003d94584
1 změnil soubory, kde provedl 28 přidání a 21 odebrání
  1. +28
    -21
      test/DotNetCore.CAP.Test/ConsumerInvokerFactoryTest.cs

+ 28
- 21
test/DotNetCore.CAP.Test/ConsumerInvokerFactoryTest.cs Zobrazit soubor

@@ -4,44 +4,48 @@ using System.Reflection;
using DotNetCore.CAP.Abstractions;
using DotNetCore.CAP.Internal;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Moq;
using Xunit;

namespace DotNetCore.CAP.Test
{
public class ConsumerInvokerFactoryTest
{
private IConsumerInvokerFactory consumerInvokerFactory;
private IServiceProvider _serviceProvider;

private Mock<IContentSerializer> _mockSerialiser;
private Mock<IMessagePacker> _mockMessagePacker;
private Mock<IModelBinderFactory> _mockModelBinderFactory;

public ConsumerInvokerFactoryTest()
{
_mockSerialiser = new Mock<IContentSerializer>();
_mockMessagePacker = new Mock<IMessagePacker>();
_mockModelBinderFactory = new Mock<IModelBinderFactory>();

var services = new ServiceCollection();
services.AddLogging();
services.AddSingleton<IContentSerializer, JsonContentSerializer>();
services.AddSingleton<IMessagePacker, DefaultMessagePacker>();
var provider = services.BuildServiceProvider();
var logFactory = provider.GetRequiredService<ILoggerFactory>();
var mesagePacker = provider.GetRequiredService<IMessagePacker>();
var binder = new ModelBinderFactory();
services.AddSingleton<ConsumerInvokerFactory>();

consumerInvokerFactory = new ConsumerInvokerFactory(logFactory, mesagePacker,binder, provider);
services.AddLogging();
services.AddSingleton(_mockSerialiser.Object);
services.AddSingleton(_mockMessagePacker.Object);
services.AddSingleton(_mockModelBinderFactory.Object);
_serviceProvider = services.BuildServiceProvider();
}

private ConsumerInvokerFactory Create() =>
_serviceProvider.GetService<ConsumerInvokerFactory>();

[Fact]
public void CreateInvokerTest()
{
var methodInfo = typeof(Sample).GetRuntimeMethods()
.Single(x => x.Name == nameof(Sample.ThrowException));

var description = new ConsumerExecutorDescriptor
{
MethodInfo = methodInfo,
ImplTypeInfo = typeof(Sample).GetTypeInfo()
};
var messageContext = new MessageContext();
// Arrange
var fixure = Create();

var invoker = consumerInvokerFactory.CreateInvoker();
// Act
var invoker = fixure.CreateInvoker();

// Assert
Assert.NotNull(invoker);
}

@@ -50,6 +54,9 @@ namespace DotNetCore.CAP.Test
[InlineData(nameof(Sample.AsyncMethod))]
public void InvokeMethodTest(string methodName)
{
// Arrange
var fixure = Create();

var methodInfo = typeof(Sample).GetRuntimeMethods()
.Single(x => x.Name == methodName);

@@ -62,7 +69,7 @@ namespace DotNetCore.CAP.Test

var context = new ConsumerContext(description, messageContext);

var invoker = consumerInvokerFactory.CreateInvoker();
var invoker = fixure.CreateInvoker();

Assert.Throws<Exception>(() =>
{


Načítá se…
Zrušit
Uložit