-
Notifications
You must be signed in to change notification settings - Fork 8
Make unit testing possible by switching to base context #17
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| module samples.unittest | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: the file name and module name should be in |
||
|
|
||
| open Microsoft.Azure.WebJobs | ||
| open DurableFunctions.FSharp | ||
| open System | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: unused |
||
|
|
||
| [<FunctionName("SayHelloTest")>] | ||
| let SayHello([<ActivityTrigger>] name) = | ||
| sprintf "Hello %s!" name | ||
|
|
||
| [<FunctionName("HelloSequenceTest")>] | ||
| let RunWorkflow ([<OrchestrationTrigger>] context: DurableOrchestrationContextBase) = | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would you think of the following style of the test:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep - makes sense - I'll try that and see how it goes |
||
| context |> | ||
| orchestrator { | ||
| let! hello1 = Activity.callByName<string> "SayHello" "Tokyo" | ||
| let! hello2 = Activity.callByName<string> "SayHello" "Seattle" | ||
| let! hello3 = Activity.callByName<string> "SayHello" "London" | ||
|
|
||
| // returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"] | ||
| return [hello1; hello2; hello3] | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using a strongly typed implementation style. I don't want to give the impression that only |
||
|
|
||
| module WorkflowTests = | ||
|
|
||
| open Moq | ||
| open Expecto | ||
|
|
||
|
|
||
| [<Tests>] | ||
| let tests = | ||
| testList "orchestration tests" [ | ||
| testAsync "Orchestration test no records" { | ||
|
|
||
| let mockContext = Mock<DurableOrchestrationContextBase>() | ||
| mockContext.Setup(fun c -> c.CallActivityAsync<string>("SayHello","Tokyo")).ReturnsAsync("Hello Tokyo") |> ignore | ||
| mockContext.Setup(fun c -> c.CallActivityAsync<string>("SayHello","Seattle")).ReturnsAsync("Hello Seattle") |> ignore | ||
| mockContext.Setup(fun c -> c.CallActivityAsync<string>("SayHello","London")).ReturnsAsync("Hello London") |> ignore | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks quite mechanic... Can you think of any helper functions that we could provide to make it read smoother? Aren't there any F#-y ways to mock things?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah I wanted to use the Foq library to mock as it has a much nicer way of setting up the expectations using quotations but it doesn't work with the DurableOrchestrationContextBase - one of the properties has a sealed setter that causes Foq to fail (someone else already raised that issue so if it gets fixed I can swap it in) |
||
| let! results = RunWorkflow mockContext.Object |> Async.AwaitTask | ||
|
|
||
| Expect.hasLength results 3 "should be 3 results" | ||
| Expect.equal results.[0] "Hello Tokyo!" "Should be Hello Tokyo!" | ||
| Expect.equal results.[1] "Hello Seattle!" "Should be Hello Seattle!" | ||
| Expect.equal results.[2] "Hello London!" "Should be Hello London!" | ||
| } | ||
| ] | ||
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.
This is really weird indeed. I can't see why type inference is broken... Almost seems like a bug in the compiler. Maybe we should change the example not to use
.Containsto avoid that.