public static int GetTaskPriority(AccountTask task)
        {
            switch (task.Type)
            {
            case "LevyDeclarationDue": return(1);

            case "AgreementToSign": return(2);

            case "AddApprentices": return(3);

            case "ApprenticeChangesToReview": return(4);

            case "CohortRequestReadyForApproval": return(5);

            case "IncompleteApprenticeshipDetails": return(6);

            case "ReviewConnectionRequest": return(7);

            case "TransferRequestReceived": return(8);

            default: return(int.MaxValue);    //if its an usupported type we place it last
            }
        }
        public void Arrange()
        {
            _accountStats = new AccountStats
            {
                AccountId         = 10,
                OrganisationCount = 3,
                PayeSchemeCount   = 4,
                TeamMemberCount   = 8
            };

            _testTask = new AccountTask
            {
                Type          = "Test",
                ItemsDueCount = 2
            };

            _tasks = new List <AccountTask>
            {
                _testTask
            };

            _mediator = new Mock <IMediator>();
            _mediator.Setup(m => m.SendAsync(It.Is <GetEmployerAccountByHashedIdQuery>(q => q.HashedAccountId == HashedAccountId)))
            .ReturnsAsync(new GetEmployerAccountByHashedIdResponse
            {
                Account = new Account
                {
                    HashedId = HashedAccountId,
                    Id       = AccountId,
                    Name     = "Account 1"
                }
            });

            _mediator.Setup(x => x.SendAsync(It.IsAny <GetAccountTasksQuery>()))
            .ReturnsAsync(new GetAccountTasksResponse
            {
                Tasks = _tasks
            });

            _mediator.Setup(m => m.SendAsync(It.Is <GetUserAccountRoleQuery>(q => q.ExternalUserId == UserId)))
            .ReturnsAsync(new GetUserAccountRoleResponse
            {
                UserRole = Role.Owner
            });

            _mediator.Setup(m => m.SendAsync(It.Is <GetAccountEmployerAgreementsRequest>(q => q.HashedAccountId == HashedAccountId)))
            .ReturnsAsync(new GetAccountEmployerAgreementsResponse
            {
                EmployerAgreements = new List <EmployerAgreementStatusDto>
                {
                    new EmployerAgreementStatusDto
                    {
                        Pending = new PendingEmployerAgreementDetailsDto {
                            Id = 123
                        }
                    },
                    new EmployerAgreementStatusDto
                    {
                        Pending = new PendingEmployerAgreementDetailsDto {
                            Id = 124
                        }
                    },
                    new EmployerAgreementStatusDto
                    {
                        Pending = new PendingEmployerAgreementDetailsDto {
                            Id = 125
                        }
                    },
                    new EmployerAgreementStatusDto
                    {
                        Pending = new PendingEmployerAgreementDetailsDto {
                            Id = 126
                        }
                    },
                    new EmployerAgreementStatusDto
                    {
                        Signed = new SignedEmployerAgreementDetailsDto {
                            Id = 111
                        }
                    },
                    new EmployerAgreementStatusDto
                    {
                        Signed = new SignedEmployerAgreementDetailsDto {
                            Id = 112
                        }
                    },
                    new EmployerAgreementStatusDto
                    {
                        Signed = new SignedEmployerAgreementDetailsDto {
                            Id = 113
                        }
                    }
                }
            });

            _mediator.Setup(x => x.SendAsync(It.IsAny <GetTeamMemberQuery>()))
            .ReturnsAsync(new GetTeamMemberResponse {
                User = new MembershipView {
                    FirstName = "Bob"
                }
            });

            _mediator.Setup(x => x.SendAsync(It.IsAny <GetAccountStatsQuery>()))
            .ReturnsAsync(new GetAccountStatsResponse {
                Stats = _accountStats
            });

            _currentDateTime = new Mock <ICurrentDateTime>();

            _accountApiClient = new Mock <IAccountApiClient>();

            _accountApiClient.Setup(c => c.GetAccount(HashedAccountId)).ReturnsAsync(new AccountDetailViewModel
            {
                ApprenticeshipEmployerType = "Levy"
            });

            _mapper = new Mock <IMapper>();

            _orchestrator = new EmployerTeamOrchestrator(_mediator.Object, _currentDateTime.Object, _accountApiClient.Object, _mapper.Object);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: Anton-Grebenkin/WebHooks
        static void Main(string[] args)
        {
            var connectionString = "";
            var contextOptions   = new DbContextOptionsBuilder <WebHooksContext>()
                                   .UseSqlServer(connectionString)
                                   .Options;
            WebHooksContext context;

            //WebHooksRepository webHooksRepository = new WebHooksRepository(connectionString);

            List <EventHook>   eventHookList   = new List <EventHook>();
            List <string>      accountList     = new List <string>();
            List <AccountTask> accountTaskList = new List <AccountTask>();
            AccountTask        accountTask;

            while (true)
            {
                Console.WriteLine(String.Format("{0}: Проверяем кол-во задач", DateTime.Now.ToString("T")));
                if (accountTaskList.Count() < 30)
                {
                    using (context = new WebHooksContext(contextOptions))
                    {
                        IRepository <EventHook> eventHookRepository = new GenericRepository <EventHook>(context);
                        try
                        {
                            Console.WriteLine(String.Format("{0}: Выпоняем основной запрос", DateTime.Now.ToString("T")));
                            accountList = eventHookRepository.GetQuery(e => e.Subscription)
                                          .AsNoTracking()
                                          .Where(e => e.SendTime <= DateTime.UtcNow && e.SendTime != null && e.IsActual && e.Subscription.IsActual)
                                          .Select(e => e.Subscription.ExternalAccountId)
                                          .Distinct()
                                          .ToList();
                            Console.WriteLine(String.Format("{0}: Основной запрос выполнился ", DateTime.Now.ToString("T")));
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(String.Format("{0}: Ошибка! Не удалось выпонить основной запрос. {1} ", DateTime.Now.ToString("T"), ex));
                        }
                    }
                }

                if (accountList.Count == 0)
                {
                    Thread.Sleep(10000);
                    continue;
                }

                string account;
                while (accountList.Count() > 0)
                {
                    account = accountList[0];
                    bool taskExists;
                    lock (accountTaskList)
                    {
                        taskExists = accountTaskList.Where(a => a.ExternalAccountId == account).Any();
                    }

                    if (!taskExists && accountTaskList.Count() < 30)
                    {
                        accountTask = new AccountTask();
                        accountTask.ExternalAccountId = account;
                        accountList.RemoveAt(0);
                        lock (accountTaskList)
                        {
                            accountTaskList.Add(accountTask);
                        }
                        accountTask.Task = SendHooks(account, accountTaskList);
                    }
                    else if (taskExists)
                    {
                        accountList.RemoveAt(0);
                    }
                }
            }
        }