Skip to content

Commit

Permalink
Support that echo test create mission definition
Browse files Browse the repository at this point in the history
  • Loading branch information
oysand committed Dec 19, 2023
1 parent 14b03cf commit c67dae4
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 14 deletions.
31 changes: 20 additions & 11 deletions backend/api.test/Mocks/EchoServiceMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading;
using System.Threading.Tasks;
using Api.Controllers.Models;
using Api.Database.Models;
using Api.Services;
namespace Api.Test.Mocks
{
Expand All @@ -21,16 +22,6 @@ public class MockEchoService : IEchoService
}
];

public EchoMission MockEchoMission =
new()
{
Id = 1,
Name = "test",
InstallationCode = "testInstallation",
URL = new Uri("https://www.I-am-echo-stid-tag-url.com"),
Tags = new List<EchoTag>()
};

public CondensedEchoMissionDefinition MockMissionDefinition =
new()
{
Expand All @@ -47,7 +38,25 @@ public async Task<IList<CondensedEchoMissionDefinition>> GetAvailableMissions(st
public async Task<EchoMission> GetMissionById(int missionId)
{
await Task.Run(() => Thread.Sleep(1));
return MockEchoMission;

var mockEchoMission = new EchoMission
{
Id = missionId,
Name = "test",
InstallationCode = "testInstallation",
URL = new Uri("https://testurl.com"),
Tags = new List<EchoTag>{new() {
Id = 1,
TagId = "testTag",
Pose = new Pose(),
Inspections = new List<EchoInspection>{new() {
InspectionType = InspectionType.Image,
InspectionPoint = new Position{X=1, Y=1, Z=1}
}}
}}
};

return mockEchoMission;
}

public async Task<IList<EchoPlantInfo>> GetEchoPlantInfos()
Expand Down
66 changes: 64 additions & 2 deletions backend/api.test/Mocks/StidServiceMock.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Api.Database.Context;
using Api.Database.Models;
using Microsoft.EntityFrameworkCore;

namespace Api.Services
{
public class MockStidService : IStidService
public class MockStidService(FlotillaDbContext context) : IStidService
{
public const string ServiceName = "StidApi";

Expand All @@ -16,5 +21,62 @@ public async Task<Position> GetTagPosition(string tag, string installationCode)
z: 0
);
}

public virtual async Task<Area> GetTagArea(string tag, string installationCode)
{
await Task.CompletedTask;
string testAreaName = "StidServiceMockArea";

var area = context.Areas.Include(a => a.SafePositions)
.Include(a => a.Deck).Include(d => d.Plant)
.Include(i => i.Installation).Include(d => d.DefaultLocalizationPose)
.Where(area => area.Name.Contains(testAreaName)).ToList().FirstOrDefault();
if (area != null) { return area; }

var testInstallation = new Installation
{
Id = Guid.NewGuid().ToString(),
Name = "StidServiceMockInstallation",
InstallationCode = "TTT"
};

var testPlant = new Plant
{
Id = Guid.NewGuid().ToString(),
Installation = testInstallation,
Name = "StidServiceMockPlant",
PlantCode = "TTT"
};

var testDeck = new Deck
{
Id = Guid.NewGuid().ToString(),
Plant = testPlant,
Installation = testPlant.Installation,
DefaultLocalizationPose = new DefaultLocalizationPose(),
Name = "StidServiceMockDeck"
};

var testArea = new Area
{
Id = Guid.NewGuid().ToString(),
Deck = testDeck,
Plant = testDeck.Plant,
Installation = testDeck.Plant.Installation,
Name = testAreaName,
MapMetadata = new MapMetadata(),
DefaultLocalizationPose = new DefaultLocalizationPose(),
SafePositions = new List<SafePosition>()
};

context.Add(testInstallation);
context.Add(testPlant);
context.Add(testDeck);
context.Add(testArea);

await context.SaveChangesAsync();

return testArea;
}
}
}
2 changes: 1 addition & 1 deletion backend/api.test/api.test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0" />
<PackageReference Include="Moq" Version="4.20.69"/>
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<PrivateAssets>all</PrivateAssets>
Expand Down

0 comments on commit c67dae4

Please sign in to comment.