<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using MediatR;
using Moq;
using NUnit.Framework;
using SFA.DAS.EAS.Account.Api.Client;
using SFA.DAS.EmployerFinance.Configuration;
using SFA.DAS.EmployerFinance.Interfaces;
using SFA.DAS.EmployerFinance.Models.Payments;
using SFA.DAS.EmployerFinance.Models.Transaction;
using SFA.DAS.EmployerFinance.Queries.FindAccountProviderPayments;
using SFA.DAS.EmployerFinance.Web.Orchestrators;
using SFA.DAS.HashingService;
using SFA.DAS.NLog.Logger;

namespace SFA.DAS.EmployerFinance.Web.UnitTests.Orchestrators
{
    internal class WhenIGetProviderPayments
    {
        private const string HashedAccountId = "123ABC";
        private const long AccountId = 1234;
        private const string ExternalUser = "Test user";
        private const long ExpectedUkPrn = 46789465;
        private readonly DateTime _fromDate = DateTime.Now.AddDays(-20);
        private readonly DateTime _toDate = DateTime.Now.AddDays(-20);
        private Mock<ICurrentDateTime> _currentTime;
        private Mock<IHashingService> _hashingService;

        private Mock<IAccountApiClient> _accountApiClient;
        private EmployerAccountsConfiguration _employerAccountsConfiguration;
        private Mock<IMediator> _mediator;
        private EmployerAccountTransactionsOrchestrator _orchestrator;
        private FindAccountProviderPaymentsResponse _response;

        [SetUp]
        public void Arrange()
        {
            _accountApiClient = new Mock<IAccountApiClient>();
            _mediator = new Mock<IMediator>();
            _currentTime = new Mock<ICurrentDateTime>();
            _hashingService = new Mock<IHashingService>();

            _response = new FindAccountProviderPaymentsResponse
            {
                ProviderName = "Test Provider",
                TransactionDate = DateTime.Now,
                Total = 100,
                Transactions = new List<PaymentTransactionLine>
                {
                    new PaymentTransactionLine {Amount = 100}
                }
            };

            _mediator.Setup(AssertExpressionValidation()).ReturnsAsync(_response);

            _hashingService.Setup(h => h.DecodeValue(HashedAccountId)).Returns(AccountId);

            _orchestrator =
                new EmployerAccountTransactionsOrchestrator(_accountApiClient.Object, _employerAccountsConfiguration, _mediator.Object, _currentTime.Object, Mock.Of<ILog>());
        }

        private Expression<Func<IMediator, Task<FindAccountProviderPaymentsResponse>>> AssertExpressionValidation()
        {
            return x => x.SendAsync(It.Is<FindAccountProviderPaymentsQuery>(c => c.ExternalUserId.Equals(ExternalUser)
                                                                                 && c.FromDate.Equals(_fromDate)
                                                                                 && c.ToDate.Equals(_toDate)
                                                                                 && c.HashedAccountId.Equals(
                                                                                     HashedAccountId)
                                                                                 && c.UkPrn.Equals(ExpectedUkPrn)));
        }


        [Test]
        public async Task ThenIShouldGetTotalsByCourseForSFACoInvestmentPayments()
        {
            //Arrange<commit_msg>[CON-878] Missing mock for unit test<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using MediatR;
using Moq;
using NUnit.Framework;
using SFA.DAS.Common.Domain.Types;
using SFA.DAS.EAS.Account.Api.Client;
using SFA.DAS.EmployerFinance.Configuration;
using SFA.DAS.EmployerFinance.Interfaces;
using SFA.DAS.EmployerFinance.Models.Account;
using SFA.DAS.EmployerFinance.Models.Payments;
using SFA.DAS.EmployerFinance.Models.Transaction;
using SFA.DAS.EmployerFinance.Queries.FindAccountProviderPayments;
using SFA.DAS.EmployerFinance.Queries.GetEmployerAccount;
using SFA.DAS.EmployerFinance.Web.Orchestrators;
using SFA.DAS.HashingService;
using SFA.DAS.NLog.Logger;

namespace SFA.DAS.EmployerFinance.Web.UnitTests.Orchestrators
{
    internal class WhenIGetProviderPayments
    {
        private const string HashedAccountId = "123ABC";
        private const long AccountId = 1234;
        private const string ExternalUser = "Test user";
        private const long ExpectedUkPrn = 46789465;
        private readonly DateTime _fromDate = DateTime.Now.AddDays(-20);
        private readonly DateTime _toDate = DateTime.Now.AddDays(-20);
        private Mock<ICurrentDateTime> _currentTime;
        private Mock<IHashingService> _hashingService;

        private Mock<IAccountApiClient> _accountApiClient;
        private EmployerAccountsConfiguration _employerAccountsConfiguration;
        private Mock<IMediator> _mediator;
        private EmployerAccountTransactionsOrchestrator _orchestrator;
        private FindAccountProviderPaymentsResponse _response;

        [SetUp]
        public void Arrange()
        {
            _accountApiClient = new Mock<IAccountApiClient>();
            _mediator = new Mock<IMediator>();
            _currentTime = new Mock<ICurrentDateTime>();
            _hashingService = new Mock<IHashingService>();

            _response = new FindAccountProviderPaymentsResponse
            {
                ProviderName = "<NAME>",
                TransactionDate = DateTime.Now,
                Total = 100,
                Transactions = new List<PaymentTransactionLine>
                {
                    new PaymentTransactionLine {Amount = 100}
                }
            };

            _mediator.Setup(AssertExpressionValidation()).ReturnsAsync(_response);

            _hashingService.Setup(h => h.DecodeValue(HashedAccountId)).Returns(AccountId);

            _mediator
                .Setup(mock => mock.SendAsync(It.Is<GetEmployerAccountHashedQuery>(query => query.HashedAccountId == HashedAccountId)))
                .ReturnsAsync(new GetEmployerAccountResponse { Account = new Account { ApprenticeshipEmployerType = ApprenticeshipEmployerType.Levy } });

            _orchestrator =
                new EmployerAccountTransactionsOrchestrator(_accountApiClient.Object, _employerAccountsConfiguration, _mediator.Object, _currentTime.Object, Mock.Of<ILog>());
        }

        private Expression<Func<IMediator, Task<FindAccountProviderPaymentsResponse>>> AssertExpressionValidation()
        {
            return x => x.SendAsync(It.Is<FindAccountProviderPaymentsQuery>(c => c.ExternalUserId.Equals(ExternalUser)
                                                                                 && c.FromDate.Equals(_fromDate)
                                                                                 && c.ToDate.Equals(_toDate)
                                                                                 && c.HashedAccountId.Equals(
                                                                                     HashedAccountId)
                                                                                 && c.UkPrn.Equals(ExpectedUkPrn)));
        }


        [Test]
        public async Task ThenIShouldGetTotalsByCourseForSFACoInvestmentPayments()
        {
            //Arrange
{'fraction_non_alphanumeric': 0.07540322580645162, 'fraction_numerical': 0.007123655913978495, 'mean_word_length': 2.108187134502924, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2896807', 'n_tokens_mistral': 1939, 'n_tokens_neox': 1820, 'n_words': 327}