parent
41327233e9
commit
35061e7c24
@ -0,0 +1,29 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
<IsTestProject>true</IsTestProject>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||||
|
<PackageReference Include="xunit" Version="2.4.2" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="6.0.0">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\API_Rest\API_Rest.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1 @@
|
|||||||
|
global using Xunit;
|
@ -0,0 +1,43 @@
|
|||||||
|
using API_Rest;
|
||||||
|
using API_Rest.Controllers;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
|
||||||
|
namespace API_UnitTest
|
||||||
|
{
|
||||||
|
public class UnitTest
|
||||||
|
{
|
||||||
|
public ILogger<WeatherForecastController> logger { get; set; }
|
||||||
|
public WeatherForecastService wfs = new WeatherForecastService();
|
||||||
|
public WeatherForecastController wfc;
|
||||||
|
|
||||||
|
|
||||||
|
public UnitTest() {
|
||||||
|
wfc = new WeatherForecastController(logger, wfs);
|
||||||
|
}
|
||||||
|
[Fact]
|
||||||
|
public void GetAll()
|
||||||
|
{
|
||||||
|
var res = wfc.GetAll();
|
||||||
|
Assert.NotNull(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetOne()
|
||||||
|
{
|
||||||
|
var res = wfc.GetOne(1);
|
||||||
|
Assert.NotNull(res.Result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void Post()
|
||||||
|
{
|
||||||
|
WeatherForecast wf = new WeatherForecast();
|
||||||
|
wf.Id = 4;
|
||||||
|
wf.Date = DateOnly.FromDateTime(DateTime.Today);
|
||||||
|
wf.TemperatureC = 5;
|
||||||
|
await wfc.Post(wf);
|
||||||
|
Assert.Contains(wf,wfs.Weathers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue