-
-
Notifications
You must be signed in to change notification settings - Fork 96
/
CarsControllerTests.cs
46 lines (40 loc) · 1.5 KB
/
CarsControllerTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AutoFixture.Xunit2;
using FluentAssertions;
using HappyCode.NetCoreBoilerplate.Api.Controllers;
using HappyCode.NetCoreBoilerplate.Core.Dtos;
using HappyCode.NetCoreBoilerplate.Core.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Moq;
using Xunit;
namespace HappyCode.NetCoreBoilerplate.Api.UnitTests.Controllers
{
public class CarsControllerTests : ControllerTestsBase<CarsController>
{
private readonly Mock<ICarService> _carServiceMock;
public CarsControllerTests()
{
_carServiceMock = Mocker.GetMock<ICarService>();
}
[Theory, AutoData]
public async Task GetAll_should_return_Ok_with_expected_result(IEnumerable<CarDto> cars)
{
//given
_carServiceMock.Setup(x => x.GetAllSortedByPlateAsync(It.IsAny<CancellationToken>()))
.ReturnsAsync(cars);
//when
var result = await Controller.GetAllAsync(default) as OkObjectResult;
//then
result.Should().NotBeNull();
result.StatusCode.Should().Be(StatusCodes.Status200OK);
result.Value.Should().BeAssignableTo<IEnumerable<CarDto>>();
var value = result.Value as IEnumerable<CarDto>;
value.Should().HaveCount(cars.Count());
_carServiceMock.VerifyAll();
}
}
}