#10333 Template Updates (#10395)

#10333 Template Updates
This commit is contained in:
Isaac Levin 2019-06-03 13:18:32 -04:00 committed by Ryan Brandenburg
parent d001f5c519
commit 34a68d5f48
7 changed files with 84 additions and 102 deletions

View File

@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Controllers/ValuesController.fs" />
<Compile Include="Controllers/WeatherController.fs" />
<Compile Include="Startup.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

View File

@ -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<IEnumerable<string>> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
[HttpGet("{id}")]
public ActionResult<string> 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
}
}
}

View File

@ -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<WeatherResult> 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; }
}
}

View File

@ -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
[<Route("api/[controller]")>]
[<ApiController>]
type ValuesController () =
inherit ControllerBase()
[<HttpGet>]
member this.Get() =
let values = [|"value1"; "value2"|]
ActionResult<string[]>(values)
[<HttpGet("{id}")>]
member this.Get(id:int) =
let value = "value"
ActionResult<string>(value)
[<HttpPost>]
member this.Post([<FromBody>] value:string) =
()
[<HttpPut("{id}")>]
member this.Put(id:int, [<FromBody>] value:string ) =
()
[<HttpDelete("{id}")>]
member this.Delete(id:int) =
()

View File

@ -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
}
[<Route("api/SampleData/[controller]")>]
[<ApiController>]
type WeatherController () =
inherit ControllerBase()
[<HttpGet>]
member this.Get(location:string, unit: TemperatureUnit) =
let rnd = System.Random()
let result:WeatherResult = {
Location = location;
Temperature = rnd.Next(-20,55);
TemperatureUnit = unit
}
ActionResult<WeatherResult>(result)

View File

@ -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("/");
}
}

View File

@ -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"
]
}