Merge pull request 'ManageUnitTest' (#2) from ManageUnitTest into main
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
Reviewed-on: #2pull/7/head
commit
536880d9bb
@ -0,0 +1,30 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
|
||||||
|
<PackageReference Include="Moq" Version="4.18.4" />
|
||||||
|
<PackageReference Include="xunit" Version="2.4.1" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\BowlingApi\BowlingApi.csproj" />
|
||||||
|
<ProjectReference Include="..\..\BowlingService\BowlingService.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,64 @@
|
|||||||
|
using DTOs;
|
||||||
|
|
||||||
|
namespace BowlingAPITest;
|
||||||
|
|
||||||
|
public class TestController
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public async void Get_ShouldReturnOkResult()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var mockService = new Mock<IJoueurService>();
|
||||||
|
mockService.Setup(service => service.GetAll()).ReturnsAsync(new List<JoueurDTO>());
|
||||||
|
var controller = new JoueurController(mockService.Object);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await controller.Get();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.IsType<OkObjectResult>(result);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void Get_ShouldReturnAllItems()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var testItems = GetTestItems();
|
||||||
|
var mockService = new Mock<IJoueurService>();
|
||||||
|
mockService.Setup(service => service.GetAll()).ReturnsAsync(testItems);
|
||||||
|
var controller = new JoueurController(mockService.Object);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = await controller.Get();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var okResult = result as OkObjectResult;
|
||||||
|
var items = Assert.IsType<List<JoueurDTO>>(okResult.Value);
|
||||||
|
Assert.Equal(2, items.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<JoueurDTO> GetTestItems()
|
||||||
|
{
|
||||||
|
|
||||||
|
var testItems = new List<JoueurDTO>();
|
||||||
|
testItems.Add(new JoueurDTO {Pseudo = "Item1" });
|
||||||
|
testItems.Add(new JoueurDTO { Pseudo = "Item2" });
|
||||||
|
return testItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async void GetById_ShouldReturnNotFound()
|
||||||
|
// {
|
||||||
|
// // Arrange
|
||||||
|
// var mockService = new Mock<IJoueurService>();
|
||||||
|
// mockService.Setup(service => service.Get(1)).ReturnsAsync((JoueurDTO)null);
|
||||||
|
// var controller = new JoueurController(mockService.Object);
|
||||||
|
//
|
||||||
|
// // Act
|
||||||
|
// var result = await controller.Get(1);
|
||||||
|
//
|
||||||
|
// // Assert
|
||||||
|
// Assert.IsType<NotFoundResult>(result);
|
||||||
|
// }
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
global using Xunit;
|
||||||
|
global using BowlingApi.Controllers;
|
||||||
|
global using BowlingEF.Entities;
|
||||||
|
global using BowlingService.Interfaces;
|
||||||
|
global using Microsoft.AspNetCore.Mvc;
|
||||||
|
global using Moq;
|
Loading…
Reference in new issue