소스 검색

add unit tests for ConsumerServiceSelector

master
Savorboard 6 년 전
부모
커밋
19ed887bfa
1개의 변경된 파일76개의 추가작업 그리고 1개의 파일을 삭제
  1. +76
    -1
      test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs

+ 76
- 1
test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs 파일 보기

@@ -28,7 +28,7 @@ namespace DotNetCore.CAP.Test
var selector = _provider.GetRequiredService<IConsumerServiceSelector>();
var candidates = selector.SelectCandidates();

Assert.Equal(2, candidates.Count);
Assert.Equal(6, candidates.Count);
}

[Fact]
@@ -42,6 +42,66 @@ namespace DotNetCore.CAP.Test
Assert.NotNull(bestCandidates.MethodInfo);
Assert.Equal(typeof(Task), bestCandidates.MethodInfo.ReturnType);
}


[Theory]
[InlineData("Candidates.Asterisk")]
[InlineData("candidates.Asterisk")]
[InlineData("AAA.BBB.Asterisk")]
[InlineData("aaa.bbb.Asterisk")]
public void CanFindAsteriskTopic(string topic)
{
var selector = _provider.GetRequiredService<IConsumerServiceSelector>();
var candidates = selector.SelectCandidates();

var bestCandidates = selector.SelectBestCandidate(topic, candidates);
Assert.NotNull(bestCandidates);
}

[Theory]
[InlineData("Candidates.Asterisk.AAA")]
[InlineData("AAA.BBB.CCC.Asterisk")]
[InlineData("aaa.BBB.ccc.Asterisk")]
[InlineData("Asterisk.aaa.bbb")]
public void CanNotFindAsteriskTopic(string topic)
{
var selector = _provider.GetRequiredService<IConsumerServiceSelector>();
var candidates = selector.SelectCandidates();

var bestCandidates = selector.SelectBestCandidate(topic, candidates);
Assert.Null(bestCandidates);
}

[Theory]
[InlineData("Candidates.Pound.AAA")]
[InlineData("Candidates.Pound.AAA.BBB")]
[InlineData("AAA.Pound")]
[InlineData("aaa.Pound")]
[InlineData("aaa.bbb.Pound")]
[InlineData("aaa.BBB.Pound")]
public void CanFindPoundTopic(string topic)
{
var selector = _provider.GetRequiredService<IConsumerServiceSelector>();
var candidates = selector.SelectCandidates();

var bestCandidates = selector.SelectBestCandidate(topic, candidates);
Assert.NotNull(bestCandidates);
}

[Theory]
[InlineData("Pound")]
[InlineData("aaa.Pound.AAA.BBB")]
[InlineData("Pound.AAA")]
[InlineData("Pound.aaa")]
[InlineData("AAA.Pound.aaa")]
public void CanNotFindPoundTopic(string topic)
{
var selector = _provider.GetRequiredService<IConsumerServiceSelector>();
var candidates = selector.SelectCandidates();

var bestCandidates = selector.SelectBestCandidate(topic, candidates);
Assert.Null(bestCandidates);
}
}

public class CandidatesTopic : TopicAttribute
@@ -73,6 +133,21 @@ namespace DotNetCore.CAP.Test
{
Console.WriteLine("GetFoo2() method has bee excuted.");
}

[CandidatesTopic("*.*.Asterisk")]
[CandidatesTopic("*.Asterisk")]
public void GetFooAsterisk()
{
Console.WriteLine("GetFoo2Asterisk() method has bee excuted.");
}

[CandidatesTopic("Candidates.Pound.#")]
[CandidatesTopic("#.Pound")]
public void GetFooPound()
{
Console.WriteLine("GetFoo2Pound() method has bee excuted.");
}

}

public class CandidatesBarTest : IBarTest


불러오는 중...
취소
저장