public void GivenACompaniesHouseCompanyProfileClient_WhenGettingACompanyProfile(CompaniesHouseCompanyChargesClientTestCase testCase) { _companyCharges = new CompanyChargesBuilder().Build(testCase); var resource = new CompanyChargesResourceBuilder(_companyCharges) .Create(); var uri = new Uri("https://wibble.com/search/companies"); HttpMessageHandler handler = new StubHttpMessageHandler(uri, resource); var uriBuilder = new Mock <ICompanyChargesUriBuilder>(); uriBuilder.Setup(x => x.Build(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>())) .Returns(uri); var uriItemBuilder = new Mock <IChargeItemUriBuilder>(); uriItemBuilder.Setup(x => x.Build(It.IsAny <string>(), It.IsAny <string>())) .Returns(uri); _client = new CompaniesHouseCompanyChargesClient(new HttpClient(handler), uriBuilder.Object, uriItemBuilder.Object); _result = _client.GetCompanyChargesAsync("abc", 0, 25).Result; _result.Data.ShouldBeEquivalentTo(_companyCharges, options => options.ComparingEnumsByName()); }
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()); }
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()); }
public void GivenACompaniesHouseCompanyProfileClient_WhenGettingACompanyProfile(CompaniesHouseCompanyFilingHistoryClientTestCase testCase) { _companyFilingHistory = new CompanyFilingHistoryBuilder().Build(testCase); var resource = new CompanyFilingHistoryResourceBuilder(_companyFilingHistory) .Create(); var uri = new Uri("https://wibble.com/search/companies"); HttpMessageHandler handler = new StubHttpMessageHandler(uri, resource); var httpClientFactory = new Mock <IHttpClientFactory>(); httpClientFactory.Setup(x => x.CreateHttpClient()) .Returns(new HttpClient(handler)); var uriBuilder = new Mock <ICompanyFilingHistoryUriBuilder>(); uriBuilder.Setup(x => x.Build(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>())) .Returns(uri); _client = new CompaniesHouseCompanyFilingHistoryClient(httpClientFactory.Object, uriBuilder.Object); _result = _client.GetCompanyFilingHistoryAsync("abc", 0, 25).Result; _result.Data.ShouldBeEquivalentTo(_companyFilingHistory); }
public async Task GivenAClient_WhenDownloadingDocument() { var requestUri = new Uri($"https://document-api.companieshouse.gov.uk/document/{DocumentId}/content"); var stubHttpMessageHandler = new StubHttpMessageHandler(requestUri, ExpectedContent, ExpectedMediaType); var mockUriBuilder = new Mock <IDocumentUriBuilder>(); mockUriBuilder.Setup(x => x.Build(DocumentId)).Returns(requestUri); _result = await new CompaniesHouseDocumentDownloadClient(new HttpClient(stubHttpMessageHandler), mockUriBuilder.Object).DownloadDocumentAsync(DocumentId); }
public void GivenACompaniesHouseCompanyProfileClient_WhenGettingACompanyProfile() { _peopleWithSignificantControl = new CompaniesHousePersonsWithSignificantControlBuilder().Build(); var resource = new CompanyPersonsWithSignificantControlResourceBuilder(_peopleWithSignificantControl).Create(); var uri = new Uri("https://wibble.com/search/companies"); HttpMessageHandler handler = new StubHttpMessageHandler(uri, resource); var uriBuilder = new Mock <IPersonsWithSignificantControlUriBuilder>(); uriBuilder.Setup(x => x.Build(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>())) .Returns(uri); var uriIndividualBuilder = new Mock <IPersonsWithSignificantControlIndividualUriBuilder>(); uriIndividualBuilder.Setup(x => x.Build(It.IsAny <string>(), It.IsAny <string>())) .Returns(uri); var uriStatementItemBuilder = new Mock <IPersonsWithSignificantControlStatementItemUriBuilder>(); uriStatementItemBuilder.Setup(x => x.Build(It.IsAny <string>(), It.IsAny <string>())) .Returns(uri); var uriStatementsBuilder = new Mock <IPersonsWithSignificantControlStatementsUriBuilder>(); uriStatementsBuilder.Setup(x => x.Build(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>())) .Returns(uri); var uriSuperSecureBuilder = new Mock <IPersonsWithSignificantControlSuperSecurePersonUriBuilder>(); uriSuperSecureBuilder.Setup(x => x.Build(It.IsAny <string>(), It.IsAny <string>())) .Returns(uri); var uriCorporateBuilder = new Mock <IPersonsWithSignificantControlUriCorporateEntitiesBuilder>(); uriCorporateBuilder.Setup(x => x.Build(It.IsAny <string>(), It.IsAny <string>())) .Returns(uri); var uriLegalPersonBuilder = new Mock <IPersonsWithSignificantControlUriLegalPersonBuilder>(); uriLegalPersonBuilder.Setup(x => x.Build(It.IsAny <string>(), It.IsAny <string>())) .Returns(uri); _client = new CompaniesHousePersonsWithSignificantControlClient(new HttpClient(handler), uriBuilder.Object, uriIndividualBuilder.Object, uriStatementsBuilder.Object, uriStatementItemBuilder.Object, uriSuperSecureBuilder.Object, uriCorporateBuilder.Object, uriLegalPersonBuilder.Object); _result = _client.GetPersonsWithSignificanControlAsync("abc", 0, 25).Result; _result.Data.ShouldBeEquivalentTo(_peopleWithSignificantControl); }
public async Task GivenACompaniesHouseChargesClient_WhenGettingCompanyCharges(CompaniesHouseChargesClientTestCase testCase) { var charges = CompanyChargesBuilder.Create(testCase); var resource = new CompanyChargesResourceBuilder(charges).Create(); var uri = new Uri("https://wibble.com/company/1/charges"); var handler = new StubHttpMessageHandler(uri, resource); var uriBuilder = new Mock <IChargesUriBuilder>(); uriBuilder.Setup(x => x.Build(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>())).Returns(uri); var client = new CompaniesHouseChargesClient(new HttpClient(handler), uriBuilder.Object); var result = await client.GetChargesListAsync("1", 0, 25); result.Data.ShouldBeEquivalentTo(charges); }
public async Task Handler_returns_response_when_request_is_authorized(HttpStatusCode statusCode) { var request = new HttpRequestMessage(HttpMethod.Get, "https://api.guildwars2.com/v2.json"); var stubHttpMessageHandler = new StubHttpMessageHandler(statusCode, @"{ ""success"": true }"); var sut = new UnauthorizedMessageHandler(stubHttpMessageHandler); var httpClient = new HttpClient(sut); var actual = await httpClient.SendAsync(request); Assert.NotNull(actual); Assert.Equal(stubHttpMessageHandler.Code, actual.StatusCode); Assert.Equal(stubHttpMessageHandler.Content, await actual.Content.ReadAsStringAsync()); }
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 async Task GivenACompaniesHouseOffficerAppointmentClient_WhenGettingAnOfficerByAppointmentId(CompaniesHouseOfficerByAppointmentTestCase testCase) { var officersAppointment = OfficerBuilder.Build(testCase); var resource = OfficersResourceBuilder.CreateSingle(officersAppointment); var uri = new Uri("https://wibble.com/company/wobble/registered-office-address"); HttpMessageHandler handler = new StubHttpMessageHandler(uri, resource); var uriBuilder = new Mock <IOfficersAppointmentUriBuilder>(); uriBuilder.Setup(x => x.Build(It.IsAny <string>(), It.IsAny <string>())).Returns(uri); var client = new CompaniesHouseOfficerByByAppointmentClient(new HttpClient(handler), uriBuilder.Object); var result = await client.GetOfficerByAppointmentIdAsync("abc", "1"); result.Data.ShouldBeEquivalentTo(officersAppointment); }
public void GivenACompaniesHouseCompanyProfileClient_WhenGettingACompanyProfile() { _officers = new OfficersBuilder().Build(); var resource = new OfficersResourceBuilder(_officers).Create(); var uri = new Uri("https://wibble.com/search/companies"); HttpMessageHandler handler = new StubHttpMessageHandler(uri, resource); var uriBuilder = new Mock<IOfficersUriBuilder>(); uriBuilder.Setup(x => x.Build(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())) .Returns(uri); _client = new CompaniesHouseOfficersClient(new HttpClient(handler), uriBuilder.Object); _result = _client.GetOfficersAsync("abc", 0, 25).Result; _result.Data.ShouldBeEquivalentTo(_officers); }
public async Task GivenACompaniesHouseCompanyFilingHistoryClient_WhenGettingAFilingHistoryItem(CompaniesHouseCompanyFilingHistoryClientTestCase testCase) { var filingHistory = CompanyFilingHistoryBuilder.BuildOne(testCase); var resource = CompanyFilingHistoryResourceBuilder.CreateOne(filingHistory); var uri = new Uri("https://wibble.com/company/1/filing-history/1"); HttpMessageHandler handler = new StubHttpMessageHandler(uri, resource); var uriBuilder = new Mock <ICompanyFilingHistoryUriBuilder>(); uriBuilder.Setup(x => x.Build(It.IsAny <string>(), It.IsAny <string>())).Returns(uri); var client = new CompaniesHouseCompanyFilingHistoryClient(new HttpClient(handler), uriBuilder.Object); var result = await client.GetFilingHistoryByTransactionAsync("abc", "id1"); result.Data.ShouldBeEquivalentTo(filingHistory); }
public void GivenACompaniesHouseCompanyProfileClient_WhenGettingPersonsWithSignificantControl() { _personsWithSignificantControl = new PersonsWithSignificantControlBuilder().Build(); var resource = new PersonsWithSignificantControlResourceBuilder(_personsWithSignificantControl).Create(); var uri = new Uri("https://wibble.com/search/companies"); HttpMessageHandler handler = new StubHttpMessageHandler(uri, resource); var uriBuilder = new Mock <IPersonsWithSignificantControlBuilder>(); uriBuilder.Setup(x => x.Build(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>())) .Returns(uri); _client = new CompaniesHousePersonsWithSignificantControlClient(new HttpClient(handler), uriBuilder.Object); _result = _client.GetPersonsWithSignificantControlAsync("abc", 0, 25).Result; _result.Data.ShouldBeEquivalentTo(_personsWithSignificantControl); }
public void GivenACompaniesHouseCompanyProfileClient_WhenGettingACompanyProfile(CompaniesHouseCompanyFilingHistoryClientTestCase testCase) { _companyFilingHistory = new CompanyFilingHistoryBuilder().Build(testCase); var resource = new CompanyFilingHistoryResourceBuilder(_companyFilingHistory) .Create(); var uri = new Uri("https://wibble.com/search/companies"); HttpMessageHandler handler = new StubHttpMessageHandler(uri, resource); var uriBuilder = new Mock<ICompanyFilingHistoryUriBuilder>(); uriBuilder.Setup(x => x.Build(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>())) .Returns(uri); _client = new CompaniesHouseCompanyFilingHistoryClient(new HttpClient(handler), uriBuilder.Object); _result = _client.GetCompanyFilingHistoryAsync("abc", 0, 25).Result; _result.Data.ShouldBeEquivalentTo(_companyFilingHistory); }
public void GivenACompaniesHouseCompanyProfileClient_WhenGettingACompanyProfile() { _officers = new OfficersBuilder().Build(); var resource = new OfficersResourceBuilder(_officers).Create(); var uri = new Uri("https://wibble.com/search/companies"); HttpMessageHandler handler = new StubHttpMessageHandler(uri, resource); var uriBuilder = new Mock <IOfficersUriBuilder>(); uriBuilder.Setup(x => x.Build(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>())) .Returns(uri); _client = new CompaniesHouseOfficersClient(new HttpClient(handler), uriBuilder.Object); _result = _client.GetOfficersAsync("abc", 0, 25).Result; _result.Data.ShouldBeEquivalentTo(_officers); }
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; }
public void GivenACompaniesHouseCompanyProfileClient_WhenGettingACompanyProfile(CompaniesHouseCompanyProfileClientTestCase testCase) { _companyProfile = new CompanyProfileBuilder().Build(testCase); var resource = new CompanyProfileResourceBuilder(_companyProfile) .Create(); var uri = new Uri("https://wibble.com/search/companies"); HttpMessageHandler handler = new StubHttpMessageHandler(uri, resource); var uriBuilder = new Mock <ICompanyProfileUriBuilder>(); uriBuilder.Setup(x => x.Build(It.IsAny <string>())) .Returns(uri); _client = new CompaniesHouseCompanyProfileClient(new HttpClient(handler), uriBuilder.Object); _result = _client.GetCompanyProfileAsync("abc").Result; _result.Data.ShouldBeEquivalentTo(_companyProfile); }
public async Task GivenACompaniesHouseRegistereOfficeAddressClient_WhenGettingARegisteredOfficeAddress(CompaniesHouseRegisteredOfficeAddressTestCase testCase) { var registeredOfficeAddress = RegisteredOfficeAddressBuilder.Build(testCase); var resource = new RegisteredOfficeAddressResourceBuilder(registeredOfficeAddress).Create(); var uri = new Uri("https://wibble.com/company/wobble/registered-office-address"); HttpMessageHandler handler = new StubHttpMessageHandler(uri, resource); var uriBuilder = new Mock <IRegisteredOfficeAddressUriBuilder>(); uriBuilder.Setup(x => x.Build(It.IsAny <string>())).Returns(uri); var client = new CompaniesHouseRegisteredOfficeAddressClient(new HttpClient(handler), uriBuilder.Object); var result = await client.GetRegisteredOfficeAddress("abc"); result.Data.ShouldBeEquivalentTo(registeredOfficeAddress, opt => opt.Excluding(x => x.Country)); result.Data.Country.GetEnumMemberValue().Should().Be(registeredOfficeAddress.Country); }