Popraw poniższy test napisany w C#, aby wykonywał się prawidłowo.

/// TEST

    [Test]
    public async Task PrintSaleConfirmationAsync_ValidInput_SuccessfulPrint()
    {
        // Arrange
        var response = new FirstDataStartResponse
        {
            AcceptorTransactionIdentifier = "123456",
            TransactionNumber = 1,
            TID = "TID001",
            MID = "MID001",
            CardAcceptorName = "Test Merchant",
            MaskedCardNumber = "************1234",
            CardName = "VISA",
            TransactionCurrencyCode = "PLN",
            TransactionAmount = 100.00m,
            MaskedExpiryDateOfCard = "12/24",
            UnmaskedExpiryDateOfCard = "12/24"
        };
        string ip = "192.168.1.1";
        int port = 9100;

        var mockFiscalPrinterService = new Mock<FiscalPrinterService>();
        mockFiscalPrinterService.Setup(x => x.SendCommandToFiscalPrinter(It.IsAny<string[]>(), ip, port))
            .ReturnsAsync(string.Empty); // Simulate successful command execution

        // Act
        await mockFiscalPrinterService.Object.PrintSaleConfirmationAsync(response, ip, port);

        // Assert
        mockFiscalPrinterService.Verify(x => x.SendCommandToFiscalPrinter(It.Is<string[]>(a => a[0] == "formstart"), ip, port), Times.Once);
        mockFiscalPrinterService.Verify(x => x.SendCommandToFiscalPrinter(It.Is<string[]>(a => a[0] == "formline" && a[2] == "fl1"), ip, port), Times.Once);
        mockFiscalPrinterService.Verify(x => x.SendCommandToFiscalPrinter(It.Is<string[]>(a => a[0] == "formline" && a[2] == "fl2"), ip, port), Times.Once);
        mockFiscalPrinterService.Verify(x => x.SendCommandToFiscalPrinter(It.Is<string[]>(a => a[0] == "formline" && a[2] == "fl4"), ip, port), Times.Once);
        mockFiscalPrinterService.Verify(x => x.SendCommandToFiscalPrinter(It.Is<string[]>(a => a[0] == "formline" && a[2] == "fl6"), ip, port), Times.Once);
        mockFiscalPrinterService.Verify(x => x.SendCommandToFiscalPrinter(It.Is<string[]>(a => a[0] == "formline" && a[2] == "fl8"), ip, port), Times.Once);
        mockFiscalPrinterService.Verify(x => x.SendCommandToFiscalPrinter(It.Is<string[]>(a => a[0] == "formline" && a[2] == "fl9"), ip, port), Times.Once);
        mockFiscalPrinterService.Verify(x => x.SendCommandToFiscalPrinter(It.Is<string[]>(a => a[0] == "formline" && a[2] == "fl31"), ip, port), Times.Once);
        mockFiscalPrinterService.Verify(x => x.SendCommandToFiscalPrinter(It.Is<string[]>(a => a[0] == "formline" && a[2] == "fl35"), ip, port), Times.Once);
        mockFiscalPrinterService.Verify(x => x.SendCommandToFiscalPrinter(It.Is<string[]>(a => a[0] == "formline" && a[2] == "fl70"), ip, port), Times.Once);
        mockFiscalPrinterService.Verify(x => x.SendCommandToFiscalPrinter(It.Is<string[]>(a => a[0] == "formend"), ip, port), Times.Once);
    }

/// KOD

public async Task PrintSaleConfirmationAsync(FirstDataStartResponse response, string ip, int port)
{
    if (response == null)
    {
        Logger.Error("Response cannot be null.");
        throw new ArgumentNullException(nameof(response));
    }

    Logger.Info($"Printing sale confirmation for transaction {response.AcceptorTransactionIdentifier} on printer at {ip}:{port}");

    var semaphore = GetPrinterSemaphore(ip, port);
    await semaphore.WaitAsync();

    try
    {
        var printRules = !string.IsNullOrEmpty(response.MaskingRulesPrintouts)
            ? response.MaskingRulesPrintouts.ToMaskingRulesPrintoutsDecoder(MaskingRulesPrintoutsDecoder.PrintType.CardholderCopy)
            : null;
        var isDCC = response.DCCExchangeRate.HasValue;
        var isApproved = response.IsApproved;
        var expiryDate = (printRules?.PrintB4 == true || printRules?.PrintB5 == true)
            ? response.MaskedExpiryDateOfCard
            : response.UnmaskedExpiryDateOfCard;

        var cardNumber = printRules?.PrintB3 == true
            ? response.MaskedCardNumber?.Trim()
            : response.UnmaskedCardNumber?.Trim();

        if (!string.IsNullOrEmpty(cardNumber) && !string.IsNullOrEmpty(expiryDate))
        {
            await PrintFormHeader(isApproved, response, ip, port);
            await PrintTransactionDetails(isDCC, response, cardNumber, expiryDate, ip, port);
            await PrintAdditionalInfo(response, ip, port);
            await PrintFormFooter(ip, port);

            Logger.Info($"Sale confirmation printed successfully for transaction {response.AcceptorTransactionIdentifier}");
        }
        else
        {
            Logger.Error("Failed to retrieve card number or expiry date.");
            throw new InvalidOperationException("Card number or expiry date is missing.");
        }
    }
    catch (Exception ex)
    {
        Logger.Error(ex, $"Error printing sale confirmation for transaction {response.AcceptorTransactionIdentifier}");
        throw;
    }
    finally
    {
        semaphore.Release();
    }
}

/// BŁĄD

 PrintSaleConfirmationAsync_ValidInput_SuccessfulPrint
   Source: FiscalPrinterServiceTests.cs line 161
   Duration: 3 ms

  Message: 
System.InvalidOperationException : Card number or expiry date is missing.

  Stack Trace: 
FiscalPrinterService.PrintSaleConfirmationAsync(FirstDataStartResponse response, String ip, Int32 port) line 282
FiscalPrinterServiceTests.PrintSaleConfirmationAsync_ValidInput_SuccessfulPrint() line 186
GenericAdapter`1.GetResult()
AsyncToSyncAdapter.Await[TResult](Func`1 invoke)
AsyncToSyncAdapter.Await(Func`1 invoke)
TestMethodCommand.RunTestMethod(TestExecutionContext context)
TestMethodCommand.Execute(TestExecutionContext context)
<>c__DisplayClass3_0.<PerformWork>b__0()
<>c__DisplayClass1_0`1.<DoIsolated>b__0(Object _)
ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
ContextUtils.DoIsolated(ContextCallback callback, Object state)
ContextUtils.DoIsolated[T](Func`1 func)
SimpleWorkItem.PerformWork()