Skip to content

Commit

Permalink
Mock logger in robotservice test
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Oct 18, 2023
1 parent d350912 commit 786926d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions backend/api.test/Services/RobotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Api.Database.Context;
using Api.Database.Models;
using Api.Services;
using Microsoft.Extensions.Logging;
using Moq;
using Xunit;

namespace Api.Test.Services
Expand All @@ -31,7 +33,8 @@ public void Dispose()
[Fact]
public async Task ReadAll()
{
var robotService = new RobotService(_context, _robotModelService);
var logger = new Mock<ILogger<RobotService>>().Object;
var robotService = new RobotService(_context, _robotModelService, logger);
var robots = await robotService.ReadAll();

Assert.True(robots.Any());
Expand All @@ -40,7 +43,8 @@ public async Task ReadAll()
[Fact]
public async Task Read()
{
var robotService = new RobotService(_context, _robotModelService);
var logger = new Mock<ILogger<RobotService>>().Object;
var robotService = new RobotService(_context, _robotModelService, logger);
var robots = await robotService.ReadAll();
var firstRobot = robots.First();
var robotById = await robotService.ReadById(firstRobot.Id);
Expand All @@ -51,15 +55,17 @@ public async Task Read()
[Fact]
public async Task ReadIdDoesNotExist()
{
var robotService = new RobotService(_context, _robotModelService);
var logger = new Mock<ILogger<RobotService>>().Object;
var robotService = new RobotService(_context, _robotModelService, logger);
var robot = await robotService.ReadById("some_id_that_does_not_exist");
Assert.Null(robot);
}

[Fact]
public async Task Create()
{
var robotService = new RobotService(_context, _robotModelService);
var logger = new Mock<ILogger<RobotService>>().Object;
var robotService = new RobotService(_context, _robotModelService, logger);
var robotsBefore = await robotService.ReadAll();
int nRobotsBefore = robotsBefore.Count();
var videoStreamQuery = new CreateVideoStreamQuery()
Expand Down

0 comments on commit 786926d

Please sign in to comment.