2017-02-12 13:42:49 +00:00
|
|
|
|
using System;
|
2021-06-04 09:51:45 +00:00
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Tapeti.Annotations;
|
2017-02-12 13:42:49 +00:00
|
|
|
|
using Tapeti.Default;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
2019-08-13 18:30:04 +00:00
|
|
|
|
namespace Tapeti.Tests.Default
|
2017-02-12 13:42:49 +00:00
|
|
|
|
{
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
|
public class TypeNameRoutingKeyStrategyTests
|
|
|
|
|
{
|
|
|
|
|
private class Example { }
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Singleword()
|
|
|
|
|
{
|
|
|
|
|
AssertRoutingKey("example", typeof(Example));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private class ExampleMessage { }
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SinglewordMessagePostfix()
|
|
|
|
|
{
|
|
|
|
|
AssertRoutingKey("example", typeof(ExampleMessage));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private class ExampleMultiWord { }
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Multiword()
|
|
|
|
|
{
|
|
|
|
|
AssertRoutingKey("example.multi.word", typeof(ExampleMultiWord));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private class ExampleMultiWordMessage { }
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void MultiwordMessagePostfix()
|
|
|
|
|
{
|
|
|
|
|
AssertRoutingKey("example.multi.word", typeof(ExampleMultiWordMessage));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private class ACRTestMessage { }
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Acronym()
|
|
|
|
|
{
|
|
|
|
|
AssertRoutingKey("acr.test", typeof(ACRTestMessage));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private class ACRTestMIXEDCaseMESSAGE { }
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void MixedCasing()
|
|
|
|
|
{
|
|
|
|
|
AssertRoutingKey("acr.test.mixed.case", typeof(ACRTestMIXEDCaseMESSAGE));
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-04 09:51:45 +00:00
|
|
|
|
|
|
|
|
|
[RoutingKey(Prefix = "prefix.")]
|
|
|
|
|
private class PrefixAttributeTestMessage { }
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Prefix()
|
|
|
|
|
{
|
|
|
|
|
AssertRoutingKey("prefix.prefix.attribute.test", typeof(PrefixAttributeTestMessage));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[RoutingKey(Postfix = ".postfix")]
|
|
|
|
|
private class PostfixAttributeTestMessage { }
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Postfix()
|
|
|
|
|
{
|
|
|
|
|
AssertRoutingKey("postfix.attribute.test.postfix", typeof(PostfixAttributeTestMessage));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[RoutingKey(Prefix = "prefix.", Postfix = ".postfix")]
|
|
|
|
|
private class PrefixPostfixAttributeTestMessage { }
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void PrefixPostfix()
|
|
|
|
|
{
|
|
|
|
|
AssertRoutingKey("prefix.prefix.postfix.attribute.test.postfix", typeof(PrefixPostfixAttributeTestMessage));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[RoutingKey(Full = "andnowforsomethingcompletelydifferent", Prefix = "ignore.", Postfix = ".me")]
|
|
|
|
|
private class FullAttributeTestMessage { }
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Full()
|
|
|
|
|
{
|
|
|
|
|
AssertRoutingKey("andnowforsomethingcompletelydifferent", typeof(FullAttributeTestMessage));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-29 19:51:58 +00:00
|
|
|
|
// ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
|
|
|
|
|
private static void AssertRoutingKey(string expected, Type messageType)
|
2017-02-12 13:42:49 +00:00
|
|
|
|
{
|
2021-06-04 09:51:45 +00:00
|
|
|
|
var routingKey = new TypeNameRoutingKeyStrategy().GetRoutingKey(messageType);
|
|
|
|
|
routingKey.Should().Be(expected);
|
2017-02-12 13:42:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// ReSharper restore InconsistentNaming
|
|
|
|
|
}
|