public UpdateProcessLevyDeclarationsSagaProgressCommandHandlerTestsFixture SetAdHocSagaType()
        {
            Saga.Set(s => s.Type, LevyDeclarationSagaType.AdHoc)
            .Set(s => s.AccountPayeSchemeId, AccountPayeSchemes[0].Id)
            .Set(s => s.ImportPayeSchemeLevyDeclarationsTasksCount, 1)
            .Set(s => s.UpdateAccountTransactionBalancesTasksCount, 1);

            Db.SaveChanges();

            return(this);
        }
        public UpdateProcessLevyDeclarationsSagaProgressCommandHandlerTestsFixture SetScheduledSagaType()
        {
            Saga.Set(s => s.Type, LevyDeclarationSagaType.Planned)
            .Set(s => s.AccountPayeSchemeHighWaterMarkId, AccountPayeSchemes.Max(aps => aps.Id))
            .Set(s => s.ImportPayeSchemeLevyDeclarationsTasksCount, AccountPayeSchemes.Select(aps => aps.EmployerReferenceNumber).Count())
            .Set(s => s.UpdateAccountTransactionBalancesTasksCount, AccountPayeSchemes.Select(aps => aps.AccountId).Distinct().Count());

            Db.SaveChanges();

            return(this);
        }
        public UpdateProcessLevyDeclarationsSagaProgressCommandHandlerTestsFixture SetTooManyUpdateAccountTransactionBalancesTasksCompleted()
        {
            Saga.Set(s => s.ImportPayeSchemeLevyDeclarationsTasksCompleteCount, AccountPayeSchemes.Count);

            Tasks = Accounts
                    .Select(a => LevyDeclarationSagaTask.CreateUpdateAccountTransactionBalancesTask(Saga.Id, a.Id))
                    .Append(LevyDeclarationSagaTask.CreateUpdateAccountTransactionBalancesTask(Saga.Id, Accounts[0].Id))
                    .ToList();

            Db.LevyDeclarationSagaTasks.AddRange(Tasks);
            Db.SaveChanges();

            return(this);
        }
        public UpdateProcessLevyDeclarationsSagaProgressCommandHandlerTestsFixture SetSomeUpdateAccountTransactionBalancesTasksCompleted()
        {
            Saga.Set(s => s.ImportPayeSchemeLevyDeclarationsTasksCompleteCount, AccountPayeSchemes.Count);

            Tasks = new List <LevyDeclarationSagaTask>
            {
                LevyDeclarationSagaTask.CreateUpdateAccountTransactionBalancesTask(Saga.Id, AccountPayeSchemes[0].AccountId)
            };

            Db.LevyDeclarationSagaTasks.AddRange(Tasks);
            Db.SaveChanges();

            return(this);
        }
        public UpdateProcessLevyDeclarationsSagaProgressCommandHandlerTestsFixture SetAllTasksCompleted()
        {
            Saga.Set(s => s.ImportPayeSchemeLevyDeclarationsTasksCompleteCount, Saga.ImportPayeSchemeLevyDeclarationsTasksCount)
            .Set(s => s.UpdateAccountTransactionBalancesTasksCompleteCount, Saga.UpdateAccountTransactionBalancesTasksCount)
            .Set(s => s.IsComplete, true)
            .Set(s => s.Updated, Now);

            var importPayeSchemeLevyDeclarationsTasks = AccountPayeSchemes
                                                        .Take(Saga.ImportPayeSchemeLevyDeclarationsTasksCount)
                                                        .Select(aps => LevyDeclarationSagaTask.CreateImportPayeSchemeLevyDeclarationsTask(Saga.Id, aps.Id));

            var updateAccountTransactionBalancesTasks = Accounts
                                                        .Take(Saga.UpdateAccountTransactionBalancesTasksCount)
                                                        .Select(a => LevyDeclarationSagaTask.CreateUpdateAccountTransactionBalancesTask(Saga.Id, a.Id));

            Tasks = importPayeSchemeLevyDeclarationsTasks.Concat(updateAccountTransactionBalancesTasks).ToList();

            Db.LevyDeclarationSagaTasks.AddRange(Tasks);
            Db.SaveChanges();

            return(this);
        }