Selaa lähdekoodia

add unit test.

master
yangxiaodong 7 vuotta sitten
vanhempi
commit
af4b8e1a10
2 muutettua tiedostoa jossa 107 lisäystä ja 0 poistoa
  1. +48
    -0
      test/DotNetCore.CAP.Test/QueueExecutorFactoryTest.cs
  2. +59
    -0
      test/DotNetCore.CAP.Test/SubscribeFinderTest.cs

+ 48
- 0
test/DotNetCore.CAP.Test/QueueExecutorFactoryTest.cs Näytä tiedosto

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.DependencyInjection;
using Xunit;

namespace DotNetCore.CAP.Test
{
public class QueueExecutorFactoryTest
{
private IServiceProvider _provider;

public QueueExecutorFactoryTest()
{
var services = new ServiceCollection();
services.AddLogging();
services.AddOptions();
services.AddCap(x => { });
_provider = services.BuildServiceProvider();
}

[Fact]
public void CanCreateInstance()
{
var queueExecutorFactory = _provider.GetService<IQueueExecutorFactory>();
Assert.NotNull(queueExecutorFactory);

var publishExecutor = queueExecutorFactory.GetInstance(Models.MessageType.Publish);
Assert.Null(publishExecutor);

var disPatchExector = queueExecutorFactory.GetInstance(Models.MessageType.Subscribe);
Assert.NotNull(disPatchExector);
}

[Fact]
public void CanGetSubscribeExector()
{
var queueExecutorFactory = _provider.GetService<IQueueExecutorFactory>();
Assert.NotNull(queueExecutorFactory);

var publishExecutor = queueExecutorFactory.GetInstance(Models.MessageType.Publish);
Assert.Equal(null, publishExecutor);
}



}
}

+ 59
- 0
test/DotNetCore.CAP.Test/SubscribeFinderTest.cs Näytä tiedosto

@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Text;
using DotNetCore.CAP.Abstractions;
using Microsoft.Extensions.DependencyInjection;
using Xunit;

namespace DotNetCore.CAP.Test
{
public class SubscribeFinderTest
{
private IServiceProvider _provider;

public SubscribeFinderTest()
{
var services = new ServiceCollection();
services.AddScoped<ITestService, TestService>();
services.AddCap(x => { });
_provider = services.BuildServiceProvider();
}

[Fact]
public void CanFindControllers()
{
}

[Fact]
public void CanFindSubscribeService()
{
var testService = _provider.GetService<ICapSubscribe>();
Assert.NotNull(testService);
Assert.IsType<TestService>(testService);
}
}

public class HomeController
{

}

public interface ITestService { }

public class TestService : ITestService, ICapSubscribe
{
[CapSubscribe("test")]
public void Index()
{

}
}

public class CapSubscribeAttribute : TopicAttribute
{
public CapSubscribeAttribute(string name) : base(name)
{
}
}
}

Ladataan…
Peruuta
Tallenna