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").Create(),
                fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, "dissolved").With(x => x.CompanyType, "private-unlimited").Create(),
                fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, "liquidation").With(x => x.CompanyType, "private-unlimited").Create(),
                fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, "receivership").With(x => x.CompanyType, "private-unlimited").Create(),
                fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, "administration").With(x => x.CompanyType, "private-unlimited").Create(),
                fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, "voluntary-arrangement").With(x => x.CompanyType, "private-unlimited").Create(),
                fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, "converted-closed").With(x => x.CompanyType, "private-unlimited").Create(),
                fixture.Build<CompanyDetails>().With(x => x.CompanyStatus, "insolvency-proceedings").With(x => x.CompanyType, "private-unlimited").Create(),
            };

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

            var resource = new CompanySearchResourceBuilder()
                .AddCompanies(_expectedCompanies)
                .CreateResource(_resourceDetails);

            HttpMessageHandler handler = new StubHttpMessageHandler(uri, resource);
            var httpClientFactory = new Mock<IHttpClientFactory>();
            httpClientFactory.Setup(x => x.CreateHttpClient())
                .Returns(new HttpClient(handler));

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

            _client = new CompaniesHouseSearchCompanyClient(httpClientFactory.Object, uriBuilder.Object);

            _result = _client.SearchCompanyAsync(new CompanySearchRequest()).Result;
        }
예제 #2
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").Create(),
                fixture.Build <CompanyDetails>().With(x => x.CompanyStatus, "dissolved").With(x => x.CompanyType, "private-unlimited").Create(),
                fixture.Build <CompanyDetails>().With(x => x.CompanyStatus, "liquidation").With(x => x.CompanyType, "private-unlimited").Create(),
                fixture.Build <CompanyDetails>().With(x => x.CompanyStatus, "receivership").With(x => x.CompanyType, "private-unlimited").Create(),
                fixture.Build <CompanyDetails>().With(x => x.CompanyStatus, "administration").With(x => x.CompanyType, "private-unlimited").Create(),
                fixture.Build <CompanyDetails>().With(x => x.CompanyStatus, "voluntary-arrangement").With(x => x.CompanyType, "private-unlimited").Create(),
                fixture.Build <CompanyDetails>().With(x => x.CompanyStatus, "converted-closed").With(x => x.CompanyType, "private-unlimited").Create(),
                fixture.Build <CompanyDetails>().With(x => x.CompanyStatus, "insolvency-proceedings").With(x => x.CompanyType, "private-unlimited").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").Create();
            var resource = new CompanySearchResourceBuilder()
                           .AddCompanies(_expectedCompanies)
                           .AddCompanyWithUnknownDateOfCessation(_companyWithUnknownDateOfCessation)
                           .CreateResource(_resourceDetails);

            HttpMessageHandler handler = new StubHttpMessageHandler(uri, resource);
            var httpClientFactory      = new Mock <IHttpClientFactory>();

            httpClientFactory.Setup(x => x.CreateHttpClient())
            .Returns(new HttpClient(handler));

            var uriBuilder = new Mock <ICompanySearchUriBuilder>();

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

            _client = new CompaniesHouseSearchCompanyClient(httpClientFactory.Object, uriBuilder.Object);

            _result = _client.SearchCompanyAsync(new CompanySearchRequest()).Result;
        }