public async Task GivenACompanyHouseSearchClient_WhenSearchingForAOfficer()
        {
            var fixture = new Fixture();
            var items   = fixture.Build <Item>()
                          .With(x => x.Kind, "searchresults#officer")
                          .CreateMany().ToArray();

            _resourceDetails = fixture.Build <ResourceDetails>()
                               .With(x => x.Officers, items)
                               .Create();

            var uri = new Uri("https://wibble.com/search/companies");

            var resource = new OfficerSearchResourceBuilder()
                           .CreateResource(_resourceDetails);

            HttpMessageHandler handler = new StubHttpMessageHandler(uri, resource);

            var uriBuilder = new Mock <ISearchUriBuilder>();

            uriBuilder.Setup(x => x.Build(It.IsAny <SearchRequest>()))
            .Returns(uri);

            var uriBuilderFactory = new Mock <ISearchUriBuilderFactory>();

            uriBuilderFactory.Setup(x => x.Create <OfficerSearch>())
            .Returns(uriBuilder.Object);

            _client = new CompaniesHouseSearchClient(new HttpClient(handler), uriBuilderFactory.Object);

            _result = await _client.SearchAsync <OfficerSearch>(new SearchRequest());
        }
Exemplo n.º 2
0
        public async Task GivenACompanyHouseSearchCompanyClient_WhenSearchingForACompanyAndApiReturnsTooManyRequests()
        {
            var uri = new Uri("https://wibble.com/search/companies");

            HttpMessageHandler handler = new TooManyRequestsHttpMessageHandler();

            var uriBuilder = new Mock <ISearchUriBuilder>();

            uriBuilder.Setup(x => x.Build(It.IsAny <SearchRequest>()))
            .Returns(uri);

            var uriBuilderFactory = new Mock <ISearchUriBuilderFactory>();

            uriBuilderFactory.Setup(x => x.Create <CompanySearch>())
            .Returns(uriBuilder.Object);

            var client = new CompaniesHouseSearchClient(new HttpClient(handler), uriBuilderFactory.Object);

            try
            {
                await client.SearchAsync <CompanySearch>(new SearchRequest());
            }
            catch (Exception ex)
            {
                _caughtException = ex;
            }
        }
        public async Task GivenACompanyHouseSearchClient_WhenSearchingForAOfficer()
        {
            var fixture = new Fixture();
            var items = fixture.Build<Item>()
                .With(x => x.Kind, "searchresults#officer")
                .CreateMany().ToArray();
            _resourceDetails = fixture.Build<ResourceDetails>()
                .With(x => x.Officers, items)
                .Create();
            
            var uri = new Uri("https://wibble.com/search/companies");

            var resource = new OfficerSearchResourceBuilder()
                .CreateResource(_resourceDetails);

            HttpMessageHandler handler = new StubHttpMessageHandler(uri, resource);

            var uriBuilder = new Mock<ISearchUriBuilder>();
            uriBuilder.Setup(x => x.Build(It.IsAny<SearchRequest>()))
                .Returns(uri);

            var uriBuilderFactory = new Mock<ISearchUriBuilderFactory>();
            uriBuilderFactory.Setup(x => x.Create<OfficerSearch>())
                .Returns(uriBuilder.Object);

            _client = new CompaniesHouseSearchClient(new HttpClient(handler), uriBuilderFactory.Object);

            _result = await _client.SearchAsync<OfficerSearch>(new SearchRequest());
        }
Exemplo n.º 4
0
        public void GivenACompanyHouseSearchCompanyClient_WhenSearchingForACompany()
        {
            var fixture = new Fixture();

            _resourceDetails   = fixture.Create <ResourceDetails>();
            _expectedCompanies = new List <CompanyDetails>
            {
                fixture.Build <CompanyDetails>().With(x => x.CompanyStatus, "active").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build <CompanyDetails>().With(x => x.CompanyStatus, "dissolved").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build <CompanyDetails>().With(x => x.CompanyStatus, "liquidation").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build <CompanyDetails>().With(x => x.CompanyStatus, "receivership").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build <CompanyDetails>().With(x => x.CompanyStatus, "administration").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build <CompanyDetails>().With(x => x.CompanyStatus, "voluntary-arrangement").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build <CompanyDetails>().With(x => x.CompanyStatus, "converted-closed").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build <CompanyDetails>().With(x => x.CompanyStatus, "insolvency-proceedings").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build <CompanyDetails>().With(x => x.CompanyStatus, "open").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build <CompanyDetails>().With(x => x.CompanyStatus, "closed").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build <CompanyDetails>().With(x => x.CompanyStatus, "closed-on").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                //fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, null).With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
            };

            var uri = new Uri("https://wibble.com/search/companies");

            _companyWithUnknownDateOfCessation = fixture.Build <CompanyDetails>().With(x => x.CompanyStatus, "insolvency-proceedings").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create();
            var resource = new CompanySearchResourceBuilder()
                           .AddCompanies(_expectedCompanies)
                           .AddCompanyWithUnknownDateOfCessation(_companyWithUnknownDateOfCessation)
                           .CreateResource(_resourceDetails);

            HttpMessageHandler handler = new StubHttpMessageHandler(uri, resource);

            var uriBuilder = new Mock <ISearchUriBuilder>();

            uriBuilder.Setup(x => x.Build(It.IsAny <SearchRequest>()))
            .Returns(uri);

            var uriBuilderFactory = new Mock <ISearchUriBuilderFactory>();

            uriBuilderFactory.Setup(x => x.Create <CompanySearch>())
            .Returns(uriBuilder.Object);

            _client = new CompaniesHouseSearchClient(new HttpClient(handler), uriBuilderFactory.Object);

            _result = _client.SearchAsync <CompanySearch>(new SearchRequest()).Result;
        }
        public void GivenACompanyHouseSearchCompanyClient_WhenSearchingForACompany()
        {
            var fixture = new Fixture();
            _resourceDetails = fixture.Create<ResourceDetails>();
            _expectedCompanies = new List<CompanyDetails>
            {
                fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, "active").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, "dissolved").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, "liquidation").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, "receivership").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, "administration").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, "voluntary-arrangement").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, "converted-closed").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, "insolvency-proceedings").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, "open").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, "closed").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
                fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, "closed-on").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create(),
            };

            var uri = new Uri("https://wibble.com/search/companies");

            _companyWithUnknownDateOfCessation = fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, "insolvency-proceedings").With(x => x.CompanyType, "private-unlimited").With(x => x.Kind, "searchresults#company").Create();
            var resource = new CompanySearchResourceBuilder()
                .AddCompanies(_expectedCompanies)
                .AddCompanyWithUnknownDateOfCessation(_companyWithUnknownDateOfCessation)
                .CreateResource(_resourceDetails);

            HttpMessageHandler handler = new StubHttpMessageHandler(uri, resource);

            var uriBuilder = new Mock<ISearchUriBuilder>();
            uriBuilder.Setup(x => x.Build(It.IsAny<SearchRequest>()))
                .Returns(uri);

            var uriBuilderFactory = new Mock<ISearchUriBuilderFactory>();
            uriBuilderFactory.Setup(x => x.Create<CompanySearch>())
                .Returns(uriBuilder.Object);

            _client = new CompaniesHouseSearchClient(new HttpClient(handler), uriBuilderFactory.Object);

            _result = _client.SearchAsync<CompanySearch>(new SearchRequest()).Result;
        }