Vda5050ProtocolServiceTerminalLocationActionResolutionTests.cs 3.65 KB
using System.Reflection;
using Rcs.Domain.Entities;
using Rcs.Domain.Enums;
using Rcs.Infrastructure.Services.Protocol;
using Xunit;

namespace Rcs.Infrastructure.Tests;

public class Vda5050ProtocolServiceTerminalLocationActionResolutionTests
{
    private static readonly MethodInfo ResolveTerminalLocationActionIdsMethod =
        typeof(Vda5050ProtocolService).GetMethod(
            "ResolveTerminalLocationActionIds",
            BindingFlags.NonPublic | BindingFlags.Static)!;

    [Fact]
    public void ResolveTerminalLocationActionIds_ReturnsPickupActionIds_WhenTaskSubTypeIsPick()
    {
        var pickupApplyId = Guid.NewGuid();
        var pickupCompleteId = Guid.NewGuid();
        var locationType = new StorageLocationType
        {
            PickupApplyRequestConfigId = pickupApplyId,
            PickupCompleteRequestConfigId = pickupCompleteId
        };

        var result = InvokeResolveTerminalLocationActionIds(locationType, TaskSubType.Pick);

        Assert.NotNull(result);
        Assert.Equal(pickupApplyId, result.Value.ApplyActionId);
        Assert.Equal(pickupCompleteId, result.Value.CompleteActionId);
    }

    [Fact]
    public void ResolveTerminalLocationActionIds_ReturnsDropActionIds_WhenTaskSubTypeIsDown()
    {
        var dropApplyId = Guid.NewGuid();
        var dropCompleteId = Guid.NewGuid();
        var locationType = new StorageLocationType
        {
            DropApplyRequestConfigId = dropApplyId,
            DropCompleteRequestConfigId = dropCompleteId
        };

        var result = InvokeResolveTerminalLocationActionIds(locationType, TaskSubType.Down);

        Assert.NotNull(result);
        Assert.Equal(dropApplyId, result.Value.ApplyActionId);
        Assert.Equal(dropCompleteId, result.Value.CompleteActionId);
    }

    [Fact]
    public void ResolveTerminalLocationActionIds_ReturnsNull_WhenTaskSubTypeIsMove()
    {
        var locationType = new StorageLocationType
        {
            PickupApplyRequestConfigId = Guid.NewGuid(),
            PickupCompleteRequestConfigId = Guid.NewGuid(),
            DropApplyRequestConfigId = Guid.NewGuid(),
            DropCompleteRequestConfigId = Guid.NewGuid()
        };

        var result = InvokeResolveTerminalLocationActionIds(locationType, TaskSubType.Move);

        Assert.Null(result);
    }

    [Fact]
    public void ResolveTerminalLocationActionIds_ReturnsNull_WhenTaskSubTypeIsNull()
    {
        var locationType = new StorageLocationType
        {
            PickupApplyRequestConfigId = Guid.NewGuid(),
            PickupCompleteRequestConfigId = Guid.NewGuid()
        };

        var result = InvokeResolveTerminalLocationActionIds(locationType, null);

        Assert.Null(result);
    }

    [Fact]
    public void ResolveTerminalLocationActionIds_ReturnsNull_WhenLocationTypeIsNull()
    {
        var result = InvokeResolveTerminalLocationActionIds(null, TaskSubType.Pick);

        Assert.Null(result);
    }

    [Fact]
    public void ResolveTerminalLocationActionIds_ReturnsNull_WhenBothActionIdsAreEmpty()
    {
        var result = InvokeResolveTerminalLocationActionIds(new StorageLocationType(), TaskSubType.Pick);

        Assert.Null(result);
    }

    private static (Guid? ApplyActionId, Guid? CompleteActionId)? InvokeResolveTerminalLocationActionIds(
        StorageLocationType? locationType,
        TaskSubType? taskSubType)
    {
        var value = ResolveTerminalLocationActionIdsMethod.Invoke(
            null,
            new object?[] { locationType, taskSubType });

        if (value == null)
        {
            return null;
        }

        var tuple = Assert.IsType<ValueTuple<Guid?, Guid?>>(value);
        return (tuple.Item1, tuple.Item2);
    }
}