public async Task Handle_WhenRequested_ThenItShouldUpdateThePriorityOrder(long accountId,
                                                                                  UpdateProviderPaymentsPriorityDataCases.Setup[] setups,
                                                                                  UpdateProviderPaymentsPriorityDataCases.Input[] inputs,
                                                                                  UpdateProviderPaymentsPriorityDataCases.ExpectedOutput[] expectedOutputs)
        {
            var fixture = new UpdateProviderPaymentPriorityCommandHandlerTestsFixture();

            foreach (var setup in setups)
            {
                fixture.SetAccount(setup.AccountId, setup.ProviderId, setup.AccountName, setup.PriorityOrder);
            }

            var updateItems = inputs.Select(input => new UpdateProviderPaymentsPriorityCommand.ProviderPaymentPriorityUpdateItem
            {
                ProviderId    = input.ProviderId,
                PriorityOrder = input.PriorityOrder
            }).ToList();

            await fixture.Handle(accountId, updateItems, new UserInfo());

            fixture.VerifyAccount(accountId, expectedOutputs
                                  .Where(p => p.UpdateType != UpdateProviderPaymentsPriorityDataCases.UpdateType.Removed)
                                  .Select(expectedOutput => new CustomProviderPaymentPriority
            {
                EmployerAccountId = expectedOutput.AccountId,
                ProviderId        = expectedOutput.ProviderId,
                PriorityOrder     = expectedOutput.PriorityOrder
            }).ToList());
        }
        public async Task Handle_WhenRequested_ThenShouldPublishUpdatedStateChangedEvents(long accountId,
                                                                                          UpdateProviderPaymentsPriorityDataCases.Setup[] setups,
                                                                                          UpdateProviderPaymentsPriorityDataCases.Input[] inputs,
                                                                                          UpdateProviderPaymentsPriorityDataCases.ExpectedOutput[] expectedOutputs)
        {
            // Arrange
            var fixture = new UpdateProviderPaymentPriorityCommandHandlerTestsFixture();

            foreach (var setup in setups)
            {
                fixture.SetAccount(setup.AccountId, setup.ProviderId, setup.AccountName, setup.PriorityOrder);
            }

            var updateItems = inputs.Select(input => new UpdateProviderPaymentsPriorityCommand.ProviderPaymentPriorityUpdateItem
            {
                ProviderId    = input.ProviderId,
                PriorityOrder = input.PriorityOrder
            }).ToList();

            // Act
            await fixture.Handle(accountId, updateItems, new UserInfo());

            // Assert
            var changedEntityStateChangedEvents = expectedOutputs
                                                  .Where(p => p.UpdateType == UpdateProviderPaymentsPriorityDataCases.UpdateType.Changed)
                                                  .Select(p => new EntityStateChangedEvent
            {
                EmployerAccountId = accountId,
                ProviderId        = p.ProviderId,
                InitialState      = JsonConvert.SerializeObject(new CustomProviderPaymentPriority {
                    EmployerAccountId = accountId, ProviderId = p.ProviderId, PriorityOrder = p.OriginalPriorityOrder
                }),
                UpdatedState = JsonConvert.SerializeObject(new CustomProviderPaymentPriority {
                    EmployerAccountId = accountId, ProviderId = p.ProviderId, PriorityOrder = p.PriorityOrder
                }),
            });

            if (changedEntityStateChangedEvents.Any())
            {
                fixture.VerifyUpdatedEntityStateChangedEventPublished(changedEntityStateChangedEvents.ToList());
            }
        }
        public async Task Handle_WhenRequested_ThenShouldPublishPaymentOrderChangedEvent(long accountId,
                                                                                         UpdateProviderPaymentsPriorityDataCases.Setup[] setups,
                                                                                         UpdateProviderPaymentsPriorityDataCases.Input[] inputs,
                                                                                         UpdateProviderPaymentsPriorityDataCases.ExpectedOutput[] expectedOutputs)
        {
            // Arrange
            var fixture = new UpdateProviderPaymentPriorityCommandHandlerTestsFixture();

            foreach (var setup in setups)
            {
                fixture.SetAccount(setup.AccountId, setup.ProviderId, setup.AccountName, setup.PriorityOrder);
            }

            var updateItems = inputs.Select(input => new UpdateProviderPaymentsPriorityCommand.ProviderPaymentPriorityUpdateItem
            {
                ProviderId    = input.ProviderId,
                PriorityOrder = input.PriorityOrder
            }).ToList();

            // Act
            await fixture.Handle(accountId, updateItems, new UserInfo());

            // Assert
            var entityStateChanged = expectedOutputs
                                     .Any(p => p.UpdateType != UpdateProviderPaymentsPriorityDataCases.UpdateType.None);

            if (entityStateChanged)
            {
                var paymentOrder = expectedOutputs
                                   .Where(p => p.UpdateType != UpdateProviderPaymentsPriorityDataCases.UpdateType.Removed)
                                   .OrderBy(x => x.PriorityOrder)
                                   .Select(x => (int)x.ProviderId);

                fixture.VerifyPaymentOrderChangedEventPublished(accountId, paymentOrder.ToArray());
            }
        }