-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
429 changed files
with
6,280 additions
and
24,022 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
assembly-versioning-scheme: Major | ||
next-version: 3.0 | ||
next-version: 3.1 | ||
branches: | ||
develop: | ||
tag: alpha | ||
releases?[/-]: | ||
tag: rc | ||
release: | ||
tag: rc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Configuration; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
public abstract class AppConfig : IDisposable | ||
{ | ||
public static AppConfig Change(string path) | ||
{ | ||
return new ChangeAppConfig(path); | ||
} | ||
|
||
public abstract void Dispose(); | ||
|
||
class ChangeAppConfig : AppConfig | ||
{ | ||
string oldConfig = AppDomain.CurrentDomain.GetData("APP_CONFIG_FILE").ToString(); | ||
|
||
bool disposedValue; | ||
|
||
public ChangeAppConfig(string path) | ||
{ | ||
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", path); | ||
ResetConfigMechanism(); | ||
} | ||
|
||
public override void Dispose() | ||
{ | ||
if (!disposedValue) | ||
{ | ||
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", oldConfig); | ||
ResetConfigMechanism(); | ||
|
||
disposedValue = true; | ||
} | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
static void ResetConfigMechanism() | ||
{ | ||
typeof(ConfigurationManager) | ||
.GetField("s_initState", BindingFlags.NonPublic | | ||
BindingFlags.Static) | ||
.SetValue(null, 0); | ||
|
||
typeof(ConfigurationManager) | ||
.GetField("s_configSystem", BindingFlags.NonPublic | | ||
BindingFlags.Static) | ||
.SetValue(null, null); | ||
|
||
typeof(ConfigurationManager) | ||
.Assembly.GetTypes() | ||
.Where(x => x.FullName == | ||
"System.Configuration.ClientConfigPaths") | ||
.First() | ||
.GetField("s_current", BindingFlags.NonPublic | | ||
BindingFlags.Static) | ||
.SetValue(null, null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
class AppConfigGenerator | ||
{ | ||
public static FileInfo Generate(string connectionString, List<ConnectionStringOverrides> connectionStrings) | ||
{ | ||
var nodes = CreateConnectionStringNode(null, connectionString); | ||
|
||
nodes = connectionStrings.Aggregate(nodes, (current, m) => current + CreateConnectionStringNode(m.Address, m.ConnectionString)); | ||
|
||
var content = $@"<?xml version='1.0' encoding='utf-8'?> | ||
<configuration> | ||
<connectionStrings> | ||
<clear /> | ||
{nodes} | ||
</connectionStrings> | ||
</configuration>"; | ||
|
||
File.WriteAllText("custom-app.config", content); | ||
|
||
return new FileInfo("custom-app.config"); | ||
} | ||
|
||
|
||
static string CreateConnectionStringNode(string name, string connectionString) | ||
{ | ||
var connectionStringAttribute = connectionString; | ||
var nameAttribute = name != null ? $"NServiceBus/Transport/{name}" : "NServiceBus/Transport"; | ||
|
||
return $@"<add name=""{nameAttribute}"" connectionString=""{connectionStringAttribute}"" />"; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/CompatibilityTests/Facade_1.2/ConnectionStringOverrides.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class ConnectionStringOverrides | ||
{ | ||
public string Address { get; set; } | ||
public string ConnectionString { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using NServiceBus.Config; | ||
using NServiceBus.Config.ConfigurationSource; | ||
|
||
class CustomConfiguration : IConfigurationSource | ||
{ | ||
List<MessageEndpointMapping> messageMappings = new List<MessageEndpointMapping>(); | ||
|
||
public void AddMapping(MessageEndpointMapping mapping) | ||
{ | ||
messageMappings.Add(mapping); | ||
} | ||
|
||
public T GetConfiguration<T>() where T : class, new() | ||
{ | ||
if (typeof(T) == typeof(MessageForwardingInCaseOfFaultConfig)) | ||
{ | ||
return new MessageForwardingInCaseOfFaultConfig | ||
{ | ||
ErrorQueue = "error" | ||
} as T; | ||
} | ||
|
||
if (typeof(T) == typeof(UnicastBusConfig)) | ||
{ | ||
var endpointMappingsCollection = new MessageEndpointMappingCollection(); | ||
|
||
foreach (var em in messageMappings) | ||
{ | ||
endpointMappingsCollection.Add(em); | ||
} | ||
|
||
return new UnicastBusConfig | ||
{ | ||
MessageEndpointMappings = endpointMappingsCollection, | ||
} as T; | ||
} | ||
|
||
if (typeof(T) == typeof(TransportConfig)) | ||
{ | ||
return new TransportConfig | ||
{ | ||
MaxRetries = 0, | ||
} as T; | ||
} | ||
|
||
if (typeof(T) == typeof(AuditConfig)) | ||
{ | ||
return new AuditConfig | ||
{ | ||
QueueName = "audit" | ||
} | ||
as T; | ||
} | ||
|
||
if (typeof(T) == typeof(SecondLevelRetriesConfig)) | ||
{ | ||
return new SecondLevelRetriesConfig | ||
{ | ||
NumberOfRetries = 0 | ||
} as T; | ||
} | ||
|
||
// leaving the rest of the configuration as is: | ||
return ConfigurationManager.GetSection(typeof(T).Name) as T; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using CompatibilityTests.Common; | ||
using CompatibilityTests.Common.Messages; | ||
using NServiceBus; | ||
using NServiceBus.Config; | ||
using NServiceBus.Features; | ||
using NServiceBus.Support; | ||
using NServiceBus.Unicast.Subscriptions.MessageDrivenSubscriptions; | ||
|
||
class EndpointFacade : MarshalByRefObject, IEndpointFacade, IEndpointConfigurationV1 | ||
{ | ||
IBus bus; | ||
IStartableBus startableBus; | ||
MessageStore messageStore; | ||
CallbackResultStore callbackResultStore; | ||
SubscriptionStore subscriptionStore; | ||
Configure configure; | ||
List<ConnectionStringOverrides> connectionStringsOverrides = new List<ConnectionStringOverrides>(); | ||
CustomConfiguration customConfiguration; | ||
string connectionString; | ||
|
||
public void Dispose() | ||
{ | ||
startableBus.Dispose(); | ||
} | ||
|
||
public IEndpointConfiguration Bootstrap(EndpointDefinition endpointDefinition) | ||
{ | ||
if (endpointDefinition.MachineName != null) | ||
{ | ||
RuntimeEnvironment.MachineNameAction = () => endpointDefinition.MachineName; | ||
} | ||
|
||
configure = Configure.With(); | ||
configure.DefaultBuilder(); | ||
|
||
configure.DefineEndpointName(endpointDefinition.Name); | ||
Address.InitializeLocalAddress(endpointDefinition.Name); | ||
|
||
configure.DefiningMessagesAs(t => t.Namespace != null && t.Namespace.EndsWith(".Messages") && t != typeof(TestEvent)); | ||
configure.DefiningEventsAs(t => t == typeof(TestEvent)); | ||
|
||
configure.UseInMemoryTimeoutPersister(); | ||
configure.InMemorySubscriptionStorage(); | ||
|
||
customConfiguration = new CustomConfiguration(); | ||
configure.CustomConfigurationSource(customConfiguration); | ||
|
||
Feature.Enable<MessageDrivenSubscriptions>(); | ||
|
||
configure.Configurer.ConfigureComponent<MessageStore>(DependencyLifecycle.SingleInstance); | ||
|
||
return this; | ||
} | ||
|
||
public void UseConnectionString(string connectionString) | ||
{ | ||
this.connectionString = connectionString; | ||
} | ||
|
||
public void MapMessageToEndpoint(Type messageType, string destination) | ||
{ | ||
customConfiguration.AddMapping(new MessageEndpointMapping | ||
{Endpoint = destination, Messages = messageType.AssemblyQualifiedName}); | ||
} | ||
|
||
public void Start() | ||
{ | ||
var configFile = AppConfigGenerator.Generate(connectionString, connectionStringsOverrides); | ||
|
||
//HINT: we need to generate custom app.config because v1 sqltransports does a direct read from ConfigurationManager | ||
using (AppConfig.Change(configFile.FullName)) | ||
{ | ||
configure.UseTransport<SqlServer>(); | ||
|
||
startableBus = configure.UnicastBus().CreateBus(); | ||
bus = startableBus.Start(() => configure.ForInstallationOn<NServiceBus.Installation.Environments.Windows>().Install()); | ||
|
||
messageStore = (MessageStore)configure.Builder.Build(typeof(MessageStore)); | ||
subscriptionStore = new SubscriptionStore(); | ||
callbackResultStore = new CallbackResultStore(); | ||
|
||
configure.Builder.Build<MessageDrivenSubscriptionManager>().ClientSubscribed += (sender, args) => { subscriptionStore.Increment(); }; | ||
} | ||
} | ||
|
||
public void ConfigureNamedConnectionStringForAddress(string endpoint, string connectionString) | ||
{ | ||
connectionStringsOverrides.Add(new ConnectionStringOverrides | ||
{ | ||
Address = endpoint, | ||
ConnectionString = connectionString | ||
}); | ||
} | ||
|
||
public void SendCommand(Guid messageId) | ||
{ | ||
bus.Send(new TestCommand { Id = messageId }); | ||
} | ||
|
||
public void SendRequest(Guid requestId) | ||
{ | ||
bus.Send(new TestRequest { RequestId = requestId }); | ||
} | ||
|
||
public void PublishEvent(Guid eventId) | ||
{ | ||
bus.Publish<TestEvent>(e => e.EventId = eventId); | ||
} | ||
|
||
public void SendAndCallbackForInt(int value) | ||
{ | ||
Task.Run(async () => | ||
{ | ||
var callback = bus.Send(new TestIntCallback { Response = value }); | ||
|
||
var res = await callback.Register(); | ||
|
||
callbackResultStore.Add(res); | ||
}); | ||
} | ||
|
||
public void SendAndCallbackForEnum(CallbackEnum value) | ||
{ | ||
Task.Run(async () => | ||
{ | ||
var res = await bus.Send(new TestEnumCallback { CallbackEnum = value }).Register<CallbackEnum>(); | ||
|
||
callbackResultStore.Add(res); | ||
}); | ||
} | ||
|
||
public Guid[] ReceivedMessageIds => messageStore.GetAll(); | ||
|
||
public Guid[] ReceivedResponseIds => messageStore.Get<TestResponse>(); | ||
|
||
public Guid[] ReceivedEventIds => messageStore.Get<TestEvent>(); | ||
|
||
public int[] ReceivedIntCallbacks => callbackResultStore.Get<int>(); | ||
|
||
public CallbackEnum[] ReceivedEnumCallbacks => callbackResultStore.Get<CallbackEnum>(); | ||
|
||
public int NumberOfSubscriptions => subscriptionStore.NumberOfSubscriptions; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net452</TargetFramework> | ||
<AssemblyName>Facade</AssemblyName> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="log4net" Version="2.0.0" /> | ||
<PackageReference Include="NServiceBus" Version="4.4.8" /> | ||
<PackageReference Include="NServiceBus.Interfaces" Version="4.4.8" /> | ||
<PackageReference Include="NServiceBus.SqlServer" Version="1.2.5" /> | ||
<ProjectReference Include="..\..\NServiceBus.SqlServer.CompatibilityTests.Common\NServiceBus.SqlServer.CompatibilityTests.Common.csproj" /> | ||
<Reference Include="System.Configuration" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using CompatibilityTests.Common; | ||
using CompatibilityTests.Common.Messages; | ||
using NServiceBus; | ||
|
||
public class Handler : IHandleMessages<TestCommand>, IHandleMessages<TestRequest>, IHandleMessages<TestResponse>, IHandleMessages<TestEvent>, IHandleMessages<TestIntCallback>, IHandleMessages<TestEnumCallback> | ||
{ | ||
public IBus Bus { get; set; } | ||
|
||
public MessageStore Store { get; set; } | ||
|
||
public void Handle(TestCommand command) | ||
{ | ||
Store.Add<TestCommand>(command.Id); | ||
} | ||
|
||
public void Handle(TestRequest message) | ||
{ | ||
Bus.Reply(new TestResponse { ResponseId = message.RequestId }); | ||
} | ||
|
||
public void Handle(TestResponse message) | ||
{ | ||
Store.Add<TestResponse>(message.ResponseId); | ||
} | ||
|
||
public void Handle(TestEvent message) | ||
{ | ||
Store.Add<TestEvent>(message.EventId); | ||
} | ||
|
||
public void Handle(TestIntCallback message) | ||
{ | ||
Bus.Return(message.Response); | ||
} | ||
|
||
public void Handle(TestEnumCallback message) | ||
{ | ||
Bus.Return(message.CallbackEnum); | ||
} | ||
} |
Oops, something went wrong.