Skip to content

Commit

Permalink
Merge branch 'hotfix-4.3.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
John Simons committed Aug 22, 2014
2 parents 9963088 + 3b6eac8 commit 3b69bff
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
namespace NServiceBus.AcceptanceTests.BasicMessaging
{
using System;
using EndpointTemplates;
using AcceptanceTesting;
using NUnit.Framework;
using ScenarioDescriptors;

public class When_using_a_greedy_convention : NServiceBusAcceptanceTest
{
[Test]
public void Should_receive_the_message()
{
Scenario.Define(() => new Context { Id = Guid.NewGuid() })
.WithEndpoint<EndPoint>(b => b.Given((bus, context) => bus.SendLocal(new MyMessage
{Id = context.Id})))
.Done(c => c.WasCalled)
.Repeat(r =>r
.For(Transports.Msmq)
)
.Should(c => Assert.True(c.WasCalled, "The message handler should be called"))
.Run();
}

public class Context : ScenarioContext
{
public bool WasCalled { get; set; }

public Guid Id { get; set; }
}

public class EndPoint : EndpointConfigurationBuilder
{
public EndPoint()
{
EndpointSetup<DefaultServer>(c => c.DefiningMessagesAs(MessageConvention));
}

static bool MessageConvention(Type t)
{
return t.Namespace != null &&
(t.Namespace.EndsWith(".Messages") || (t == typeof(MyMessage)));
}
}

[Serializable]
public class MyMessage
{
public Guid Id { get; set; }
}

public class MyMessageHandler : IHandleMessages<MyMessage>
{
public Context Context { get; set; }
public void Handle(MyMessage message)
{
if (Context.Id != message.Id)
return;

Context.WasCalled = true;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="BasicMessaging\When_using_a_greedy_convention.cs" />
<Compile Include="Audit\When_using_auditing_as_a_feature.cs" />
<Compile Include="Audit\When_a_message_is_audited.cs" />
<Compile Include="BasicMessaging\When_sending_a_message_with_no_correlation_id.cs" />
Expand Down
38 changes: 37 additions & 1 deletion src/NServiceBus.Core.Tests/MessageConventionExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
namespace NServiceBus.Core.Tests.Encryption
namespace NServiceBus.Core.Tests
{
using System;
using System.Reflection;
using System.Reflection.Emit;
using Unicast.Messages;
using NUnit.Framework;

[TestFixture]
Expand All @@ -12,6 +15,7 @@ public void Should_use_TimeToBeReceived_from_bottom_of_tree()
var timeToBeReceivedAction = MessageConventionExtensions.TimeToBeReceivedAction(typeof(InheritedClassWithAttribute));
Assert.AreEqual(TimeSpan.FromSeconds(2), timeToBeReceivedAction);
}

[Test]
public void Should_use_inherited_TimeToBeReceived()
{
Expand All @@ -32,6 +36,38 @@ class InheritedClassWithNoAttribute : BaseClass
{

}


[Test]
public void Should_return_false_for_SN_and_non_particular_assembly()
{
Assert.IsFalse(MessageConventionExtensions.IsFromParticularAssembly(typeof(string)));
}

[Test]
public void Should_return_true_for_particular_assembly()
{
Assert.IsTrue(MessageConventionExtensions.IsFromParticularAssembly(typeof(ExecuteLogicalMessagesBehavior)));
}

[Test]
public void Should_return_false_for_non_SN_and_non_particular_assembly()
{
var type = GetNonSnFakeType();
Assert.IsFalse(MessageConventionExtensions.IsFromParticularAssembly(type));
}

static Type GetNonSnFakeType()
{
var assemblyName = new AssemblyName
{
Name = "myAssembly"
};
var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.ReflectionOnly);
var newModule = assemblyBuilder.DefineDynamicModule("myModule");
var myType = newModule.DefineType("myType", TypeAttributes.Public);
return myType.CreateType();
}
}

}
3 changes: 3 additions & 0 deletions src/NServiceBus.Core.Tests/NServiceBus.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<FileAlignment>512</FileAlignment>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\NServiceBus.snk</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile>Test.snk</AssemblyOriginatorKeyFile>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -310,6 +312,7 @@
<SubType>Designer</SubType>
</None>
<None Include="ripple.dependencies.config" />
<None Include="Test.snk" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NServiceBus.Core\NServiceBus.Core.csproj">
Expand Down
Binary file added src/NServiceBus.Core.Tests/Test.snk
Binary file not shown.
2 changes: 1 addition & 1 deletion src/NServiceBus.Core/InternalsVisibleTo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("NServiceBus.Hosting.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100dde965e6172e019ac82c2639ffe494dd2e7dd16347c34762a05732b492e110f2e4e2e1b5ef2d85c848ccfb671ee20a47c8d1376276708dc30a90ff1121b647ba3b7259a6bc383b2034938ef0e275b58b920375ac605076178123693c6c4f1331661a62eba28c249386855637780e3ff5f23a6d854700eaa6803ef48907513b92")]
[assembly: InternalsVisibleTo("NServiceBus.Core.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100dde965e6172e019ac82c2639ffe494dd2e7dd16347c34762a05732b492e110f2e4e2e1b5ef2d85c848ccfb671ee20a47c8d1376276708dc30a90ff1121b647ba3b7259a6bc383b2034938ef0e275b58b920375ac605076178123693c6c4f1331661a62eba28c249386855637780e3ff5f23a6d854700eaa6803ef48907513b92")]
[assembly: InternalsVisibleTo("NServiceBus.Core.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001007f16e21368ff041183fab592d9e8ed37e7be355e93323147a1d29983d6e591b04282e4da0c9e18bd901e112c0033925eb7d7872c2f1706655891c5c9d57297994f707d16ee9a8f40d978f064ee1ffc73c0db3f4712691b23bf596f75130f4ec978cf78757ec034625a5f27e6bb50c618931ea49f6f628fd74271c32959efb1c5")]
60 changes: 53 additions & 7 deletions src/NServiceBus/MessageConventionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@
/// </summary>
public static class MessageConventionExtensions
{
static byte[] nsbPublicKeyToken;

static MessageConventionExtensions()
{
var currentAssemblyName = typeof(MessageConventionExtensions).Assembly.GetName();
nsbPublicKeyToken = currentAssemblyName.GetPublicKeyToken();
}

internal static bool IsFromParticularAssembly(Type type)
{
return type.Assembly.GetName()
.GetPublicKeyToken()
.SequenceEqual(nsbPublicKeyToken);
}

/// <summary>
/// Returns true if the given object is a message.
/// </summary>
Expand All @@ -27,10 +42,20 @@ public static bool IsMessageType(Type t)
try
{
return MessagesConventionCache.ApplyConvention(t,
type => IsMessageTypeAction(type) ||
IsCommandTypeAction(type) ||
IsEventTypeAction(type) ||
IsInSystemConventionList(type));
type =>
{
if (IsInSystemConventionList(type))
{
return true;
}
if (IsFromParticularAssembly(type))
{
return false;
}
return IsMessageTypeAction(type) ||
IsCommandTypeAction(type) ||
IsEventTypeAction(type);
});
}
catch (Exception ex)
{
Expand Down Expand Up @@ -73,7 +98,14 @@ public static bool IsCommandType(Type t)
{
try
{
return CommandsConventionCache.ApplyConvention(t, type => IsCommandTypeAction(type));
return CommandsConventionCache.ApplyConvention(t, type =>
{
if (IsFromParticularAssembly(type))
{
return false;
}
return IsCommandTypeAction(type);
});
}
catch (Exception ex)
{
Expand All @@ -96,7 +128,14 @@ public static bool IsExpressMessageType(Type t)
{
try
{
return ExpressConventionCache.ApplyConvention(t, type => IsExpressMessageAction(type));
return ExpressConventionCache.ApplyConvention(t, type =>
{
if (IsFromParticularAssembly(type))
{
return false;
}
return IsExpressMessageAction(type);
});
}
catch (Exception ex)
{
Expand Down Expand Up @@ -151,7 +190,14 @@ public static bool IsEventType(Type t)
{
try
{
return EventsConventionCache.ApplyConvention(t, type => IsEventTypeAction(type));
return EventsConventionCache.ApplyConvention(t, type =>
{
if (IsFromParticularAssembly(type))
{
return false;
}
return IsEventTypeAction(type);
});
}
catch (Exception ex)
{
Expand Down
3 changes: 3 additions & 0 deletions src/NServiceBus/NServiceBus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\NServiceBus.Core\InternalsVisibleTo.cs">
<Link>InternalsVisibleTo.cs</Link>
</Compile>
<Compile Include="Address.cs" />
<Compile Include="AddressMode.cs" />
<Compile Include="CompletionResult.cs" />
Expand Down

0 comments on commit 3b69bff

Please sign in to comment.