Skip to content

Commit 86283cf

Browse files
author
John Simons
committedAug 22, 2014
Merge branch 'hotfix-4.5.3'
2 parents 0b6aff8 + dccf363 commit 86283cf

File tree

8 files changed

+161
-10
lines changed

8 files changed

+161
-10
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
namespace NServiceBus.AcceptanceTests.BasicMessaging
2+
{
3+
using System;
4+
using EndpointTemplates;
5+
using AcceptanceTesting;
6+
using NUnit.Framework;
7+
using ScenarioDescriptors;
8+
9+
public class When_using_a_greedy_convention : NServiceBusAcceptanceTest
10+
{
11+
[Test]
12+
public void Should_receive_the_message()
13+
{
14+
Scenario.Define(() => new Context { Id = Guid.NewGuid() })
15+
.WithEndpoint<EndPoint>(b => b.Given((bus, context) => bus.SendLocal(new MyMessage
16+
{Id = context.Id})))
17+
.Done(c => c.WasCalled)
18+
.Repeat(r =>r
19+
.For(Transports.Msmq)
20+
)
21+
.Should(c => Assert.True(c.WasCalled, "The message handler should be called"))
22+
.Run();
23+
}
24+
25+
public class Context : ScenarioContext
26+
{
27+
public bool WasCalled { get; set; }
28+
29+
public Guid Id { get; set; }
30+
}
31+
32+
public class EndPoint : EndpointConfigurationBuilder
33+
{
34+
public EndPoint()
35+
{
36+
EndpointSetup<DefaultServer>(c => c.DefiningMessagesAs(MessageConvention));
37+
}
38+
39+
static bool MessageConvention(Type t)
40+
{
41+
return t.Namespace != null &&
42+
(t.Namespace.EndsWith(".Messages") || (t == typeof(MyMessage)));
43+
}
44+
}
45+
46+
[Serializable]
47+
public class MyMessage
48+
{
49+
public Guid Id { get; set; }
50+
}
51+
52+
public class MyMessageHandler : IHandleMessages<MyMessage>
53+
{
54+
public Context Context { get; set; }
55+
public void Handle(MyMessage message)
56+
{
57+
if (Context.Id != message.Id)
58+
return;
59+
60+
Context.WasCalled = true;
61+
}
62+
}
63+
}
64+
}

‎src/NServiceBus.AcceptanceTests/NServiceBus.AcceptanceTests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<Reference Include="System.Xml.Linq" />
101101
</ItemGroup>
102102
<ItemGroup>
103+
<Compile Include="BasicMessaging\When_using_a_greedy_convention.cs" />
103104
<Compile Include="BasicMessaging\When_using_a_message_with_TimeToBeReceived_has_not_expired.cs" />
104105
<Compile Include="BasicMessaging\When_using_a_message_with_TimeToBeReceived_has_expired.cs" />
105106
<Compile Include="BasicMessaging\When_Deferring_a_message.cs" />

‎src/NServiceBus.Core.Tests/MessageConventionExtensionsTests.cs

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
namespace NServiceBus.Core.Tests.Encryption
1+
namespace NServiceBus.Core.Tests
22
{
33
using System;
4+
using System.Reflection;
5+
using System.Reflection.Emit;
6+
using Unicast.Messages;
47
using NUnit.Framework;
58

69
[TestFixture]
@@ -12,6 +15,7 @@ public void Should_use_TimeToBeReceived_from_bottom_of_tree()
1215
var timeToBeReceivedAction = MessageConventionExtensions.TimeToBeReceivedAction(typeof(InheritedClassWithAttribute));
1316
Assert.AreEqual(TimeSpan.FromSeconds(2), timeToBeReceivedAction);
1417
}
18+
1519
[Test]
1620
public void Should_use_inherited_TimeToBeReceived()
1721
{
@@ -32,6 +36,38 @@ class InheritedClassWithNoAttribute : BaseClass
3236
{
3337

3438
}
39+
40+
41+
[Test]
42+
public void Should_return_false_for_SN_and_non_particular_assembly()
43+
{
44+
Assert.IsFalse(MessageConventionExtensions.IsFromParticularAssembly(typeof(string)));
45+
}
46+
47+
[Test]
48+
public void Should_return_true_for_particular_assembly()
49+
{
50+
Assert.IsTrue(MessageConventionExtensions.IsFromParticularAssembly(typeof(ExecuteLogicalMessagesBehavior)));
51+
}
52+
53+
[Test]
54+
public void Should_return_false_for_non_SN_and_non_particular_assembly()
55+
{
56+
var type = GetNonSnFakeType();
57+
Assert.IsFalse(MessageConventionExtensions.IsFromParticularAssembly(type));
58+
}
59+
60+
static Type GetNonSnFakeType()
61+
{
62+
var assemblyName = new AssemblyName
63+
{
64+
Name = "myAssembly"
65+
};
66+
var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.ReflectionOnly);
67+
var newModule = assemblyBuilder.DefineDynamicModule("myModule");
68+
var myType = newModule.DefineType("myType", TypeAttributes.Public);
69+
return myType.CreateType();
70+
}
3571
}
3672

3773
}

‎src/NServiceBus.Core.Tests/NServiceBus.Core.Tests.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<SignAssembly>true</SignAssembly>
15-
<AssemblyOriginatorKeyFile>..\NServiceBus.snk</AssemblyOriginatorKeyFile>
15+
<AssemblyOriginatorKeyFile>Test.snk</AssemblyOriginatorKeyFile>
1616
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
1717
</PropertyGroup>
1818
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -307,6 +307,7 @@
307307
<SubType>Designer</SubType>
308308
</None>
309309
<None Include="ripple.dependencies.config" />
310+
<None Include="Test.snk" />
310311
</ItemGroup>
311312
<ItemGroup>
312313
<ProjectReference Include="..\NServiceBus.Core\NServiceBus.Core.csproj">

‎src/NServiceBus.Core.Tests/Test.snk

596 Bytes
Binary file not shown.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
using System.Runtime.CompilerServices;
22

33
[assembly: InternalsVisibleTo("NServiceBus.Hosting.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100dde965e6172e019ac82c2639ffe494dd2e7dd16347c34762a05732b492e110f2e4e2e1b5ef2d85c848ccfb671ee20a47c8d1376276708dc30a90ff1121b647ba3b7259a6bc383b2034938ef0e275b58b920375ac605076178123693c6c4f1331661a62eba28c249386855637780e3ff5f23a6d854700eaa6803ef48907513b92")]
4-
[assembly: InternalsVisibleTo("NServiceBus.Core.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100dde965e6172e019ac82c2639ffe494dd2e7dd16347c34762a05732b492e110f2e4e2e1b5ef2d85c848ccfb671ee20a47c8d1376276708dc30a90ff1121b647ba3b7259a6bc383b2034938ef0e275b58b920375ac605076178123693c6c4f1331661a62eba28c249386855637780e3ff5f23a6d854700eaa6803ef48907513b92")]
4+
[assembly: InternalsVisibleTo("NServiceBus.Core.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001007f16e21368ff041183fab592d9e8ed37e7be355e93323147a1d29983d6e591b04282e4da0c9e18bd901e112c0033925eb7d7872c2f1706655891c5c9d57297994f707d16ee9a8f40d978f064ee1ffc73c0db3f4712691b23bf596f75130f4ec978cf78757ec034625a5f27e6bb50c618931ea49f6f628fd74271c32959efb1c5")]

‎src/NServiceBus/MessageConventionExtensions.cs

+53-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@
1111
/// </summary>
1212
public static class MessageConventionExtensions
1313
{
14+
static byte[] nsbPublicKeyToken;
15+
16+
static MessageConventionExtensions()
17+
{
18+
var currentAssemblyName = typeof(MessageConventionExtensions).Assembly.GetName();
19+
nsbPublicKeyToken = currentAssemblyName.GetPublicKeyToken();
20+
}
21+
22+
internal static bool IsFromParticularAssembly(Type type)
23+
{
24+
return type.Assembly.GetName()
25+
.GetPublicKeyToken()
26+
.SequenceEqual(nsbPublicKeyToken);
27+
}
28+
1429
/// <summary>
1530
/// Returns true if the given object is a message.
1631
/// </summary>
@@ -27,10 +42,20 @@ public static bool IsMessageType(Type t)
2742
try
2843
{
2944
return MessagesConventionCache.ApplyConvention(t,
30-
type => IsMessageTypeAction(type) ||
31-
IsCommandTypeAction(type) ||
32-
IsEventTypeAction(type) ||
33-
IsInSystemConventionList(type));
45+
type =>
46+
{
47+
if (IsInSystemConventionList(type))
48+
{
49+
return true;
50+
}
51+
if (IsFromParticularAssembly(type))
52+
{
53+
return false;
54+
}
55+
return IsMessageTypeAction(type) ||
56+
IsCommandTypeAction(type) ||
57+
IsEventTypeAction(type);
58+
});
3459
}
3560
catch (Exception ex)
3661
{
@@ -73,7 +98,14 @@ public static bool IsCommandType(Type t)
7398
{
7499
try
75100
{
76-
return CommandsConventionCache.ApplyConvention(t, type => IsCommandTypeAction(type));
101+
return CommandsConventionCache.ApplyConvention(t, type =>
102+
{
103+
if (IsFromParticularAssembly(type))
104+
{
105+
return false;
106+
}
107+
return IsCommandTypeAction(type);
108+
});
77109
}
78110
catch (Exception ex)
79111
{
@@ -96,7 +128,14 @@ public static bool IsExpressMessageType(Type t)
96128
{
97129
try
98130
{
99-
return ExpressConventionCache.ApplyConvention(t, type => IsExpressMessageAction(type));
131+
return ExpressConventionCache.ApplyConvention(t, type =>
132+
{
133+
if (IsFromParticularAssembly(type))
134+
{
135+
return false;
136+
}
137+
return IsExpressMessageAction(type);
138+
});
100139
}
101140
catch (Exception ex)
102141
{
@@ -151,7 +190,14 @@ public static bool IsEventType(Type t)
151190
{
152191
try
153192
{
154-
return EventsConventionCache.ApplyConvention(t, type => IsEventTypeAction(type));
193+
return EventsConventionCache.ApplyConvention(t, type =>
194+
{
195+
if (IsFromParticularAssembly(type))
196+
{
197+
return false;
198+
}
199+
return IsEventTypeAction(type);
200+
});
155201
}
156202
catch (Exception ex)
157203
{

‎src/NServiceBus/NServiceBus.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
<Reference Include="System.Core" />
5757
</ItemGroup>
5858
<ItemGroup>
59+
<Compile Include="..\NServiceBus.Core\InternalsVisibleTo.cs">
60+
<Link>InternalsVisibleTo.cs</Link>
61+
</Compile>
5962
<Compile Include="Address.cs" />
6063
<Compile Include="AddressMode.cs" />
6164
<Compile Include="CompletionResult.cs" />

0 commit comments

Comments
 (0)
Please sign in to comment.