-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test to verify credentials work (#521)
* Add test to verify credentials work * Cleanup * Cleanup and alignment of tests --------- Co-authored-by: Daniel Marbach <danielmarbach@users.noreply.github.com>
- Loading branch information
1 parent
71ef2a6
commit df2688d
Showing
15 changed files
with
111 additions
and
61 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
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
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
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
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
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
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
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
76 changes: 76 additions & 0 deletions
76
...ons.Worker.ServiceBus.Tests/When_using_token_credential_with_fully_qualified_namespace.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,76 @@ | ||
namespace NServiceBus.AzureFunctions.Worker.ServiceBus.Tests | ||
{ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AcceptanceTesting; | ||
using Azure.Messaging.ServiceBus; | ||
using NUnit.Framework; | ||
using static System.Environment; | ||
|
||
public class When_using_token_credential_with_fully_qualified_namespace | ||
{ | ||
string fullyQualifiedNamespace; | ||
string originalConnectionString; | ||
readonly string fullyQualifiedNamespaceStringKey = $"{defaultConnectionStringKey}__fullyQualifiedNamespace"; | ||
static readonly string defaultConnectionStringKey = ServerlessTransport.DefaultServiceBusConnectionName; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
originalConnectionString = GetEnvironmentVariable(defaultConnectionStringKey); | ||
|
||
var connectionStringProperties = ServiceBusConnectionStringProperties.Parse(originalConnectionString); | ||
fullyQualifiedNamespace = connectionStringProperties.FullyQualifiedNamespace; | ||
|
||
SetEnvironmentVariable(defaultConnectionStringKey, null, EnvironmentVariableTarget.Process); | ||
SetEnvironmentVariable(fullyQualifiedNamespaceStringKey, | ||
fullyQualifiedNamespace, EnvironmentVariableTarget.Process); | ||
} | ||
|
||
[Test] | ||
public async Task Should_work() | ||
{ | ||
Context context = await Scenario.Define<Context>() | ||
.WithComponent(new FunctionUsingTokenCredential()) | ||
.Done(c => c.HandlerInvocationCount > 0) | ||
.Run(); | ||
|
||
Assert.That(context.HandlerInvocationCount, Is.EqualTo(1)); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
SetEnvironmentVariable(fullyQualifiedNamespaceStringKey, | ||
fullyQualifiedNamespace, EnvironmentVariableTarget.Process); | ||
SetEnvironmentVariable(ServerlessTransport.DefaultServiceBusConnectionName, | ||
originalConnectionString); | ||
} | ||
|
||
class Context : ScenarioContext | ||
{ | ||
public int HandlerInvocationCount => count; | ||
|
||
public void HandlerInvoked() => Interlocked.Increment(ref count); | ||
|
||
int count; | ||
} | ||
|
||
class FunctionUsingTokenCredential : FunctionEndpointComponent | ||
{ | ||
public FunctionUsingTokenCredential() => AddTestMessage(new Message()); | ||
|
||
class Handler(Context testContext) : IHandleMessages<Message> | ||
{ | ||
public Task Handle(Message message, IMessageHandlerContext context) | ||
{ | ||
testContext.HandlerInvoked(); | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} | ||
|
||
class Message : ICommand; | ||
} | ||
} |