├── .github
├── ISSUE_TEMPLATE.md
└── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── CHANGELOG.md
├── CONTRIBUTING.md
├── DotNet
├── DotNet.Test
│ ├── DotNet.Test.csproj
│ ├── DurableFunctionTest.cs
│ ├── HttpTriggerTest.cs
│ └── QueueTriggerTest.cs
├── DotNet.sln
├── DotNet
│ ├── .gitignore
│ ├── DotNet.csproj
│ ├── DurableFunctions.cs
│ ├── HttpTrigger.cs
│ ├── QueueTrigger.cs
│ └── host.json
└── FunctionTestHelper
│ ├── FunctionTest.cs
│ ├── FunctionTestHelper.csproj
│ └── VerboseDignosticsTraceWriter.cs
├── LICENSE.md
└── README.md
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
4 | > Please provide us with the following information:
5 | > ---------------------------------------------------------------
6 |
7 | ### This issue is for a: (mark with an `x`)
8 | ```
9 | - [ ] bug report -> please search issues before submitting
10 | - [ ] feature request
11 | - [ ] documentation issue or request
12 | - [ ] regression (a behavior that used to work and stopped in a new release)
13 | ```
14 |
15 | ### Minimal steps to reproduce
16 | >
17 |
18 | ### Any log messages given by the failure
19 | >
20 |
21 | ### Expected/desired behavior
22 | >
23 |
24 | ### OS and Version?
25 | > Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)
26 |
27 | ### Versions
28 | >
29 |
30 | ### Mention any other details that might be useful
31 |
32 | > ---------------------------------------------------------------
33 | > Thanks! We'll be in touch soon.
34 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Purpose
2 |
3 | * ...
4 |
5 | ## Does this introduce a breaking change?
6 |
7 | ```
8 | [ ] Yes
9 | [ ] No
10 | ```
11 |
12 | ## Pull Request Type
13 | What kind of change does this Pull Request introduce?
14 |
15 |
16 | ```
17 | [ ] Bugfix
18 | [ ] Feature
19 | [ ] Code style update (formatting, local variables)
20 | [ ] Refactoring (no functional changes, no api changes)
21 | [ ] Documentation content changes
22 | [ ] Other... Please describe:
23 | ```
24 |
25 | ## How to Test
26 | * Get the code
27 |
28 | ```
29 | git clone [repo-address]
30 | cd [repo-name]
31 | git checkout [branch-name]
32 | npm install
33 | ```
34 |
35 | * Test the code
36 |
37 | ```
38 | ```
39 |
40 | ## What to Check
41 | Verify that the following are valid
42 | * ...
43 |
44 | ## Other Information
45 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # MSTest test Results
33 | [Tt]est[Rr]esult*/
34 | [Bb]uild[Ll]og.*
35 |
36 | # NUNIT
37 | *.VisualState.xml
38 | TestResult.xml
39 |
40 | # Build Results of an ATL Project
41 | [Dd]ebugPS/
42 | [Rr]eleasePS/
43 | dlldata.c
44 |
45 | # .NET Core
46 | project.lock.json
47 | project.fragment.lock.json
48 | artifacts/
49 | **/Properties/launchSettings.json
50 |
51 | *_i.c
52 | *_p.c
53 | *_i.h
54 | *.ilk
55 | *.meta
56 | *.obj
57 | *.pch
58 | *.pdb
59 | *.pgc
60 | *.pgd
61 | *.rsp
62 | *.sbr
63 | *.tlb
64 | *.tli
65 | *.tlh
66 | *.tmp
67 | *.tmp_proj
68 | *.log
69 | *.vspscc
70 | *.vssscc
71 | .builds
72 | *.pidb
73 | *.svclog
74 | *.scc
75 |
76 | # Chutzpah Test files
77 | _Chutzpah*
78 |
79 | # Visual C++ cache files
80 | ipch/
81 | *.aps
82 | *.ncb
83 | *.opendb
84 | *.opensdf
85 | *.sdf
86 | *.cachefile
87 | *.VC.db
88 | *.VC.VC.opendb
89 |
90 | # Visual Studio profiler
91 | *.psess
92 | *.vsp
93 | *.vspx
94 | *.sap
95 |
96 | # TFS 2012 Local Workspace
97 | $tf/
98 |
99 | # Guidance Automation Toolkit
100 | *.gpState
101 |
102 | # ReSharper is a .NET coding add-in
103 | _ReSharper*/
104 | *.[Rr]e[Ss]harper
105 | *.DotSettings.user
106 |
107 | # JustCode is a .NET coding add-in
108 | .JustCode
109 |
110 | # TeamCity is a build add-in
111 | _TeamCity*
112 |
113 | # DotCover is a Code Coverage Tool
114 | *.dotCover
115 |
116 | # Visual Studio code coverage results
117 | *.coverage
118 | *.coveragexml
119 |
120 | # NCrunch
121 | _NCrunch_*
122 | .*crunch*.local.xml
123 | nCrunchTemp_*
124 |
125 | # MightyMoose
126 | *.mm.*
127 | AutoTest.Net/
128 |
129 | # Web workbench (sass)
130 | .sass-cache/
131 |
132 | # Installshield output folder
133 | [Ee]xpress/
134 |
135 | # DocProject is a documentation generator add-in
136 | DocProject/buildhelp/
137 | DocProject/Help/*.HxT
138 | DocProject/Help/*.HxC
139 | DocProject/Help/*.hhc
140 | DocProject/Help/*.hhk
141 | DocProject/Help/*.hhp
142 | DocProject/Help/Html2
143 | DocProject/Help/html
144 |
145 | # Click-Once directory
146 | publish/
147 |
148 | # Publish Web Output
149 | *.[Pp]ublish.xml
150 | *.azurePubxml
151 | # TODO: Comment the next line if you want to checkin your web deploy settings
152 | # but database connection strings (with potential passwords) will be unencrypted
153 | *.pubxml
154 | *.publishproj
155 |
156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
157 | # checkin your Azure Web App publish settings, but sensitive information contained
158 | # in these scripts will be unencrypted
159 | PublishScripts/
160 |
161 | # NuGet Packages
162 | *.nupkg
163 | # The packages folder can be ignored because of Package Restore
164 | **/packages/*
165 | # except build/, which is used as an MSBuild target.
166 | !**/packages/build/
167 | # Uncomment if necessary however generally it will be regenerated when needed
168 | #!**/packages/repositories.config
169 | # NuGet v3's project.json files produces more ignorable files
170 | *.nuget.props
171 | *.nuget.targets
172 |
173 | # Microsoft Azure Build Output
174 | csx/
175 | *.build.csdef
176 |
177 | # Microsoft Azure Emulator
178 | ecf/
179 | rcf/
180 |
181 | # Windows Store app package directories and files
182 | AppPackages/
183 | BundleArtifacts/
184 | Package.StoreAssociation.xml
185 | _pkginfo.txt
186 |
187 | # Visual Studio cache files
188 | # files ending in .cache can be ignored
189 | *.[Cc]ache
190 | # but keep track of directories ending in .cache
191 | !*.[Cc]ache/
192 |
193 | # Others
194 | ClientBin/
195 | ~$*
196 | *~
197 | *.dbmdl
198 | *.dbproj.schemaview
199 | *.jfm
200 | *.pfx
201 | *.publishsettings
202 | orleans.codegen.cs
203 |
204 | # Since there are multiple workflows, uncomment next line to ignore bower_components
205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
206 | #bower_components/
207 |
208 | # RIA/Silverlight projects
209 | Generated_Code/
210 |
211 | # Backup & report files from converting an old project file
212 | # to a newer Visual Studio version. Backup files are not needed,
213 | # because we have git ;-)
214 | _UpgradeReport_Files/
215 | Backup*/
216 | UpgradeLog*.XML
217 | UpgradeLog*.htm
218 |
219 | # SQL Server files
220 | *.mdf
221 | *.ldf
222 | *.ndf
223 |
224 | # Business Intelligence projects
225 | *.rdl.data
226 | *.bim.layout
227 | *.bim_*.settings
228 |
229 | # Microsoft Fakes
230 | FakesAssemblies/
231 |
232 | # GhostDoc plugin setting file
233 | *.GhostDoc.xml
234 |
235 | # Node.js Tools for Visual Studio
236 | .ntvs_analysis.dat
237 | node_modules/
238 |
239 | # Typescript v1 declaration files
240 | typings/
241 |
242 | # Visual Studio 6 build log
243 | *.plg
244 |
245 | # Visual Studio 6 workspace options file
246 | *.opt
247 |
248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
249 | *.vbw
250 |
251 | # Visual Studio LightSwitch build output
252 | **/*.HTMLClient/GeneratedArtifacts
253 | **/*.DesktopClient/GeneratedArtifacts
254 | **/*.DesktopClient/ModelManifest.xml
255 | **/*.Server/GeneratedArtifacts
256 | **/*.Server/ModelManifest.xml
257 | _Pvt_Extensions
258 |
259 | # Paket dependency manager
260 | .paket/paket.exe
261 | paket-files/
262 |
263 | # FAKE - F# Make
264 | .fake/
265 |
266 | # JetBrains Rider
267 | .idea/
268 | *.sln.iml
269 |
270 | # CodeRush
271 | .cr/
272 |
273 | # Python Tools for Visual Studio (PTVS)
274 | __pycache__/
275 | *.pyc
276 |
277 | # Cake - Uncomment if you are using it
278 | # tools/**
279 | # !tools/packages.config
280 |
281 | # Telerik's JustMock configuration file
282 | *.jmconfig
283 |
284 | # BizTalk build output
285 | *.btp.cs
286 | *.btm.cs
287 | *.odx.cs
288 | *.xsd.cs
289 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## [project-title] Changelog
2 |
3 |
4 | # x.y.z (yyyy-mm-dd)
5 |
6 | *Features*
7 | * ...
8 |
9 | *Bug Fixes*
10 | * ...
11 |
12 | *Breaking Changes*
13 | * ...
14 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to [project-title]
2 |
3 | This project welcomes contributions and suggestions. Most contributions require you to agree to a
4 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
5 | the rights to use your contribution. For details, visit https://cla.microsoft.com.
6 |
7 | When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
8 | a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
9 | provided by the bot. You will only need to do this once across all repos using our CLA.
10 |
11 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
12 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
13 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
14 |
15 | - [Code of Conduct](#coc)
16 | - [Issues and Bugs](#issue)
17 | - [Feature Requests](#feature)
18 | - [Submission Guidelines](#submit)
19 |
20 | ## Code of Conduct
21 | Help us keep this project open and inclusive. Please read and follow our [Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
22 |
23 | ## Found an Issue?
24 | If you find a bug in the source code or a mistake in the documentation, you can help us by
25 | [submitting an issue](#submit-issue) to the GitHub Repository. Even better, you can
26 | [submit a Pull Request](#submit-pr) with a fix.
27 |
28 | ## Want a Feature?
29 | You can *request* a new feature by [submitting an issue](#submit-issue) to the GitHub
30 | Repository. If you would like to *implement* a new feature, please submit an issue with
31 | a proposal for your work first, to be sure that we can use it.
32 |
33 | * **Small Features** can be crafted and directly [submitted as a Pull Request](#submit-pr).
34 |
35 | ## Submission Guidelines
36 |
37 | ### Submitting an Issue
38 | Before you submit an issue, search the archive, maybe your question was already answered.
39 |
40 | If your issue appears to be a bug, and hasn't been reported, open a new issue.
41 | Help us to maximize the effort we can spend fixing issues and adding new
42 | features, by not reporting duplicate issues. Providing the following information will increase the
43 | chances of your issue being dealt with quickly:
44 |
45 | * **Overview of the Issue** - if an error is being thrown a non-minified stack trace helps
46 | * **Version** - what version is affected (e.g. 0.1.2)
47 | * **Motivation for or Use Case** - explain what are you trying to do and why the current behavior is a bug for you
48 | * **Browsers and Operating System** - is this a problem with all browsers?
49 | * **Reproduce the Error** - provide a live example or a unambiguous set of steps
50 | * **Related Issues** - has a similar issue been reported before?
51 | * **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be
52 | causing the problem (line of code or commit)
53 |
54 | You can file new issues by providing the above information at the corresponding repository's issues link: https://github.com/[organization-name]/[repository-name]/issues/new].
55 |
56 | ### Submitting a Pull Request (PR)
57 | Before you submit your Pull Request (PR) consider the following guidelines:
58 |
59 | * Search the repository (https://github.com/[organization-name]/[repository-name]/pulls) for an open or closed PR
60 | that relates to your submission. You don't want to duplicate effort.
61 |
62 | * Make your changes in a new git fork:
63 |
64 | * Commit your changes using a descriptive commit message
65 | * Push your fork to GitHub:
66 | * In GitHub, create a pull request
67 | * If we suggest changes then:
68 | * Make the required updates.
69 | * Rebase your fork and force push to your GitHub repository (this will update your Pull Request):
70 |
71 | ```shell
72 | git rebase master -i
73 | git push -f
74 | ```
75 |
76 | That's it! Thank you for your contribution!
77 |
--------------------------------------------------------------------------------
/DotNet/DotNet.Test/DotNet.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.0
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/DotNet/DotNet.Test/DurableFunctionTest.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 | using Moq;
6 | using System.Threading.Tasks;
7 | using Microsoft.Azure.WebJobs;
8 | using System.Net.Http;
9 |
10 | namespace DotNet.Test
11 | {
12 | [TestClass]
13 | public class DurableFunctionTest : FunctionTestHelper.FunctionTest
14 | {
15 | [TestMethod]
16 | public async Task Run_Orchectrator()
17 | {
18 | var contextMock = new Mock();
19 | contextMock.Setup(context => context.CallActivityAsync("DurableFunctions_Hello", "Tokyo")).Returns(Task.FromResult("Hello Tokyo!"));
20 | contextMock.Setup(context => context.CallActivityAsync("DurableFunctions_Hello", "Seattle")).Returns(Task.FromResult("Hello Seattle!"));
21 | contextMock.Setup(context => context.CallActivityAsync("DurableFunctions_Hello", "London")).Returns(Task.FromResult("Hello London!"));
22 | var result = await DotNet.DurableFunctions.RunOrchestrator(contextMock.Object);
23 | Assert.AreEqual("Hello Tokyo!", result[0]);
24 | Assert.AreEqual("Hello Seattle!", result[1]);
25 | Assert.AreEqual("Hello London!", result[2]);
26 | }
27 |
28 | [TestMethod]
29 | public async Task Run_Hello_Activity()
30 | {
31 | var result = DotNet.DurableFunctions.SayHello("Amsterdam", log);
32 | Assert.AreEqual("Hello Amsterdam!", result);
33 | }
34 |
35 | [TestMethod]
36 | public async Task Run_Orchectrator_Client()
37 | {
38 | var clientMock = new Mock();
39 | // https://github.com/Azure/azure-functions-durable-extension/blob/0345b369ffa1745c24ffbacfaf8a43fb62dd2572/src/WebJobs.Extensions.DurableTask/DurableOrchestrationClient.cs#L46
40 | var requestMock = new Mock();
41 | var id = "8e503c5e-19de-40e1-932d-298c4263115b";
42 | clientMock.Setup(client => client.StartNewAsync("DurableFunctions", null)).Returns(Task.FromResult(id));
43 | var request = requestMock.Object;
44 | clientMock.Setup(client => client.CreateCheckStatusResponse(request, id));
45 | var result = DotNet.DurableFunctions.HttpStart(request, clientMock.Object, log);
46 | try
47 | {
48 |
49 | clientMock.Verify(client => client.StartNewAsync("DurableFunctions", null));
50 | clientMock.Verify(client => client.CreateCheckStatusResponse(request, id));
51 | } catch (MockException ex)
52 | {
53 | Assert.Fail();
54 | }
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/DotNet/DotNet.Test/HttpTriggerTest.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using Microsoft.AspNetCore.Http;
3 | using Moq;
4 | using System.Threading.Tasks;
5 | using System.Collections.Generic;
6 | using System;
7 | using Microsoft.Extensions.Primitives;
8 | using Microsoft.AspNetCore.Http.Internal;
9 | using System.IO;
10 | using DotNet;
11 | using Microsoft.AspNetCore.Mvc;
12 |
13 | namespace DotNet.Test
14 | {
15 | [TestClass]
16 | public class HttpTriggerTest : FunctionTestHelper.FunctionTest
17 | {
18 | [TestMethod]
19 | public async Task Request_With_Query()
20 | {
21 | var query = new Dictionary();
22 | query.TryAdd("name", "ushio");
23 | var body = "";
24 |
25 | var result = await HttpTrigger.RunAsync(req: HttpRequestSetup(query, body), log: log);
26 | var resultObject = (OkObjectResult)result;
27 | Assert.AreEqual("Hello, ushio", resultObject.Value);
28 |
29 | }
30 |
31 | [TestMethod]
32 | public async Task Request_Without_Query()
33 | {
34 | var query = new Dictionary();
35 | var body = "{\"name\":\"yamada\"}";
36 |
37 | var result = await HttpTrigger.RunAsync(HttpRequestSetup(query, body), log);
38 | var resultObject = (OkObjectResult)result;
39 | Assert.AreEqual("Hello, yamada", resultObject.Value);
40 |
41 | }
42 |
43 | [TestMethod]
44 | public async Task Request_Without_Query_And_Body()
45 | {
46 | var query = new Dictionary();
47 | var body = "";
48 | var result = await HttpTrigger.RunAsync(HttpRequestSetup(query, body), log);
49 | var resultObject = (BadRequestObjectResult)result;
50 | Assert.AreEqual("Please pass a name on the query string or in the request body", resultObject.Value);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/DotNet/DotNet.Test/QueueTriggerTest.cs:
--------------------------------------------------------------------------------
1 | using FunctionTestHelper;
2 | using Microsoft.Azure.WebJobs;
3 | using Microsoft.VisualStudio.TestTools.UnitTesting;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using static DotNet.QueueTrigger;
9 |
10 | namespace DotNet.Test
11 | {
12 | [TestClass]
13 | public class QueueTriggerTest : FunctionTestHelper.FunctionTest
14 | {
15 | [TestMethod]
16 | public async Task Recieve_Queue_And_Emit_To_Table()
17 | {
18 | var col = new AsyncCollector();
19 | var json = "{\"name\": \"ushio\"}";
20 | await DotNet.QueueTrigger.RunAsync(json, col, log);
21 | Assert.AreEqual(json, col.Items[0].Text);
22 |
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/DotNet/DotNet.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27323.2
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNet", "DotNet\DotNet.csproj", "{B156689D-45A9-4DF6-9859-C974F06DACFA}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNet.Test", "DotNet.Test\DotNet.Test.csproj", "{A0A2C310-7750-4C5F-B3D7-150EF4F3F827}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FunctionTestHelper", "FunctionTestHelper\FunctionTestHelper.csproj", "{D1475DA2-BC46-48F7-821D-3DB40F7326FC}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {B156689D-45A9-4DF6-9859-C974F06DACFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {B156689D-45A9-4DF6-9859-C974F06DACFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {B156689D-45A9-4DF6-9859-C974F06DACFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {B156689D-45A9-4DF6-9859-C974F06DACFA}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {A0A2C310-7750-4C5F-B3D7-150EF4F3F827}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {A0A2C310-7750-4C5F-B3D7-150EF4F3F827}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {A0A2C310-7750-4C5F-B3D7-150EF4F3F827}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {A0A2C310-7750-4C5F-B3D7-150EF4F3F827}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {D1475DA2-BC46-48F7-821D-3DB40F7326FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {D1475DA2-BC46-48F7-821D-3DB40F7326FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {D1475DA2-BC46-48F7-821D-3DB40F7326FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {D1475DA2-BC46-48F7-821D-3DB40F7326FC}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | GlobalSection(ExtensibilityGlobals) = postSolution
35 | SolutionGuid = {075F6066-B0C2-4E52-B095-B3F9A44FE680}
36 | EndGlobalSection
37 | EndGlobal
38 |
--------------------------------------------------------------------------------
/DotNet/DotNet/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # Azure Functions localsettings file
5 | local.settings.json
6 |
7 | # User-specific files
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Dd]ebugPublic/
19 | [Rr]elease/
20 | [Rr]eleases/
21 | x64/
22 | x86/
23 | bld/
24 | [Bb]in/
25 | [Oo]bj/
26 | [Ll]og/
27 |
28 | # Visual Studio 2015 cache/options directory
29 | .vs/
30 | # Uncomment if you have tasks that create the project's static files in wwwroot
31 | #wwwroot/
32 |
33 | # MSTest test Results
34 | [Tt]est[Rr]esult*/
35 | [Bb]uild[Ll]og.*
36 |
37 | # NUNIT
38 | *.VisualState.xml
39 | TestResult.xml
40 |
41 | # Build Results of an ATL Project
42 | [Dd]ebugPS/
43 | [Rr]eleasePS/
44 | dlldata.c
45 |
46 | # DNX
47 | project.lock.json
48 | project.fragment.lock.json
49 | artifacts/
50 |
51 | *_i.c
52 | *_p.c
53 | *_i.h
54 | *.ilk
55 | *.meta
56 | *.obj
57 | *.pch
58 | *.pdb
59 | *.pgc
60 | *.pgd
61 | *.rsp
62 | *.sbr
63 | *.tlb
64 | *.tli
65 | *.tlh
66 | *.tmp
67 | *.tmp_proj
68 | *.log
69 | *.vspscc
70 | *.vssscc
71 | .builds
72 | *.pidb
73 | *.svclog
74 | *.scc
75 |
76 | # Chutzpah Test files
77 | _Chutzpah*
78 |
79 | # Visual C++ cache files
80 | ipch/
81 | *.aps
82 | *.ncb
83 | *.opendb
84 | *.opensdf
85 | *.sdf
86 | *.cachefile
87 | *.VC.db
88 | *.VC.VC.opendb
89 |
90 | # Visual Studio profiler
91 | *.psess
92 | *.vsp
93 | *.vspx
94 | *.sap
95 |
96 | # TFS 2012 Local Workspace
97 | $tf/
98 |
99 | # Guidance Automation Toolkit
100 | *.gpState
101 |
102 | # ReSharper is a .NET coding add-in
103 | _ReSharper*/
104 | *.[Rr]e[Ss]harper
105 | *.DotSettings.user
106 |
107 | # JustCode is a .NET coding add-in
108 | .JustCode
109 |
110 | # TeamCity is a build add-in
111 | _TeamCity*
112 |
113 | # DotCover is a Code Coverage Tool
114 | *.dotCover
115 |
116 | # NCrunch
117 | _NCrunch_*
118 | .*crunch*.local.xml
119 | nCrunchTemp_*
120 |
121 | # MightyMoose
122 | *.mm.*
123 | AutoTest.Net/
124 |
125 | # Web workbench (sass)
126 | .sass-cache/
127 |
128 | # Installshield output folder
129 | [Ee]xpress/
130 |
131 | # DocProject is a documentation generator add-in
132 | DocProject/buildhelp/
133 | DocProject/Help/*.HxT
134 | DocProject/Help/*.HxC
135 | DocProject/Help/*.hhc
136 | DocProject/Help/*.hhk
137 | DocProject/Help/*.hhp
138 | DocProject/Help/Html2
139 | DocProject/Help/html
140 |
141 | # Click-Once directory
142 | publish/
143 |
144 | # Publish Web Output
145 | *.[Pp]ublish.xml
146 | *.azurePubxml
147 | # TODO: Comment the next line if you want to checkin your web deploy settings
148 | # but database connection strings (with potential passwords) will be unencrypted
149 | #*.pubxml
150 | *.publishproj
151 |
152 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
153 | # checkin your Azure Web App publish settings, but sensitive information contained
154 | # in these scripts will be unencrypted
155 | PublishScripts/
156 |
157 | # NuGet Packages
158 | *.nupkg
159 | # The packages folder can be ignored because of Package Restore
160 | **/packages/*
161 | # except build/, which is used as an MSBuild target.
162 | !**/packages/build/
163 | # Uncomment if necessary however generally it will be regenerated when needed
164 | #!**/packages/repositories.config
165 | # NuGet v3's project.json files produces more ignoreable files
166 | *.nuget.props
167 | *.nuget.targets
168 |
169 | # Microsoft Azure Build Output
170 | csx/
171 | *.build.csdef
172 |
173 | # Microsoft Azure Emulator
174 | ecf/
175 | rcf/
176 |
177 | # Windows Store app package directories and files
178 | AppPackages/
179 | BundleArtifacts/
180 | Package.StoreAssociation.xml
181 | _pkginfo.txt
182 |
183 | # Visual Studio cache files
184 | # files ending in .cache can be ignored
185 | *.[Cc]ache
186 | # but keep track of directories ending in .cache
187 | !*.[Cc]ache/
188 |
189 | # Others
190 | ClientBin/
191 | ~$*
192 | *~
193 | *.dbmdl
194 | *.dbproj.schemaview
195 | *.jfm
196 | *.pfx
197 | *.publishsettings
198 | node_modules/
199 | orleans.codegen.cs
200 |
201 | # Since there are multiple workflows, uncomment next line to ignore bower_components
202 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
203 | #bower_components/
204 |
205 | # RIA/Silverlight projects
206 | Generated_Code/
207 |
208 | # Backup & report files from converting an old project file
209 | # to a newer Visual Studio version. Backup files are not needed,
210 | # because we have git ;-)
211 | _UpgradeReport_Files/
212 | Backup*/
213 | UpgradeLog*.XML
214 | UpgradeLog*.htm
215 |
216 | # SQL Server files
217 | *.mdf
218 | *.ldf
219 |
220 | # Business Intelligence projects
221 | *.rdl.data
222 | *.bim.layout
223 | *.bim_*.settings
224 |
225 | # Microsoft Fakes
226 | FakesAssemblies/
227 |
228 | # GhostDoc plugin setting file
229 | *.GhostDoc.xml
230 |
231 | # Node.js Tools for Visual Studio
232 | .ntvs_analysis.dat
233 |
234 | # Visual Studio 6 build log
235 | *.plg
236 |
237 | # Visual Studio 6 workspace options file
238 | *.opt
239 |
240 | # Visual Studio LightSwitch build output
241 | **/*.HTMLClient/GeneratedArtifacts
242 | **/*.DesktopClient/GeneratedArtifacts
243 | **/*.DesktopClient/ModelManifest.xml
244 | **/*.Server/GeneratedArtifacts
245 | **/*.Server/ModelManifest.xml
246 | _Pvt_Extensions
247 |
248 | # Paket dependency manager
249 | .paket/paket.exe
250 | paket-files/
251 |
252 | # FAKE - F# Make
253 | .fake/
254 |
255 | # JetBrains Rider
256 | .idea/
257 | *.sln.iml
258 |
259 | # CodeRush
260 | .cr/
261 |
262 | # Python Tools for Visual Studio (PTVS)
263 | __pycache__/
264 | *.pyc
--------------------------------------------------------------------------------
/DotNet/DotNet/DotNet.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | netstandard2.0
4 | v2
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | PreserveNewest
13 |
14 |
15 | PreserveNewest
16 | Never
17 |
18 |
19 |
--------------------------------------------------------------------------------
/DotNet/DotNet/DurableFunctions.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Net.Http;
3 | using System.Threading.Tasks;
4 | using Microsoft.Azure.WebJobs;
5 | using Microsoft.Azure.WebJobs.Extensions.Http;
6 | using Microsoft.Azure.WebJobs.Host;
7 |
8 | namespace DotNet
9 | {
10 | public static class DurableFunctions
11 | {
12 | [FunctionName("DurableFunctions")]
13 | public static async Task> RunOrchestrator(
14 | [OrchestrationTrigger] DurableOrchestrationContextBase context)
15 | {
16 | var outputs = new List();
17 |
18 | // Replace "hello" with the name of your Durable Activity Function.
19 | outputs.Add(await context.CallActivityAsync("DurableFunctions_Hello", "Tokyo"));
20 | outputs.Add(await context.CallActivityAsync("DurableFunctions_Hello", "Seattle"));
21 | outputs.Add(await context.CallActivityAsync("DurableFunctions_Hello", "London"));
22 |
23 | // returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
24 | return outputs;
25 | }
26 |
27 | [FunctionName("DurableFunctions_Hello")]
28 | public static string SayHello([ActivityTrigger] string name, TraceWriter log)
29 | {
30 | log.Info($"Saying hello to {name}.");
31 | return $"Hello {name}!";
32 | }
33 |
34 | [FunctionName("DurableFunctions_HttpStart")]
35 | public static async Task HttpStart(
36 | [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")]HttpRequestMessage req,
37 | [OrchestrationClient]DurableOrchestrationClientBase starter,
38 | TraceWriter log)
39 | {
40 | // Function input comes from the request content.
41 | string instanceId = await starter.StartNewAsync("DurableFunctions", null);
42 |
43 | log.Info($"Started orchestration with ID = '{instanceId}'.");
44 | return starter.CreateCheckStatusResponse(req, instanceId);
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/DotNet/DotNet/HttpTrigger.cs:
--------------------------------------------------------------------------------
1 |
2 | using System.IO;
3 | using Microsoft.AspNetCore.Mvc;
4 | using Microsoft.Azure.WebJobs;
5 | using Microsoft.Azure.WebJobs.Extensions.Http;
6 | using Microsoft.AspNetCore.Http;
7 | using Microsoft.Azure.WebJobs.Host;
8 | using Newtonsoft.Json;
9 | using System.Threading.Tasks;
10 |
11 | namespace DotNet
12 | {
13 | public static class HttpTrigger
14 | {
15 | [FunctionName("HttpTrigger")]
16 | public async static Task RunAsync([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequest req, TraceWriter log)
17 | {
18 | log.Info("C# HTTP trigger function processed a request.");
19 |
20 | string name = req.Query["name"];
21 |
22 | string requestBody = new StreamReader(req.Body).ReadToEnd();
23 | dynamic data = JsonConvert.DeserializeObject(requestBody);
24 | name = name ?? data?.name;
25 |
26 | return name != null
27 | ? (ActionResult)new OkObjectResult($"Hello, {name}")
28 | : new BadRequestObjectResult("Please pass a name on the query string or in the request body");
29 | }
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/DotNet/DotNet/QueueTrigger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using Microsoft.Azure.WebJobs;
4 | using Microsoft.Azure.WebJobs.Host;
5 | using Microsoft.WindowsAzure.Storage.Table;
6 |
7 | namespace DotNet
8 | {
9 | public static class QueueTrigger
10 | {
11 | public class Message : TableEntity
12 | {
13 | public string Text { get; set; }
14 | }
15 |
16 | [FunctionName("Function1")]
17 | public async static Task RunAsync([QueueTrigger("myqueue-items", Connection = "connectionString")]string myQueueItem, [Table("MyTable", Connection = "connectionString")]IAsyncCollector messages, TraceWriter log)
18 | {
19 | log.Info($"C# Queue trigger function processed: {myQueueItem}");
20 | var message = new Message();
21 | message.PartitionKey = "1";
22 | message.RowKey = "2";
23 | message.Text = myQueueItem;
24 | await messages.AddAsync(message);
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/DotNet/DotNet/host.json:
--------------------------------------------------------------------------------
1 | {
2 | }
--------------------------------------------------------------------------------
/DotNet/FunctionTestHelper/FunctionTest.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Http;
2 | using Microsoft.AspNetCore.Http.Internal;
3 | using Microsoft.Azure.WebJobs;
4 | using Microsoft.Azure.WebJobs.Host;
5 | using Microsoft.Extensions.Primitives;
6 | using Moq;
7 | using System;
8 | using System.Collections.Generic;
9 | using System.IO;
10 | using System.Net.Http;
11 | using System.Text;
12 | using System.Threading;
13 | using System.Threading.Tasks;
14 |
15 | namespace FunctionTestHelper
16 | {
17 | public abstract class FunctionTest
18 | {
19 |
20 | protected TraceWriter log = new VerboseDiagnosticsTraceWriter();
21 |
22 | public HttpRequest HttpRequestSetup(Dictionary query, string body)
23 | {
24 | var reqMock = new Mock();
25 |
26 | reqMock.Setup(req => req.Query).Returns(new QueryCollection(query));
27 | var stream = new MemoryStream();
28 | var writer = new StreamWriter(stream);
29 | writer.Write(body);
30 | writer.Flush();
31 | stream.Position = 0;
32 | reqMock.Setup(req => req.Body).Returns(stream);
33 | return reqMock.Object;
34 | }
35 |
36 | }
37 |
38 | public class AsyncCollector : IAsyncCollector
39 | {
40 | public readonly List Items = new List();
41 |
42 | public Task AddAsync(T item, CancellationToken cancellationToken = default(CancellationToken))
43 | {
44 |
45 | Items.Add(item);
46 |
47 | return Task.FromResult(true);
48 | }
49 |
50 | public Task FlushAsync(CancellationToken cancellationToken = default(CancellationToken))
51 | {
52 | return Task.FromResult(true);
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/DotNet/FunctionTestHelper/FunctionTestHelper.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/DotNet/FunctionTestHelper/VerboseDignosticsTraceWriter.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Azure.WebJobs.Host;
2 | using System.Diagnostics;
3 |
4 | namespace FunctionTestHelper
5 | {
6 | public class VerboseDiagnosticsTraceWriter : TraceWriter
7 | {
8 |
9 | public VerboseDiagnosticsTraceWriter() : base(TraceLevel.Verbose)
10 | {
11 |
12 | }
13 | public override void Trace(TraceEvent traceEvent)
14 | {
15 | Debug.WriteLine(traceEvent.Message);
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Microsoft Corporation. All rights reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Azure Functions / Durable Functions Unit Testing Sample
4 |
5 | Azure Functions Unit Testing Samples for V2 Functions.
6 |
7 | ## Features
8 |
9 | The sample provides the following samples:
10 |
11 | * HttpTrigger
12 | * QueueTrigger
13 | * Table Output bindings
14 | * Durable Functions
15 |
16 | You can refer how to mock the apps. Also, you can re-use FunctionTestHelper package.
17 |
18 | We try to increase the samples, EventGridTrigger, EventHubTrigger, ServiceBus... and so on.
19 |
20 | ## Getting Started
21 |
22 | ### 1. Clone this samples
23 |
24 | Clone this repo with your Visual Studo.
25 |
26 | ```
27 | git clone https://github.com/Azure-Samples/functions-unittesting-sample.git
28 | ```
29 |
30 | ### Prerequisites
31 |
32 | Visual Studio 2017 (15.6+)
33 | .Net Core Runtime
34 |
35 |
36 | ### Note
37 |
38 | For enabling Durable Functions Unit Testing feature, you need to upgrade nuget packages.
39 |
40 | * Microsoft.NET.Sdk.Functions v1.0.7
41 | * Microsoft.Azure.WebJobs.Extensions.DurableTask v1.1.1-beta2
42 |
43 | You might need to add `https://www.myget.org/F/azure-appservice/api/v3/index.json` as a nuget package sources for fetching the DurableTask v1.1.1-beta2
44 |
45 |
46 | ## Resources
47 |
48 | Coming soon
49 |
50 |
--------------------------------------------------------------------------------