Skip to content

Commit

Permalink
[Service Bus Functions Extensions] Session Actions Mock Support (#25493)
Browse files Browse the repository at this point in the history
# Summary

The focus of these changes is to add a protected constructor to the `ServiceBusSessionMessageActions` class to support mocking for test scenarios.

# References and Related

- [Twitter thread discussing mocking difficulties](https://twitter.com/rolandkru/status/1462756372651593733)
- [[Service Bus Functions Extensions] Actions Mock Support (#25489)](#25489)
  • Loading branch information
jsquire authored Nov 23, 2021
1 parent 3fe8d28 commit f3dd315
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public ServiceBusOptions() { }
}
public partial class ServiceBusSessionMessageActions : Microsoft.Azure.WebJobs.ServiceBus.ServiceBusMessageActions
{
internal ServiceBusSessionMessageActions() { }
protected ServiceBusSessionMessageActions() { }
public virtual System.Threading.Tasks.Task<System.BinaryData> GetSessionStateAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task SetSessionStateAsync(System.BinaryData sessionState, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ internal ServiceBusSessionMessageActions(ServiceBusSessionReceiver receiver) : b
_receiver = receiver;
}

/// <summary>
/// Initializes a new instance of the <see cref="ServiceBusSessionMessageActions"/> class for mocking use in testing.
/// </summary>
/// <remarks>
/// This constructor exists only to support mocking. When used, class state is not fully initialized, and
/// will not function correctly; virtual members are meant to be mocked.
///</remarks>
protected ServiceBusSessionMessageActions()
{
}

/// <inheritdoc cref="ServiceBusSessionReceiver.GetSessionStateAsync(CancellationToken)"/>
public virtual async Task<BinaryData> GetSessionStateAsync(
CancellationToken cancellationToken = default)
Expand Down

0 comments on commit f3dd315

Please sign in to comment.