Skip to content

Commit 4dfcdb3

Browse files
authored
Merge pull request #225 from metamemelord/gaursain/csharp-to-official
Moved C# to officially supported languages and fixed typos
2 parents dcbb152 + eb23f55 commit 4dfcdb3

2 files changed

Lines changed: 48 additions & 30 deletions

File tree

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ Official:
1414
* [Node.js](node/intro/README.md)
1515
* [Ruby](ruby/intro/README.md)
1616
* [Python](python/intro/README.md)
17-
18-
Community Supported:
19-
2017
* [C#](csharp/intro/README.md)
2118

2219
## Explore Fn

csharp/intro/README.md

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func.yaml created.
3939
>cd dotnetfn
4040
>```
4141
42-
The `fn init` command creates an simple function with a bit of boilerplate to get you
42+
The `fn init` command creates a simple function with a bit of boilerplate to get you
4343
started. The `--runtime` option is used to indicate that the function
4444
we're going to develop will be written in C# and will work on dotnet core 3.1,
4545
the default version as of this writing.
@@ -332,8 +332,8 @@ namespace Function.Tests {
332332
```
333333
334334
You can run the tests by building your function with `fn build`. This
335-
will cause Dotnet to add both Source and Test project to `Function.sln`.
336-
The code will be build and tests will be run on creating a new function.
335+
will cause Dotnet to add both Source and Test projects to `Function.sln`.
336+
The code will be built and tests will be run on creating a new function.
337337
338338
![](images/userinput.png)
339339
>`fn build`
@@ -350,45 +350,66 @@ Replace the definition of `HelloFunction` with the following:
350350
351351
```csharp
352352
using Fnproject.Fn.Fdk;
353+
using System;
353354
354355
using System.Runtime.CompilerServices;
355-
[assembly:InternalsVisibleTo("Function.Tests")]
356-
namespace Function {
357-
class Input {
358-
public string name;
359-
}
360-
361-
class Greeter {
362-
public string greet(Input input) {
363-
return string.Format("Hello {0}!",
364-
input.name.Length == 0 ? "World" : input.name.Trim());
365-
}
366-
367-
static void Main(string[] args) { Fdk.Handle(args[0]); }
368-
}
356+
[assembly:InternalsVisibleTo("Function.Tests")] namespace Function {
357+
class Input {
358+
public string name {
359+
get;
360+
set;
361+
}
362+
}
363+
364+
class Greeter {
365+
public string greet(Input input) {
366+
return string.Format("Hello {0}!", string.IsNullOrEmpty(input.name)
367+
? "World"
368+
: input.name.Trim());
369+
}
370+
371+
static void Main(string[] args) { Fdk.Handle(args[0]); }
372+
}
369373
}
370374
```
371375
372-
Since we modified the `Program.cs` and changes the function format, we need to modify the `ProgramTest.cs` class.
376+
Since we modified the `Program.cs` and changed the function format, we need to modify the `ProgramTest.cs` class.
373377
374378
```csharp
375379
using Function;
376380
using NUnit.Framework;
377381
378382
namespace Function.Tests {
379-
public class GreeterTest {
380-
[Test]
381-
public void TestGreetEmpty() {
382-
Greeter greeter = new Greeter();
383-
Input input = new Input();
383+
public class GreeterTest {
384+
[Test]
385+
public void TestGreetEmpty() {
386+
Greeter greeter = new Greeter();
387+
Input input = new Input();
388+
string response = greeter.greet(input);
389+
Assert.AreEqual("Hello World!", response);
390+
}
391+
392+
[Test]
393+
public void TestGreetValid() {
394+
Greeter greeter = new Greeter();
395+
Input input = new Input();
384396
input.name = "Dotnet";
385-
string response = greeter.greet(input);
386-
Assert.AreEqual("Hello Dotnet!", response);
387-
}
388-
}
397+
string response = greeter.greet(input);
398+
Assert.AreEqual("Hello Dotnet!", response);
399+
}
400+
}
389401
}
390402
```
391403
404+
![user input](images/userinput.png)
405+
>```sh
406+
> echo '{"name":"Dotnet"}' | fn invoke dotnet-app dotnetfn
407+
>```
408+
409+
```sh
410+
Hello Dotnet!
411+
```
412+
392413
## Invoke with Curl
393414
394415
The other way to invoke your function is via HTTP. With the changes to the code,

0 commit comments

Comments
 (0)