From 34a68d5f4860e1e5767839695e45f1eeda4c9f2d Mon Sep 17 00:00:00 2001
From: Isaac Levin <8878502+isaac2004@users.noreply.github.com>
Date: Mon, 3 Jun 2019 13:18:32 -0400
Subject: [PATCH] #10333 Template Updates (#10395)
#10333 Template Updates
---
.../WebApi-FSharp.fsproj.in | 2 +-
.../Controllers/ValuesController.cs | 60 -------------------
.../Controllers/WeatherController.cs | 44 ++++++++++++++
.../Controllers/ValuesController.fs | 34 -----------
.../Controllers/WeatherController.fs | 32 ++++++++++
.../test/WebApiTemplateTest.cs | 4 +-
.../test/template-baselines.json | 10 ++--
7 files changed, 84 insertions(+), 102 deletions(-)
delete mode 100644 src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/ValuesController.cs
create mode 100644 src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/WeatherController.cs
delete mode 100644 src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/ValuesController.fs
create mode 100644 src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/WeatherController.fs
diff --git a/src/ProjectTemplates/Web.ProjectTemplates/WebApi-FSharp.fsproj.in b/src/ProjectTemplates/Web.ProjectTemplates/WebApi-FSharp.fsproj.in
index 36af1dc9f5..c6017dc6c8 100644
--- a/src/ProjectTemplates/Web.ProjectTemplates/WebApi-FSharp.fsproj.in
+++ b/src/ProjectTemplates/Web.ProjectTemplates/WebApi-FSharp.fsproj.in
@@ -7,7 +7,7 @@
-
+
diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/ValuesController.cs b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/ValuesController.cs
deleted file mode 100644
index 55a45bf67f..0000000000
--- a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/ValuesController.cs
+++ /dev/null
@@ -1,60 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-#if (!NoAuth)
-using Microsoft.AspNetCore.Authorization;
-#endif
-using Microsoft.AspNetCore.Mvc;
-
-namespace Company.WebApplication1.Controllers
-{
-#if (!NoAuth)
- [Authorize]
-#endif
- [Route("api/[controller]")]
- [ApiController]
- public class ValuesController : ControllerBase
- {
- // GET api/values
- [HttpGet]
- public ActionResult> Get()
- {
- return new string[] { "value1", "value2" };
- }
-
- // GET api/values/5
- [HttpGet("{id}")]
- public ActionResult Get(int id)
- {
- return "value";
- }
-
- // POST api/values
- [HttpPost]
- public void Post([FromBody] string value)
- {
-#if (OrganizationalAuth || WindowsAuth)
- // For more information on protecting this API from Cross Site Request Forgery (CSRF) attacks, see https://go.microsoft.com/fwlink/?LinkID=717803
-#endif
- }
-
- // PUT api/values/5
- [HttpPut("{id}")]
- public void Put(int id, [FromBody] string value)
- {
-#if (OrganizationalAuth || WindowsAuth)
- // For more information on protecting this API from Cross Site Request Forgery (CSRF) attacks, see https://go.microsoft.com/fwlink/?LinkID=717803
-#endif
- }
-
- // DELETE api/values/5
- [HttpDelete("{id}")]
- public void Delete(int id)
- {
-#if (OrganizationalAuth || WindowsAuth)
- // For more information on protecting this API from Cross Site Request Forgery (CSRF) attacks, see https://go.microsoft.com/fwlink/?LinkID=717803
-#endif
- }
- }
-}
diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/WeatherController.cs b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/WeatherController.cs
new file mode 100644
index 0000000000..f562613ea4
--- /dev/null
+++ b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/WeatherController.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+#if (!NoAuth)
+using Microsoft.AspNetCore.Authorization;
+#endif
+using Microsoft.AspNetCore.Mvc;
+
+namespace Company.WebApplication1.Controllers
+{
+#if (!NoAuth)
+ [Authorize]
+#endif
+
+ [Route("api/SampleData/[controller]")]
+ [ApiController]
+ public class WeatherController : ControllerBase
+ {
+ [HttpGet]
+ public ActionResult GetWeatherForecasts(string location, TemperatureUnit unit)
+ {
+ var rng = new Random();
+ return new WeatherResult
+ {
+ Location = location,
+ Temperature = rng.Next(-20, 55),
+ TemperatureUnit = unit
+ };
+ }
+ }
+
+ public enum TemperatureUnit
+ {
+ Celsius,
+ Fahrenheit
+ }
+ public class WeatherResult
+ {
+ public int Temperature { get; set; }
+ public TemperatureUnit TemperatureUnit { get; set; }
+ public string Location { get; set; }
+ }
+}
diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/ValuesController.fs b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/ValuesController.fs
deleted file mode 100644
index c77d5d4b79..0000000000
--- a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/ValuesController.fs
+++ /dev/null
@@ -1,34 +0,0 @@
-namespace Company.WebApplication1.Controllers
-
-open System
-open System.Collections.Generic
-open System.Linq
-open System.Threading.Tasks
-open Microsoft.AspNetCore.Mvc
-
-[]
-[]
-type ValuesController () =
- inherit ControllerBase()
-
- []
- member this.Get() =
- let values = [|"value1"; "value2"|]
- ActionResult(values)
-
- []
- member this.Get(id:int) =
- let value = "value"
- ActionResult(value)
-
- []
- member this.Post([] value:string) =
- ()
-
- []
- member this.Put(id:int, [] value:string ) =
- ()
-
- []
- member this.Delete(id:int) =
- ()
diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/WeatherController.fs b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/WeatherController.fs
new file mode 100644
index 0000000000..29ac8c9365
--- /dev/null
+++ b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-FSharp/Controllers/WeatherController.fs
@@ -0,0 +1,32 @@
+namespace WebApplication1.Controllers
+
+open System
+open System.Collections.Generic
+open System.Linq
+open System.Threading.Tasks
+open Microsoft.AspNetCore.Mvc
+
+type public TemperatureUnit =
+ | Celsius=0
+ | Fahrenheit=1
+
+type WeatherResult = {
+ Location: string
+ TemperatureUnit: TemperatureUnit
+ Temperature: int
+}
+
+[]
+[]
+type WeatherController () =
+ inherit ControllerBase()
+
+ []
+ member this.Get(location:string, unit: TemperatureUnit) =
+ let rnd = System.Random()
+ let result:WeatherResult = {
+ Location = location;
+ Temperature = rnd.Next(-20,55);
+ TemperatureUnit = unit
+ }
+ ActionResult(result)
diff --git a/src/ProjectTemplates/test/WebApiTemplateTest.cs b/src/ProjectTemplates/test/WebApiTemplateTest.cs
index 3069e84d2c..5f21ac7b2c 100644
--- a/src/ProjectTemplates/test/WebApiTemplateTest.cs
+++ b/src/ProjectTemplates/test/WebApiTemplateTest.cs
@@ -48,7 +48,7 @@ namespace Templates.Test
aspNetProcess.Process.HasExited,
ErrorMessages.GetFailedProcessMessageOrEmpty("Run built project", Project, aspNetProcess.Process));
- await aspNetProcess.AssertOk("/api/values");
+ await aspNetProcess.AssertOk("/api/SampleData/Weather");
await aspNetProcess.AssertNotFound("/");
}
@@ -59,7 +59,7 @@ namespace Templates.Test
ErrorMessages.GetFailedProcessMessageOrEmpty("Run published project", Project, aspNetProcess.Process));
- await aspNetProcess.AssertOk("/api/values");
+ await aspNetProcess.AssertOk("/api/SampleData/Weather");
await aspNetProcess.AssertNotFound("/");
}
}
diff --git a/src/ProjectTemplates/test/template-baselines.json b/src/ProjectTemplates/test/template-baselines.json
index 279d5a6852..a6e919620c 100644
--- a/src/ProjectTemplates/test/template-baselines.json
+++ b/src/ProjectTemplates/test/template-baselines.json
@@ -404,7 +404,7 @@
"appsettings.json",
"Program.cs",
"Startup.cs",
- "Controllers/ValuesController.cs",
+ "Controllers/WeatherController.cs",
"Properties/launchSettings.json"
],
"AuthOption": "IndividualB2C"
@@ -417,7 +417,7 @@
"appsettings.json",
"Program.cs",
"Startup.cs",
- "Controllers/ValuesController.cs",
+ "Controllers/WeatherController.cs",
"Properties/launchSettings.json"
],
"AuthOption": "SingleOrg"
@@ -430,7 +430,7 @@
"appsettings.json",
"Program.cs",
"Startup.cs",
- "Controllers/ValuesController.cs",
+ "Controllers/WeatherController.cs",
"Properties/launchSettings.json"
],
"AuthOption": "None"
@@ -443,7 +443,7 @@
"appsettings.json",
"Program.cs",
"Startup.cs",
- "Controllers/ValuesController.cs",
+ "Controllers/WeatherController.cs",
"Properties/launchSettings.json"
],
"AuthOption": "Windows"
@@ -456,7 +456,7 @@
"appsettings.json",
"Program.fs",
"Startup.fs",
- "Controllers/ValuesController.fs",
+ "Controllers/WeatherController.fs",
"Properties/launchSettings.json"
]
}