Skip to content
This repository was archived by the owner on Oct 2, 2022. It is now read-only.

Commit 24cd18e

Browse files
committed
init project
0 parents  commit 24cd18e

12 files changed

+691
-0
lines changed

.gitignore

+454
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
13+
<PackageReference Include="Moq" Version="4.18.2" />
14+
<PackageReference Include="NUnit" Version="3.13.3" />
15+
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
16+
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
17+
<PackageReference Include="coverlet.collector" Version="3.1.2" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<ProjectReference Include="..\MyWeatherApi\MyWeatherApi.csproj" />
22+
</ItemGroup>
23+
24+
</Project>

MyWeatherApi.Tests/Usings.cs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
global using NUnit.Framework;
2+
global using Moq;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Microsoft.Extensions.Logging;
2+
using MyWeatherApi.Controllers;
3+
4+
namespace MyWeatherApi.Tests;
5+
6+
public class Tests
7+
{
8+
private WeatherForecastController myController;
9+
private ILogger<WeatherForecastController> _logger;
10+
11+
[SetUp]
12+
public void Setup()
13+
{
14+
this._logger = Mock.Of<ILogger<WeatherForecastController>>();
15+
this.myController = new WeatherForecastController(_logger);
16+
}
17+
18+
[Test]
19+
public void WeatherForecast_Get_Should_Return_Data()
20+
{
21+
Assert.IsNotNull(this.myController.Get());
22+
}
23+
24+
[Test]
25+
public void WeatherForecast_Get_By_ZipCode_Given_NoArgument_Throw_ArgumentException()
26+
{
27+
Assert.Throws<ArgumentNullException>(() => this.myController.GetByZipCode(null));
28+
}
29+
30+
[Test]
31+
public void WeatherForecast_Get_By_ZipCode_Given_ZipCode_Return_Data()
32+
{
33+
Assert.IsInstanceOf(typeof(WeatherForecast),this.myController.GetByZipCode("92220"));
34+
}
35+
}

MyWeatherApi.sln

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyWeatherApi", "MyWeatherApi\MyWeatherApi.csproj", "{8B532B01-CB1E-4D42-B1C5-269E8D24C3BB}"
4+
EndProject
5+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F0225315-811B-4FB6-8915-31D418C4F20C}"
6+
EndProject
7+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{6DA5D4F2-D632-4ACE-8980-A1EE0E7B95BC}"
8+
EndProject
9+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyWeatherApi.Tests", "MyWeatherApi.Tests\MyWeatherApi.Tests.csproj", "{A219582F-904E-4A6D-A2D6-AF71E45D5FCE}"
10+
EndProject
11+
Global
12+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
13+
Debug|Any CPU = Debug|Any CPU
14+
Release|Any CPU = Release|Any CPU
15+
EndGlobalSection
16+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
17+
{8B532B01-CB1E-4D42-B1C5-269E8D24C3BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18+
{8B532B01-CB1E-4D42-B1C5-269E8D24C3BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
19+
{8B532B01-CB1E-4D42-B1C5-269E8D24C3BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{8B532B01-CB1E-4D42-B1C5-269E8D24C3BB}.Release|Any CPU.Build.0 = Release|Any CPU
21+
{A219582F-904E-4A6D-A2D6-AF71E45D5FCE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{A219582F-904E-4A6D-A2D6-AF71E45D5FCE}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{A219582F-904E-4A6D-A2D6-AF71E45D5FCE}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{A219582F-904E-4A6D-A2D6-AF71E45D5FCE}.Release|Any CPU.Build.0 = Release|Any CPU
25+
EndGlobalSection
26+
GlobalSection(NestedProjects) = preSolution
27+
{8B532B01-CB1E-4D42-B1C5-269E8D24C3BB} = {F0225315-811B-4FB6-8915-31D418C4F20C}
28+
{A219582F-904E-4A6D-A2D6-AF71E45D5FCE} = {6DA5D4F2-D632-4ACE-8980-A1EE0E7B95BC}
29+
EndGlobalSection
30+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace MyWeatherApi.Controllers;
4+
5+
[ApiController]
6+
[Route("[controller]")]
7+
public class WeatherForecastController : ControllerBase
8+
{
9+
private static readonly string[] Summaries = new[]
10+
{
11+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
12+
};
13+
14+
private readonly ILogger<WeatherForecastController> _logger;
15+
16+
public WeatherForecastController(ILogger<WeatherForecastController> logger)
17+
{
18+
_logger = logger;
19+
}
20+
21+
[HttpGet(Name = "GetWeatherForecast")]
22+
public IEnumerable<WeatherForecast> Get()
23+
{
24+
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
25+
{
26+
Date = DateTime.Now.AddDays(index),
27+
TemperatureC = Random.Shared.Next(-20, 55),
28+
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
29+
})
30+
.ToArray();
31+
}
32+
33+
[HttpGet(Name = "GetWeatherForecastByZipCode")]
34+
public WeatherForecast GetByZipCode([FromQuery] string zipCode)
35+
{
36+
if (zipCode == null)
37+
{
38+
throw new ArgumentNullException(zipCode, "Zip code shouldn't Be null");
39+
}
40+
41+
return new WeatherForecast
42+
{
43+
Date = DateTime.Now,
44+
TemperatureC = Random.Shared.Next(-20, 55),
45+
Summary = Summaries[0]
46+
};
47+
}
48+
}

MyWeatherApi/MyWeatherApi.csproj

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3"/>
11+
</ItemGroup>
12+
13+
</Project>

MyWeatherApi/Program.cs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
// Add services to the container.
4+
5+
builder.Services.AddControllers();
6+
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
7+
builder.Services.AddEndpointsApiExplorer();
8+
builder.Services.AddSwaggerGen();
9+
10+
var app = builder.Build();
11+
12+
// Configure the HTTP request pipeline.
13+
if (app.Environment.IsDevelopment())
14+
{
15+
app.UseSwagger();
16+
app.UseSwaggerUI();
17+
}
18+
19+
app.UseHttpsRedirection();
20+
21+
app.UseAuthorization();
22+
23+
app.MapControllers();
24+
25+
app.Run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:12220",
8+
"sslPort": 44317
9+
}
10+
},
11+
"profiles": {
12+
"MyWeatherApi": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"launchUrl": "swagger",
17+
"applicationUrl": "https://localhost:7052;http://localhost:5052",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
},
22+
"IIS Express": {
23+
"commandName": "IISExpress",
24+
"launchBrowser": true,
25+
"launchUrl": "swagger",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
}
30+
}
31+
}

MyWeatherApi/WeatherForecast.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace MyWeatherApi;
2+
3+
public class WeatherForecast
4+
{
5+
public DateTime Date { get; set; }
6+
7+
public int TemperatureC { get; set; }
8+
9+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
10+
11+
public string? Summary { get; set; }
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}

MyWeatherApi/appsettings.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}

0 commit comments

Comments
 (0)