< Summary

Information
Class: LGDXRobotCloud.API.Authorisation.RobotClientShouldOnlineHandler
Assembly: LGDXRobotCloud.API
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Authorisation/RobotClientShouldOnlineHandler.cs
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 32
Line coverage: 100%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)50%22100%
HandleRequirementAsync()100%66100%

File(s)

/builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Authorisation/RobotClientShouldOnlineHandler.cs

#LineLine coverage
 1using System.Security.Claims;
 2using LGDXRobotCloud.API.Services.Navigation;
 3using Microsoft.AspNetCore.Authorization;
 4
 5namespace LGDXRobotCloud.API.Authorisation;
 6
 47public class RobotClientShouldOnlineHandler (
 48  IOnlineRobotsService OnlineRobotsService
 49) : AuthorizationHandler<RobotClientShouldOnlineRequirement>
 10{
 411  private readonly IOnlineRobotsService _onlineRobotsService = OnlineRobotsService ?? throw new ArgumentException(nameof
 12
 13  protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, RobotClientShouldOnlineRequi
 414  {
 415    var robotClaim = context.User.FindFirst(ClaimTypes.NameIdentifier);
 416    if (robotClaim == null)
 117    {
 118      context.Fail();
 119      return;
 20    }
 321    if (Guid.TryParse(robotClaim.Value, out var robotId) && await _onlineRobotsService.IsRobotOnlineAsync(robotId))
 122    {
 123      context.Succeed(requirement);
 124      return;
 25    }
 26    else
 227    {
 228      context.Fail();
 229      return;
 30    }
 431  }
 32}