forked from equinor/flotilla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMissionService.cs
71 lines (64 loc) · 2.72 KB
/
MissionService.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Threading.Tasks;
using Api.Controllers.Models;
using Api.Database.Context;
using Api.Database.Models;
using Api.Services;
using Api.Test.Database;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Moq;
using Xunit;
namespace Api.Test.Services
{
[Collection("Database collection")]
public class MissionServiceTest : IDisposable
{
private readonly FlotillaDbContext _context;
private readonly DatabaseUtilities _databaseUtilities;
private readonly ILogger<MissionRunService> _logger;
private readonly MissionRunService _missionRunService;
private readonly ISignalRService _signalRService;
private readonly IAccessRoleService _accessRoleService;
public MissionServiceTest(DatabaseFixture fixture)
{
_context = fixture.NewContext;
_logger = new Mock<ILogger<MissionRunService>>().Object;
_signalRService = new MockSignalRService();
_accessRoleService = new AccessRoleService(_context, new HttpContextAccessor());
_missionRunService = new MissionRunService(_context, _signalRService, _logger, _accessRoleService);
_databaseUtilities = new DatabaseUtilities(_context);
}
public void Dispose()
{
_context.Dispose();
GC.SuppressFinalize(this);
}
[Fact]
public async Task ReadIdDoesNotExist()
{
var missionRun = await _missionRunService.ReadById("some_id_that_does_not_exist");
Assert.Null(missionRun);
}
[Fact]
public async Task Create()
{
var reportsBefore = await _missionRunService.ReadAll(
new MissionRunQueryStringParameters()
);
int nReportsBefore = reportsBefore.Count;
var installation = await _databaseUtilities.NewInstallation();
var plant = await _databaseUtilities.NewPlant(installation.InstallationCode);
var deck = await _databaseUtilities.NewDeck(installation.InstallationCode, plant.PlantCode);
var area = await _databaseUtilities.NewArea(installation.InstallationCode, plant.PlantCode, deck.Name);
var robot = await _databaseUtilities.NewRobot(RobotStatus.Available, installation);
var missionRun = await _databaseUtilities.NewMissionRun(installation.InstallationCode, robot, area);
await _missionRunService.Create(missionRun);
var reportsAfter = await _missionRunService.ReadAll(
new MissionRunQueryStringParameters()
);
int nReportsAfter = reportsAfter.Count;
Assert.Equal(nReportsBefore + 1, nReportsAfter);
}
}
}