parent
f29bb823b5
commit
16059ff5d0
@ -0,0 +1,64 @@ |
|||||||
|
using System.Collections.Generic; |
||||||
|
using espacecollab.backend.api.Controllers; |
||||||
|
using espacecollab.backend.appservices.dtos.Interfaces; |
||||||
|
using FluentAssertions; |
||||||
|
using Microsoft.AspNetCore.Mvc; |
||||||
|
using Xunit; |
||||||
|
|
||||||
|
namespace espacecollab.backend.api.tests; |
||||||
|
|
||||||
|
public abstract class BaseControllerTest<T, TO> where T : IBaseController<TO> |
||||||
|
where TO : class, IGenericIdApiDto |
||||||
|
{ |
||||||
|
protected T Controller { get; set; } |
||||||
|
protected TO NewApiDo { get; set; } |
||||||
|
protected TO UpdateApiDo { get; set; } |
||||||
|
|
||||||
|
[Fact] |
||||||
|
public void GetAllTest() |
||||||
|
{ |
||||||
|
ActionResult<IEnumerable<TO>> actionResult = Controller.GetAll(); |
||||||
|
|
||||||
|
OkObjectResult result = actionResult.Result.Should().BeOfType<OkObjectResult>().Subject; |
||||||
|
result.Value.Should().BeOfType<List<TO>>(); |
||||||
|
} |
||||||
|
|
||||||
|
[Fact] |
||||||
|
public void GetByIdTest() |
||||||
|
{ |
||||||
|
uint id = 1; |
||||||
|
|
||||||
|
ActionResult<TO> actionResult = Controller.GetById(id); |
||||||
|
|
||||||
|
OkObjectResult result = actionResult.Result.Should().BeOfType<OkObjectResult>().Subject; |
||||||
|
result.Value.Should().BeOfType<TO>(); |
||||||
|
} |
||||||
|
|
||||||
|
[Fact] |
||||||
|
public void AddTest() |
||||||
|
{ |
||||||
|
ActionResult<TO> actionResult = Controller.Add(NewApiDo); |
||||||
|
|
||||||
|
OkObjectResult result = actionResult.Result.Should().BeOfType<OkObjectResult>().Subject; |
||||||
|
result.Value.Should().BeOfType<TO>().Subject.Id.Should().NotBe(0); |
||||||
|
} |
||||||
|
|
||||||
|
[Fact] |
||||||
|
public void DeleteTest() |
||||||
|
{ |
||||||
|
uint id = 1; |
||||||
|
|
||||||
|
ActionResult<TO> actionResult = Controller.Delete(id); |
||||||
|
|
||||||
|
actionResult.Result.Should().BeOfType<OkResult>(); |
||||||
|
} |
||||||
|
|
||||||
|
[Fact] |
||||||
|
public void UpdateTest() |
||||||
|
{ |
||||||
|
ActionResult<TO> actionResult = Controller.Update(UpdateApiDo.Id, UpdateApiDo); |
||||||
|
|
||||||
|
OkObjectResult result = actionResult.Result.Should().BeOfType<OkObjectResult>().Subject; |
||||||
|
result.Value.Should().BeOfType<TO>().Subject.Id.Should().Be(UpdateApiDo.Id); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,28 @@ |
|||||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||||
|
|
||||||
|
<PropertyGroup> |
||||||
|
<TargetFramework>net6.0</TargetFramework> |
||||||
|
<Nullable>enable</Nullable> |
||||||
|
|
||||||
|
<IsPackable>false</IsPackable> |
||||||
|
</PropertyGroup> |
||||||
|
|
||||||
|
<ItemGroup> |
||||||
|
<PackageReference Include="FluentAssertions" Version="6.3.0" /> |
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /> |
||||||
|
<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.0"> |
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> |
||||||
|
<PrivateAssets>all</PrivateAssets> |
||||||
|
</PackageReference> |
||||||
|
</ItemGroup> |
||||||
|
|
||||||
|
<ItemGroup> |
||||||
|
<ProjectReference Include="..\espacecollab.backend.api\espacecollab.backend.api.csproj" /> |
||||||
|
</ItemGroup> |
||||||
|
|
||||||
|
</Project> |
Loading…
Reference in new issue