public void Arrange()
        {
            _query = new GetAccountLegalEntitiesQuery {
                AccountId = ExpectedAccountId
            };
            _validator = new Mock <IValidator <GetAccountLegalEntitiesQuery> >();
            _validator.Setup(x => x.ValidateAsync(It.IsAny <GetAccountLegalEntitiesQuery>()))
            .ReturnsAsync(new ValidationResult {
                ValidationDictionary = new Dictionary <string, string>()
            });
            _cancellationToken = new CancellationToken();
            _service           = new Mock <IAccountLegalEntitiesService>();

            _handler = new GetAccountLegalEntitiesQueryHandler(_validator.Object, _service.Object);
        }
        public async Task Then_If_Not_Found_Then_Empty_List_Returned(
            GetAccountLegalEntitiesQuery query,
            [Frozen] Mock <IAccountsApiClient <AccountsConfiguration> > accountApiClient,
            GetAccountLegalEntitiesQueryHandler handler)
        {
            //Arrange
            accountApiClient
            .Setup(x => x.GetAll <GetAccountLegalEntityResponseItem>(
                       It.IsAny <GetAccountLegalEntitiesRequest>()))
            .ReturnsAsync((List <GetAccountLegalEntityResponseItem>)null);

            //Act
            var actual = await handler.Handle(query, CancellationToken.None);

            //Assert
            actual.AccountLegalEntities.Should().BeNullOrEmpty();
        }
        public GetAccountLegalEntitiesQueryHandlerTestsFixture()
        {
            Query = new GetAccountLegalEntitiesQuery();

            ConfigurationProvider = new MapperConfiguration(c =>
            {
                c.AddProfile <LegalEntityMappings>();
            });

            Db = new Mock <EmployerAccountsDbContext>();
            AccountLegalEntities = new List <EmployerAccounts.Models.Account.AccountLegalEntity>();

            Db.Setup(d => d.AccountLegalEntities).Returns(new DbSetStub <EmployerAccounts.Models.Account.AccountLegalEntity>(AccountLegalEntities));

            Handler = new GetAccountLegalEntitiesQueryHandler(ConfigurationProvider, new Lazy <EmployerAccountsDbContext>(() => Db.Object));

            QueryFutureManager.AllowQueryBatch = false;
        }
        public async Task Then_The_Query_Is_Handled_And_Data_Returned(
            GetAccountLegalEntitiesQuery query,
            List <GetAccountLegalEntityResponseItem> apiResponse,
            [Frozen] Mock <IAccountsApiClient <AccountsConfiguration> > accountApiClient,
            GetAccountLegalEntitiesQueryHandler handler)
        {
            //Arrange
            var expectedGet = new GetAccountLegalEntitiesRequest(query.HashedAccountId);

            accountApiClient
            .Setup(x => x.GetAll <GetAccountLegalEntityResponseItem>(
                       It.Is <GetAccountLegalEntitiesRequest>(c => c.GetAllUrl.Equals(expectedGet.GetAllUrl))))
            .ReturnsAsync(apiResponse);

            //Act
            var actual = await handler.Handle(query, CancellationToken.None);

            //Assert
            actual.AccountLegalEntities.Should().BeEquivalentTo(apiResponse);
        }