envoie de ce que j'ai fait (les tests)
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
70f7d6d316
commit
e1518a8e17
@ -0,0 +1,152 @@
|
||||
using DbConnectionLibrairie;
|
||||
using Entities;
|
||||
using EntityManagers;
|
||||
using static System.Net.WebRequestMethods;
|
||||
using Xunit.Abstractions;
|
||||
using System.Text.Json;
|
||||
using System.Net.Http.Json;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace UnitTestsEntityManagers
|
||||
{
|
||||
|
||||
public class UnitTestAnswerManager : AbstractUnitTestEM
|
||||
{
|
||||
IEnumerable<AnswerEntity> answers = JsonConvert
|
||||
.DeserializeObject<IEnumerable<AnswerEntity>>
|
||||
("../FakeDatas/fake-Answer.json")!; // if this is null, we don't want to continue
|
||||
|
||||
AnswerEntityManager mgr;
|
||||
public UnitTestAnswerManager()
|
||||
: base()
|
||||
{
|
||||
mgr = new AnswerEntityManager(dbContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// test of the 'ajouterAnswer' method of an AnswerManager
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TestAjouterAnswer()
|
||||
{
|
||||
var answerToAdd = new AnswerEntity { Id = -1, Content = "châteîgne" };
|
||||
var a = mgr.ajouterAnswer(answerToAdd);
|
||||
// 1) with an id less than 0
|
||||
// WF : it works so 'a' is not null,
|
||||
// his content is equal to the
|
||||
// content of 'answerToAdd'
|
||||
// and since it's the first answer
|
||||
// that we add, his id equal 0
|
||||
Assert.NotNull(a);
|
||||
Assert.Equal(answerToAdd.Content, a.Content);
|
||||
Assert.NotEqual(0, a.Id);
|
||||
|
||||
answerToAdd = new AnswerEntity { Id = 5, Content = "damien" };
|
||||
a = mgr.ajouterAnswer(answerToAdd);
|
||||
// 2) with a random id greater than 0
|
||||
// WF : it works so 'a' is not null,
|
||||
// his content is equal to the
|
||||
// content of 'answerToAdd'
|
||||
// and since it's the second answer
|
||||
// that we add, his id equal 1
|
||||
Assert.NotNull(a);
|
||||
Assert.Equal(answerToAdd.Content, a.Content);
|
||||
Assert.NotEqual(1, a.Id);
|
||||
|
||||
answerToAdd = new AnswerEntity { Id = 7, Content = "châteîgne" };
|
||||
a = mgr.ajouterAnswer(answerToAdd);
|
||||
// 3) with a content that we already have added
|
||||
// WF : it don't works so 'a' is null
|
||||
Assert.Null(a);
|
||||
|
||||
answerToAdd = new AnswerEntity { Id = 7, Content = "CHÂTEÎGNE" };
|
||||
a = mgr.ajouterAnswer(answerToAdd);
|
||||
// 3) with a content that we already have added
|
||||
// but in upperCase instead of lowerCase
|
||||
// WF : it don't works so 'a' is null
|
||||
Assert.Null(a);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// test of the 'supprimerAnswer' method of an AnswerManager
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TestSupprimerAnswer()
|
||||
{
|
||||
// remember that we have only 2 answers in the database :
|
||||
// 1) (0, "châteigne")
|
||||
// 2) (1, "damien")
|
||||
var a = mgr.supprimerAnswer(-3);
|
||||
// 1) with an id less than 0
|
||||
// WF : it don't work because there's no
|
||||
// negative id so 'a' is null
|
||||
Assert.Null(a);
|
||||
|
||||
a = mgr.supprimerAnswer(3);
|
||||
// 2) with an id greater or equal
|
||||
// to the number of element
|
||||
// WF : it don't works so 'a' is null,
|
||||
Assert.Null(a);
|
||||
|
||||
a = mgr.supprimerAnswer(0);
|
||||
// 1) with an id that belongs to an answer
|
||||
// WF : it works so 'a' is not null,
|
||||
// and since we've delete the answer with
|
||||
// the id 0, the content is "châteigne"
|
||||
Assert.NotNull(a);
|
||||
Assert.Equal(0, a.Id);
|
||||
Assert.Equal("châteigne", a.Content);
|
||||
|
||||
a = mgr.supprimerAnswer(0);
|
||||
// 1) same thing with the id 1 just
|
||||
// for cleaning the database
|
||||
// WF : it works so 'a' is not null,
|
||||
// and since we've delete the answer with
|
||||
// the id 1, the content is "damien"
|
||||
Assert.NotNull(a);
|
||||
Assert.Equal(0, a.Id);
|
||||
Assert.Equal("damien", a.Content);
|
||||
|
||||
// now, the database should be clean
|
||||
}
|
||||
|
||||
// /!\ WARNING : since there was 2 answers added to the base,
|
||||
// id index while now start at 2 (even though we've delete those)
|
||||
|
||||
/// <summary>
|
||||
/// test of the 'getNbElement' method of an AnswerManager
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TestGetNbElement()
|
||||
{
|
||||
Assert.Equal(0, mgr.getNbElement()); // just to be sure
|
||||
|
||||
Assert.NotNull(answers); // just to be sure
|
||||
|
||||
int count = 0;
|
||||
foreach (var answer in answers)
|
||||
{
|
||||
mgr.ajouterAnswer(answer);
|
||||
count++;
|
||||
Assert.Equal(count, mgr.getNbElement());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void testGetAnswer()
|
||||
{
|
||||
// with an id which correspond of
|
||||
// an answer which is in the database
|
||||
foreach (var a in answers)
|
||||
{
|
||||
var tmp = mgr.getAnswer(a.Id+2);
|
||||
Assert.NotNull(tmp);
|
||||
Assert.Equal(a.Content, tmp.Content);
|
||||
Assert.Equal(a.Id, tmp.Id);
|
||||
}
|
||||
}
|
||||
// getAnswers
|
||||
|
||||
// modifierAnswer
|
||||
}
|
||||
}
|
@ -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="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="xunit" Version="2.5.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DbConnectionLibrairie\DbConnectionLibrairie.csproj" />
|
||||
<ProjectReference Include="..\Entities\Entities.csproj" />
|
||||
<ProjectReference Include="..\EntityManagers\EntityManagers.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,33 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace WebApplication.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries = new[]
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
|
||||
private readonly ILogger<WeatherForecastController> _logger;
|
||||
|
||||
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet(Name = "GetWeatherForecast")]
|
||||
public IEnumerable<WeatherForecast> Get()
|
||||
{
|
||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
@ -1,13 +0,0 @@
|
||||
namespace WebApplication
|
||||
{
|
||||
public class WeatherForecast
|
||||
{
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
|
||||
public string? Summary { get; set; }
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,6 +0,0 @@
|
||||
@WebApplication_HostAddress = http://localhost:5228
|
||||
|
||||
GET {{WebApplication_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
@ -1,8 +0,0 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
Loading…
Reference in new issue