Skip to content

Commit f2f20b4

Browse files
committed
Make decorated entity example self-contained
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 643dfa24-59f4-4119-9377-0d9e488df141
1 parent 4d90fc6 commit f2f20b4

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

azure-functions-durable/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,26 @@ assert outcome.actions == ()
6161
For an `entity_trigger`-decorated function, pass the exposed entity function:
6262

6363
```python
64+
import azure.durable_functions as df
65+
from azure.durable_functions.testing import execute_entity
66+
67+
68+
app = df.DFApp()
69+
70+
71+
@app.entity_trigger(context_name="context")
72+
def counter(context: df.DurableEntityContext) -> None:
73+
value = context.get_state(initializer=lambda: 0)
74+
value += context.get_input()
75+
context.set_state(value)
76+
context.set_result(value)
77+
78+
6479
entity_function = counter.build().get_user_function().entity_function
6580
outcome = execute_entity(entity_function, "add", input=2, state=3)
81+
82+
assert outcome.result == 5
83+
assert outcome.state == 5
6684
```
6785

6886
The returned `EntityTestResult` includes the operation result, resulting state,

0 commit comments

Comments
 (0)