-
Notifications
You must be signed in to change notification settings - Fork 647
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
9 changed files
with
174 additions
and
103 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
src/NServiceBus.AcceptanceTests/HostInformation/When_feature_overrides_hostid.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,87 @@ | ||
namespace NServiceBus.AcceptanceTests.HostInformation | ||
{ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Reflection; | ||
using NServiceBus.AcceptanceTesting; | ||
using NServiceBus.AcceptanceTests.EndpointTemplates; | ||
using NServiceBus.Features; | ||
using NUnit.Framework; | ||
|
||
public class When_feature_overrides_hostid : NServiceBusAcceptanceTest | ||
{ | ||
|
||
[Test] | ||
public void MD5_should_not_be_used() | ||
{ | ||
var context = new Context(); | ||
|
||
Scenario.Define(context) | ||
.WithEndpoint<MyEndpoint>(e => e.Given(b => b.SendLocal(new MyMessage()))) | ||
.Done(c => c.Done) | ||
.Run(); | ||
|
||
Assert.IsTrue(context.NotSet); | ||
} | ||
|
||
public class MyEndpoint : EndpointConfigurationBuilder | ||
{ | ||
public MyEndpoint() | ||
{ | ||
EndpointSetup<DefaultServer>(c => c.UniquelyIdentifyRunningInstance().UsingCustomIdentifier(Guid.NewGuid())); | ||
} | ||
} | ||
|
||
public class MyFeatureThatOverridesHostInformationDefaults : Feature | ||
{ | ||
bool notSet; | ||
|
||
public MyFeatureThatOverridesHostInformationDefaults() | ||
{ | ||
EnableByDefault(); | ||
DependsOn("UnicastBus"); | ||
Defaults(s => | ||
{ | ||
// remove the override, we need to hack it via reflection! | ||
var fieldInfo = s.GetType().GetField("Overrides", BindingFlags.Instance | BindingFlags.NonPublic); | ||
var dictionary = (ConcurrentDictionary<string, object>)fieldInfo.GetValue(s); | ||
object s2; | ||
dictionary.TryRemove("NServiceBus.HostInformation.HostId", out s2); | ||
// Try to get value, setting should not exist | ||
notSet = !s.HasSetting("NServiceBus.HostInformation.HostId"); | ||
// Set override again so we have something | ||
s.Set("NServiceBus.HostInformation.HostId", Guid.NewGuid()); | ||
}); | ||
} | ||
|
||
protected override void Setup(FeatureConfigurationContext context) | ||
{ | ||
context.Container.ConfigureProperty<Context>(c => c.NotSet, notSet); | ||
} | ||
} | ||
|
||
public class MyMessageHandler : IHandleMessages<MyMessage> | ||
{ | ||
public Context Context { get; set; } | ||
|
||
public void Handle(MyMessage message) | ||
{ | ||
Context.Done = true; | ||
} | ||
} | ||
|
||
public class Context : ScenarioContext | ||
{ | ||
public bool NotSet { get; set; } | ||
public bool Done { get; set; } | ||
} | ||
|
||
[Serializable] | ||
public class MyMessage : ICommand | ||
{ | ||
} | ||
} | ||
} |
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
61 changes: 0 additions & 61 deletions
61
src/NServiceBus.Core.Tests/Hosting/When_creating_host_information_from_environment.cs
This file was deleted.
Oops, something went wrong.
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
58 changes: 58 additions & 0 deletions
58
src/NServiceBus.Core.Tests/Unicast/Config/PathUtilities_Tests.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,58 @@ | ||
namespace NServiceBus.Features.Tests | ||
{ | ||
using NUnit.Framework; | ||
|
||
[TestFixture] | ||
public class PathUtilities_Tests | ||
{ | ||
[Test] | ||
public void Parse_from_path_without_spaces_but_with_quotes() | ||
{ | ||
var path = PathUtilities.SanitizedPath("\"pathto\\mysuperduper.exe\" somevar"); | ||
|
||
Assert.AreEqual("pathto\\mysuperduper.exe", path); | ||
} | ||
|
||
[Test] | ||
public void Parse_from_path_without_spaces_but_without_quotes() | ||
{ | ||
var path = PathUtilities.SanitizedPath("pathto\\mysuperduper.exe somevar"); | ||
|
||
Assert.AreEqual("pathto\\mysuperduper.exe", path); | ||
} | ||
|
||
[Test] | ||
public void Paths_without_spaces_are_equal() | ||
{ | ||
var path1 = PathUtilities.SanitizedPath("\"pathto\\mysuperduper.exe\" somevar"); | ||
var path2 = PathUtilities.SanitizedPath("pathto\\mysuperduper.exe somevar"); | ||
|
||
Assert.AreEqual(path1, path2); | ||
} | ||
|
||
[Test] | ||
public void Parse_from_path_with_spaces_having_a_parameter_with_spaces() | ||
{ | ||
var path = PathUtilities.SanitizedPath("\"pathto\\mysuper duper.exe\" \"somevar with spaces\""); | ||
|
||
Assert.AreEqual("pathto\\mysuper duper.exe", path); | ||
} | ||
|
||
[Test] | ||
public void Parse_from_path_with_spaces_having_a_parameter_without_spaces() | ||
{ | ||
var path = PathUtilities.SanitizedPath("\"pathto\\mysuper duper.exe\" somevar"); | ||
|
||
Assert.AreEqual("pathto\\mysuper duper.exe", path); | ||
} | ||
|
||
[Test] | ||
public void Both_paths_with_spaces_are_equal() | ||
{ | ||
var path1 = PathUtilities.SanitizedPath("\"pathto\\mysuper duper.exe\" \"somevar with spaces\""); | ||
var path2 = PathUtilities.SanitizedPath("\"pathto\\mysuper duper.exe\" somevar"); | ||
|
||
Assert.AreEqual(path1, path2); | ||
} | ||
} | ||
} |
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,19 @@ | ||
namespace NServiceBus.Features | ||
{ | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
|
||
internal static class PathUtilities | ||
{ | ||
public static string SanitizedPath(string commandLine) | ||
{ | ||
if (commandLine.StartsWith("\"")) | ||
{ | ||
return (from Match match in Regex.Matches(commandLine, "\"([^\"]*)\"") | ||
select match.ToString()).First().Trim('"'); | ||
} | ||
|
||
return commandLine.Split(' ').First(); | ||
} | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.