-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Azure Functions unit testing sample #312
Conversation
ILogger logger = context.CreateReplaySafeLogger(nameof(AzureFunctionsApp)); | ||
logger.LogInformation("Saying hello."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add this back right after the change to make CreateReplaySafeLogger
virtual is released.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this be needed if you use Moq.Protected
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, added it back just now
Co-authored-by: Jacob Viau <javia@microsoft.com>
Co-authored-by: Jacob Viau <javia@microsoft.com>
Co-authored-by: Jacob Viau <javia@microsoft.com>
ILogger logger = context.CreateReplaySafeLogger(nameof(AzureFunctionsApp)); | ||
logger.LogInformation("Saying hello."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this be needed if you use Moq.Protected
?
Co-authored-by: Jacob Viau <javia@microsoft.com>
@@ -385,7 +385,7 @@ public virtual Task CallSubOrchestratorAsync(TaskName orchestratorName, TaskOpti | |||
/// </summary> | |||
/// <param name="categoryName">The logger's category name.</param> | |||
/// <returns>An instance of <see cref="ILogger"/> that is replay-safe.</returns> | |||
public ILogger CreateReplaySafeLogger(string categoryName) | |||
public virtual ILogger CreateReplaySafeLogger(string categoryName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you still want this change, it is fine to leave in. Otherwise if you think Moq.Protected
is sufficient, we can remove this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to keep this as I'd like for customer to be able to mock this directly :)
We've received a few requests to provide unit testing samples for Azure Functions. This PR provides a minimal example of how to set up such tests.
In general, I had no issue mocking the DF APIs except for the
CreateReplaySafeLogger
API, and the Azure Functions workerGetLogger
API, both of which are not marked as virtual or abstract, and therefore cannot be mocked. Not sure what's the guidance for dealing with those APIs, perhaps it's just a gap in the unit testing experience today. As a result, I removed the logger usage in the Azure Functions samples, so that the methods there could be unit tested in their entirerty.To help bridge the gap on the DF-side, I marked
CreateReplaySafeLogger
as virtual. On the Functions worker side, we may need guidance or assistance.