-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathCarServiceTests.cs
50 lines (41 loc) · 1.59 KB
/
CarServiceTests.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
47
48
49
50
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoFixture;
using AutoFixture.Xunit2;
using FluentAssertions;
using HappyCode.NetCoreBoilerplate.Core.Models;
using HappyCode.NetCoreBoilerplate.Core.Services;
using HappyCode.NetCoreBoilerplate.Core.UnitTests.Extensions;
using Microsoft.EntityFrameworkCore;
using Moq;
using Xunit;
namespace HappyCode.NetCoreBoilerplate.Core.UnitTests.Services
{
public class CarServiceTests
{
private static readonly Fixture _fixture = new Fixture();
private readonly CarService _service;
private readonly Mock<CarsContext> _dbContextMock;
public CarServiceTests()
{
_dbContextMock = new Mock<CarsContext>(new DbContextOptionsBuilder<CarsContext>().Options);
_service = new CarService(_dbContextMock.Object);
}
[Theory, AutoData]
public async Task GetAllSortedByPlateAsync_should_return_expected_result(int rand1, int rand2, int expectedId)
{
//given
_fixture.Customize<Car>(c => c.Without(x => x.Owner));
var cars = new List<Car>();
_fixture.AddManyTo(cars, rand1);
cars.Add(new Car { Id = expectedId, Plate = "0" });
_fixture.AddManyTo(cars, rand2);
_dbContextMock.Setup(x => x.Cars).Returns(cars.GetMockDbSetObject());
//when
var result = await _service.GetAllSortedByPlateAsync(default);
//then
result.First().Id.Should().Be(expectedId);
}
}
}