public void ShouldSeeAFrameworkIsMissing() { //Arrange const string frameworkId = "1-2-3"; MockProviderService .UponReceiving($"a request to retrieve framework with id '{frameworkId}'") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = $"/frameworks/{frameworkId}", Headers = new Dictionary <string, string> { { "Accept", "application/json" } } }) .WillRespondWith(new ProviderServiceResponse { Status = 404 }); var consumer = new FrameworkApiClient(MockProviderServiceBaseUri); //Act Assert.Throws <EntityNotFoundException>(() => consumer.Get(frameworkId)); MockProviderService.VerifyInteractions(); }
public void GetThing_WhenTheThingExists_ReturnTheThing() { MockProviderService.Given("There is a thing") .UponReceiving("A GET request to retrieve the thing") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = "/api/values/", Headers = new Dictionary <string, object> { { "Accept", "application/json" } } //Query = "" }) .WillRespondWith(new ProviderServiceResponse { Status = 200, Headers = new Dictionary <string, object> { { "Content-Type", "application/json; charset=utf-8" } }, Body = new //NOTE: Note the case sensitivity here, the body will be serialised as per the casing defined { value1 = "value1", value2 = "value2" } }); //NOTE: WillRespondWith call must come last as it will register the interaction var response = ApiTestClient.MakeRequest(HttpMethod.Get, "http://localhost:9222/api/values"); var content = ApiTestClient.HttpResponseToString(response); Assert.IsNotNull(content); }
public void ShouldGetProviderViewModel() { // Arrange. var providerProvider = GetProviderProvider(); var provider = new Fixture() .Create <Provider>(); MockProviderService.Setup(mock => mock.GetProvider(provider.Ukprn, true)) .Returns(provider); var providerSites = new Fixture() .Build <ProviderSite>() .CreateMany(5) .ToArray(); MockProviderService.Setup(mock => mock.GetProviderSites(provider.Ukprn)) .Returns(providerSites); // Act. var viewModel = providerProvider.GetProviderViewModel(provider.Ukprn); // Assert. viewModel.Should().NotBeNull(); viewModel.ProviderId.Should().Be(provider.ProviderId); viewModel.FullName.Should().Be(provider.FullName); viewModel.TradingName.Should().Be(provider.TradingName); viewModel.IsMigrated.Should().Be(provider.IsMigrated); viewModel.ProviderSiteViewModels.Should().NotBeNull(); viewModel.ProviderSiteViewModels.Count().Should().Be(providerSites.Length); }
public void ShouldAssignLocalAuthorityCodeOnUpdatingVacancyLocationsWithMultipleAddresses() { // Arrange. var geopoint = new Fixture().Create <GeoPoint>(); var geopoint2 = new Fixture().Create <GeoPoint>(); var addressViewModel = new Fixture().Build <AddressViewModel>().Create(); var postalAddress = new Fixture().Build <PostalAddress>().With(a => a.GeoPoint, geopoint).Create(); var postalAddress2 = new Fixture().Build <PostalAddress>().With(a => a.GeoPoint, geopoint2).Create(); MockGeocodeService.Setup(gs => gs.GetGeoPointFor(It.IsAny <PostalAddress>())).Returns(geopoint); var locationSearchViewModel = new LocationSearchViewModel { EmployerId = EmployerId, ProviderSiteId = ProviderSiteId, EmployerEdsUrn = EdsUrn, Addresses = new List <VacancyLocationAddressViewModel> { new VacancyLocationAddressViewModel { Address = addressViewModel }, new VacancyLocationAddressViewModel { Address = addressViewModel } } }; var vacancyLocations = new List <VacancyLocation> { new VacancyLocation { Address = postalAddress }, new VacancyLocation { Address = postalAddress2 } }; MockMapper.Setup(m => m.Map <VacancyLocationAddressViewModel, VacancyLocation>(locationSearchViewModel.Addresses[0])).Returns(vacancyLocations[0]); MockMapper.Setup(m => m.Map <VacancyLocationAddressViewModel, VacancyLocation>(locationSearchViewModel.Addresses[1])).Returns(vacancyLocations[1]); MockVacancyPostingService.Setup(v => v.CreateVacancy(It.IsAny <Vacancy>())) .Returns(new Vacancy()); var vacancy = new Fixture().Create <Vacancy>(); MockVacancyPostingService.Setup(s => s.GetVacancyByReferenceNumber(It.IsAny <int>())) .Returns(vacancy); MockProviderService.Setup(s => s.GetProvider(Ukprn, true)).Returns(new Provider()); var provider = GetVacancyPostingProvider(); // Act. provider.AddLocations(locationSearchViewModel); // Assert. MockVacancyPostingService.Verify(m => m.UpdateVacancy(It.IsAny <Vacancy>()), Times.Once); MockLocalAuthorityLookupService.Verify(m => m.GetLocalAuthorityCode(It.IsAny <string>()), Times.Exactly(2)); MockVacancyPostingService.Verify(m => m.DeleteVacancyLocationsFor(vacancy.VacancyId)); MockVacancyPostingService.Verify(m => m.CreateVacancyLocations(It.IsAny <List <VacancyLocation> >()), Times.Once); }
public void ShouldIncrementSubmissionCountWhenSumbittingTheVacancy() { var vacancyPostingProvider = GetVacancyPostingProvider(); const int referenceNumber = 1; var apprenticeshipVacancy = new Vacancy { VacancyOwnerRelationshipId = 42, IsEmployerLocationMainApprenticeshipLocation = true, SubmissionCount = 2 }; MockVacancyPostingService.Setup(ps => ps.GetVacancyByReferenceNumber(It.IsAny <int>())).Returns(apprenticeshipVacancy); MockVacancyPostingService.Setup(ps => ps.UpdateVacancy(It.IsAny <Vacancy>())) .Returns(apprenticeshipVacancy); MockProviderService.Setup(ps => ps.GetProviderSite(It.IsAny <string>())) .Returns(new ProviderSite { Address = new PostalAddress() }); MockReferenceDataService.Setup(ds => ds.GetSubCategoryByCode(It.IsAny <string>())).Returns(Category.EmptyFramework); vacancyPostingProvider.SubmitVacancy(referenceNumber); MockVacancyPostingService.Verify( ps => ps.UpdateVacancy( It.Is <Vacancy>(v => v.SubmissionCount == 3))); }
public void ShouldSeeaStandardIsMissing() { //Arrange const string standardCode = "-1"; MockProviderService .UponReceiving($"a request to retrieve standard with id '{standardCode}'") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = $"/standards/{standardCode}", Headers = new Dictionary <string, string> { { "Accept", "application/json" } } }) .WillRespondWith(new ProviderServiceResponse { Status = 404 }); var consumer = new StandardApiClient(MockProviderServiceBaseUri); //Act Assert.Throws <EntityNotFoundException>(() => consumer.Get(standardCode)); MockProviderService.VerifyInteractions(); }
public async Task GivenAPort_MockProviderHosts() { var mockProvider = new MockProviderService(port); HttpClient client = new HttpClient(); var response = await client.GetAsync($"http://localhost:{port}/"); Assert.That(response.StatusCode == HttpStatusCode.NotFound); }
public void SetUp() { MockProviderService .Setup(mock => mock.GetVacancyOwnerRelationship(VacancyOwnerRelationshipId, true)) .Returns(VacancyOwnerRelationship); MockEmployerService.Setup(s => s.GetEmployer(VacancyOwnerRelationship.EmployerId, true)) .Returns(new Fixture().Build <Employer>().Create()); }
public void ShouldAssignLocalAuthorityCodeOnUpdatingVacancyLocationsWithSingleAddressDifferentToEmployer() { // Arrange. const string localAuthorityCode = "ABCD"; var geopoint = new Fixture().Create <GeoPoint>(); var addressViewModel = new Fixture().Build <AddressViewModel>().Create(); var postalAddress = new Fixture().Build <PostalAddress>().With(a => a.GeoPoint, geopoint).Create(); MockGeocodeService.Setup(gs => gs.GetGeoPointFor(It.IsAny <PostalAddress>())).Returns(geopoint); var locationSearchViewModel = new LocationSearchViewModel { EmployerId = EmployerId, ProviderSiteId = ProviderSiteId, EmployerEdsUrn = EdsUrn, Addresses = new List <VacancyLocationAddressViewModel>() { new VacancyLocationAddressViewModel() { Address = addressViewModel } } }; MockMapper.Setup( m => m.Map <VacancyLocationAddressViewModel, VacancyLocation>(It.IsAny <VacancyLocationAddressViewModel>())) .Returns(new VacancyLocation { Address = postalAddress }); MockMapper.Setup(m => m.Map <AddressViewModel, PostalAddress>(addressViewModel)).Returns(postalAddress); var geoPointViewModel = new Fixture().Create <GeoPointViewModel>(); MockMapper.Setup(m => m.Map <GeoPoint, GeoPointViewModel>(geopoint)) .Returns(geoPointViewModel); MockMapper.Setup(m => m.Map <GeoPointViewModel, GeoPoint>(geoPointViewModel)).Returns(geopoint); MockLocalAuthorityLookupService.Setup(m => m.GetLocalAuthorityCode(It.IsAny <string>())) .Returns(localAuthorityCode); var vacancy = new Fixture().Create <Vacancy>(); MockVacancyPostingService.Setup(s => s.GetVacancyByReferenceNumber(It.IsAny <int>())) .Returns(vacancy); MockProviderService.Setup(s => s.GetProvider(Ukprn, true)).Returns(new Provider()); var provider = GetVacancyPostingProvider(); // Act. provider.AddLocations(locationSearchViewModel); // Assert. MockLocalAuthorityLookupService.Verify(m => m.GetLocalAuthorityCode(It.IsAny <string>()), Times.Once); MockVacancyPostingService.Verify(m => m.UpdateVacancy(It.Is <Vacancy>(av => av.LocalAuthorityCode == localAuthorityCode))); MockVacancyPostingService.Verify(m => m.UpdateVacancy(It.IsAny <Vacancy>()), Times.Once); }
public void ShoulReturnEmployersForNameAndLocationEmployerSearchViewModel(int unactivatedEmployerCount) { // Arrange. var searchViewModel = new EmployerSearchViewModel { FilterType = EmployerFilterType.NameAndLocation, ProviderSiteId = 42, Name = "a", Location = "b", Employers = new PageableViewModel <EmployerViewModel> { CurrentPage = 3 } }; var employers = new Fixture() .CreateMany <Employer>(PageSize) .ToArray(); var vacancyParties = BuildFakeVacancyParties(employers, unactivatedEmployerCount); var pageableVacancyParties = new Fixture() .Build <Pageable <VacancyOwnerRelationship> >() .With(each => each.Page, vacancyParties) .Create(); Expression <Func <EmployerSearchRequest, bool> > matchingSearchRequest = it => it.ProviderSiteId == searchViewModel.ProviderSiteId; MockProviderService.Setup(mock => mock .GetVacancyOwnerRelationships(It.Is(matchingSearchRequest), searchViewModel.Employers.CurrentPage, PageSize)) .Returns(pageableVacancyParties); Expression <Func <IEnumerable <int>, bool> > matchingEmployerIds = it => true; MockEmployerService.Setup(mock => mock .GetEmployers(It.Is(matchingEmployerIds), It.IsAny <bool>())) .Returns(employers); var provider = GetProviderProvider(); // Act. var viewModel = provider.GetVacancyOwnerRelationshipViewModels(searchViewModel); // Assert. viewModel.Should().NotBeNull(); viewModel.ProviderSiteId.Should().Be(searchViewModel.ProviderSiteId); viewModel.Employers.Should().NotBeNull(); viewModel.Employers.Page.Count().Should().Be(PageSize - unactivatedEmployerCount); viewModel.FilterType.Should().Be(EmployerFilterType.NameAndLocation); viewModel.Name.Should().NotBeEmpty(); viewModel.Location.Should().NotBeEmpty(); }
public void SetUp() { _validNewVacancyViewModelWithReferenceNumber = new NewVacancyViewModel() { VacancyReferenceNumber = 1, OfflineVacancy = false, VacancyOwnerRelationship = new VacancyOwnerRelationshipViewModel() }; MockVacancyPostingService.Setup(mock => mock.GetVacancyByReferenceNumber(_validNewVacancyViewModelWithReferenceNumber.VacancyReferenceNumber.Value)) .Returns(_existingVacancy); MockVacancyPostingService.Setup(mock => mock.CreateVacancy(It.IsAny <Vacancy>())) .Returns <Vacancy>(v => v); MockReferenceDataService.Setup(mock => mock.GetSectors()) .Returns(new List <Sector> { new Sector { Id = 1, Standards = new List <Standard> { new Standard { Id = 1, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Intermediate }, new Standard { Id = 2, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Advanced }, new Standard { Id = 3, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Higher }, new Standard { Id = 4, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.FoundationDegree }, new Standard { Id = 5, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Degree }, new Standard { Id = 6, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Masters } } } }); MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(ProviderSiteId, EdsUrn)) .Returns(_vacancyOwnerRelationship); MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(VacancyOwnerRelationshipId, true)) .Returns(_vacancyOwnerRelationship); MockProviderService.Setup(s => s.GetProvider(Ukprn, true)) .Returns(new Provider()); MockEmployerService.Setup(s => s.GetEmployer(EmployerId, It.IsAny <bool>())).Returns(new Fixture().Build <Employer>().Create()); MockMapper.Setup(m => m.Map <Vacancy, NewVacancyViewModel>(It.IsAny <Vacancy>())) .Returns(new NewVacancyViewModel()); }
public void GivenAPartialContract_AndAttemptToStartAnother_ItThrowsException() { var mockProvider = new MockProviderService(port); mockProvider.Given("Test1"); Assert.Throws <Exception>(() => mockProvider.Given("Test2")); mockProvider.UponReceiving("A Request"); Assert.Throws <Exception>(() => mockProvider.Given("A Request 2")); }
public async Task GetEtaForNextTrip_ReturnsExpectedTripInformation() { // /eta/routeName/direction/stopName // Arrange string routeName = "20"; string direction = "Northbound"; string stopName = "Opera"; var busId = 99999; var eta = 5; var busIdRegex = "^[1-9]{1,5}$"; // All positive integers between 1 and 99999 var etaIdRegex = "^[0-9]{0,2}$"; // All positive integers between 0 and 99 var expectedBusInfo = new { busID = Match.Type(busId), eta = Match.Type(eta), }; MockProviderService .Given($"There are buses scheduled for route {routeName} and direction {direction} to arrive at stop {stopName}") // Describe the state the provider needs to setup .UponReceiving($"A request for eta for route {routeName} to {stopName} station") // textual description - business case .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = Uri.EscapeUriString($"/eta/{routeName}/{direction}/{stopName}"), }) .WillRespondWith(new ProviderServiceResponse { Status = 200, Headers = new Dictionary <string, object> { { "Content-Type", "application/json; charset=utf-8" } }, Body = expectedBusInfo }); var consumer = new BusServiceClient(MockServerBaseUri); // Act var result = await consumer.GetBusInfo(routeName, direction, stopName); // Assert Assert.That(result.BusID.ToString(), Does.Match(busIdRegex)); Assert.That(result.Eta.ToString(), Does.Match(etaIdRegex)); // NOTE: Verifies that interactions registered on the mock provider are called at least once MockProviderService.VerifyInteractions(); }
public void CreateVacancyShouldGeoCodeTheEmpoyersAddressIfTheGeoPointIsInvalid() { const int vacancyOwnerRelationshipId = 1; const int employerId = 2; const string ukprn = "1234"; const string employersPostcode = "cv1 9SX"; var vacancyGuid = Guid.NewGuid(); const int vacancyReferenceNumber = 123456; const bool isEmployerLocationMainApprenticeshipLocation = true; int? numberOfPositions = 2; var address = new Fixture().Build <PostalAddress>() .With(a => a.Postcode, employersPostcode) .With(a => a.GeoPoint, null) .Create(); const int providerId = 4; const string localAuthorityCode = "lac"; // Arrange. MockVacancyPostingService.Setup(s => s.GetNextVacancyReferenceNumber()).Returns(vacancyReferenceNumber); MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(vacancyOwnerRelationshipId, true)) .Returns( new Fixture().Build <VacancyOwnerRelationship>() .With(v => v.VacancyOwnerRelationshipId, vacancyOwnerRelationshipId) .With(v => v.EmployerId, employerId) .Create()); MockEmployerService.Setup(s => s.GetEmployer(employerId, It.IsAny <bool>())) .Returns( new Fixture().Build <Employer>() .With(e => e.EmployerId, employerId) .With(e => e.Address, address) .Create()); MockProviderService.Setup(s => s.GetProvider(ukprn, true)) .Returns(new Fixture().Build <Provider>().With(p => p.ProviderId, providerId).Create()); MockLocalAuthorityService.Setup(s => s.GetLocalAuthorityCode(employersPostcode)).Returns(localAuthorityCode); // Act. var provider = GetVacancyPostingProvider(); provider.CreateVacancy(new VacancyMinimumData { IsEmployerLocationMainApprenticeshipLocation = isEmployerLocationMainApprenticeshipLocation, VacancyGuid = vacancyGuid, VacancyOwnerRelationshipId = vacancyOwnerRelationshipId, Ukprn = ukprn, NumberOfPositions = numberOfPositions }); // Assert. MockGeoCodingService.Verify(s => s.GetGeoPointFor(address)); }
public void GivenAContractWithoutRequest_AndAttemptToComplete_ItThrowsException() { var mockProvider = new MockProviderService(port); mockProvider.Given("A Test"); Assert.Throws <Exception>(() => mockProvider.WillRespondWith(new ContractResponse() { StatusCode = HttpStatusCode.Accepted })); }
public void ShouldUpdateVacancyProviderSiteEmployerLinkIfTheVacancyAlreadyExists() { // Arrange var vacancyGuid = Guid.NewGuid(); var apprenticeshipVacancy = new Vacancy(); var vacancyOwnerRelationshipId = 42; var providerSiteId = 1; var employerId = 2; var edsErn = "232"; var vacancyOwnerRelationship = new VacancyOwnerRelationship { VacancyOwnerRelationshipId = vacancyOwnerRelationshipId, ProviderSiteId = providerSiteId, EmployerId = employerId, EmployerDescription = "Description", EmployerWebsiteUrl = "Url" }; MockVacancyPostingService.Setup(s => s.GetVacancy(vacancyGuid)).Returns(apprenticeshipVacancy); MockProviderService.Setup(s => s.SaveVacancyOwnerRelationship(vacancyOwnerRelationship)) .Returns(vacancyOwnerRelationship); MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(providerSiteId, edsErn)) .Returns(vacancyOwnerRelationship); MockEmployerService.Setup(s => s.GetEmployer(employerId, It.IsAny <bool>())) .Returns(new Fixture().Build <Employer>().With(e => e.EmployerId, employerId).Create()); var provider = GetProviderProvider(); // Act provider.ConfirmVacancyOwnerRelationship(new VacancyOwnerRelationshipViewModel { ProviderSiteId = providerSiteId, Employer = new EmployerViewModel { EmployerId = employerId, EdsUrn = edsErn, Address = new AddressViewModel() }, VacancyGuid = vacancyGuid, IsEmployerLocationMainApprenticeshipLocation = true, NumberOfPositions = 4 }); // Assert MockVacancyPostingService.Verify(s => s.GetVacancy(vacancyGuid), Times.Once); MockProviderService.Verify(s => s.SaveVacancyOwnerRelationship(vacancyOwnerRelationship), Times.Once); MockVacancyPostingService.Verify( s => s.UpdateVacancy( It.Is <Vacancy>(v => v.VacancyOwnerRelationshipId == vacancyOwnerRelationshipId)), Times.Once); }
public void SetUp() { _validVacancyMinimumDataSansReferenceNumber = new VacancyMinimumData { VacancyOwnerRelationshipId = VacancyOwnerRelationshipId }; _validNewVacancyViewModelSansReferenceNumber = new NewVacancyViewModel { VacancyOwnerRelationship = new VacancyOwnerRelationshipViewModel() { VacancyOwnerRelationshipId = VacancyOwnerRelationshipId, ProviderSiteId = ProviderSiteId, Employer = new EmployerViewModel { EmployerId = EmployerId, EdsUrn = EdsUrn, Address = new AddressViewModel() } }, OfflineVacancy = false, }; _validNewVacancyViewModelWithReferenceNumber = new NewVacancyViewModel { VacancyOwnerRelationship = new VacancyOwnerRelationshipViewModel() { VacancyOwnerRelationshipId = VacancyOwnerRelationshipId, ProviderSiteId = ProviderSiteId, Employer = new EmployerViewModel { EmployerId = EmployerId, EdsUrn = EdsUrn, Address = new AddressViewModel() } }, OfflineVacancy = false, VacancyReferenceNumber = 1, VacancyGuid = Guid.NewGuid() }; MockVacancyPostingService.Setup(mock => mock.CreateVacancy(It.IsAny <Vacancy>())) .Returns <Vacancy>(v => v); MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(ProviderSiteId, EdsUrn)) .Returns(_vacancyOwnerRelationship); MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(VacancyOwnerRelationshipId, true)) .Returns(_vacancyOwnerRelationship); MockEmployerService.Setup(s => s.GetEmployer(EmployerId, true)).Returns(new Fixture().Build <Employer>().Create()); }
public void ShouldDefaultToPreferredSite() { // Arrange. var provider = GetVacancyPostingProvider(); // Act. var viewModel = provider.GetNewVacancyViewModel(VacancyOwnerRelationshipId, VacancyGuid, null); // Assert. MockProviderService.Verify(mock => mock.GetVacancyOwnerRelationship(VacancyOwnerRelationshipId, true), Times.Once); MockEmployerService.Verify(s => s.GetEmployer(EmployerId, true), Times.Once); viewModel.Should().NotBeNull(); viewModel.VacancyOwnerRelationship.ProviderSiteId.Should().Be(ProviderSiteId); }
public void SetUp() { MockVacancyPostingService.Setup(mock => mock.GetVacancyByReferenceNumber(It.IsAny <int>())) .Returns(_existingVacancy); MockVacancyPostingService.Setup(mock => mock.CreateVacancy(It.IsAny <Vacancy>())) .Returns <Vacancy>(v => v); MockReferenceDataService.Setup(mock => mock.GetSectors()) .Returns(new List <Sector> { new Sector { Id = 1, Standards = new List <Standard> { new Standard { Id = 1, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Intermediate }, new Standard { Id = 2, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Advanced }, new Standard { Id = 3, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Higher }, new Standard { Id = 4, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.FoundationDegree }, new Standard { Id = 5, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Degree }, new Standard { Id = 6, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Masters } } } }); MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(ProviderSiteId, EdsUrn)) .Returns(_vacancyOwnerRelationship); MockConfigurationService .Setup(mock => mock.Get <CommonWebConfiguration>()) .Returns(_webConfiguration); MockReferenceDataService .Setup(mock => mock.GetCategories()) .Returns(_categories); }
public async Task GivenAContract_AndItsRequested_TheProviderReturnsTheResponse() { var mockProvider = new MockProviderService(port); mockProvider.Given("A Test").UponReceiving("A Scenario").With(new ContractRequest() { Url = "/1234", Method = "GET" }).WillRespondWith(new ContractResponse() { StatusCode = HttpStatusCode.OK }); HttpClient client = new HttpClient(); var response = await client.GetAsync($"http://localhost:{port}/1234"); Assert.That(response.StatusCode == HttpStatusCode.OK); }
public void AddInteraction(ProviderServiceInteraction PSI) { MockProviderService .Given(PSI.ProviderState) .UponReceiving(PSI.Description) .With(new ProviderServiceRequest { Method = PSI.Request.Method, Path = PSI.Request.Path, Headers = PSI.Request.Headers, Body = PSI.Request.Body }) .WillRespondWith(new ProviderServiceResponse { Status = PSI.Response.Status, Headers = PSI.Response.Headers, Body = PSI.Response.Body }); }
public void ShoulReturnEmployersForProviderSite(int unactivatedEmployerCount) { // Arrange. const int pageNumber = 1; const int providerSiteId = 42; var employers = new Fixture() .CreateMany <Employer>(PageSize) .ToArray(); var vacancyParties = BuildFakeVacancyParties(employers, unactivatedEmployerCount); var pageableVacancyParties = new Fixture() .Build <Pageable <VacancyOwnerRelationship> >() .With(each => each.Page, vacancyParties) .Create(); Expression <Func <EmployerSearchRequest, bool> > matchingSearchRequest = it => it.ProviderSiteId == providerSiteId; MockProviderService.Setup(mock => mock .GetVacancyOwnerRelationships(It.Is(matchingSearchRequest), pageNumber, PageSize)) .Returns(pageableVacancyParties); Expression <Func <IEnumerable <int>, bool> > matchingEmployerIds = it => true; MockEmployerService.Setup(mock => mock .GetEmployers(It.Is(matchingEmployerIds), It.IsAny <bool>())) .Returns(employers); var provider = GetProviderProvider(); // Act. var viewModel = provider.GetVacancyOwnerRelationshipViewModels(providerSiteId); // Assert. viewModel.Should().NotBeNull(); viewModel.ProviderSiteId.Should().Be(providerSiteId); viewModel.Employers.Should().NotBeNull(); viewModel.Employers.Page.Count().Should().Be(PageSize - unactivatedEmployerCount); }
public void WhenCreatingANewVacancyShouldReturnANewLocationSearchViewModel() { const string ukprn = "ukprn"; const int employerId = 1; const int providerSiteId = 42; var provider = GetVacancyPostingProvider(); MockProviderService.Setup(s => s.GetProviderSite(providerSiteId)) .Returns(new Fixture().Build <ProviderSite>().With(ps => ps.ProviderSiteId, providerSiteId).Create()); MockEmployerService.Setup(s => s.GetEmployer(employerId, It.IsAny <bool>())) .Returns(new Fixture().Build <Employer>().With(e => e.EmployerId, employerId).Create()); var result = provider.LocationAddressesViewModel(ukprn, providerSiteId, employerId, _vacancyGuid); result.Ukprn.Should().Be(ukprn); result.EmployerId.Should().Be(employerId); result.ProviderSiteId.Should().Be(providerSiteId); result.VacancyGuid.Should().Be(_vacancyGuid); result.Addresses.Should().HaveCount(0); }
public void GivenAContractToBuild_ItIsInTheStore() { var mockProvider = new MockProviderService(port); mockProvider.Given("A Test").UponReceiving("A Request").With(new ContractRequest() { Method = "Get", Url = "/1234" }).WillRespondWith(new ContractResponse() { StatusCode = HttpStatusCode.OK }); var contractFromStore = mockProvider.GetContracts().FirstOrDefault(c => c.Name == "A Test"); Assert.NotNull(contractFromStore); Assert.AreEqual("A Test", contractFromStore.Name); Assert.AreEqual("A Request", contractFromStore.Scenario); Assert.AreEqual("Get", contractFromStore.Request.Method); Assert.AreEqual("/1234", contractFromStore.Request.Url); Assert.AreEqual(HttpStatusCode.OK, contractFromStore.Response.StatusCode); }
public void ShouldAssignLocalAuthorityCodeToVacancyWithSameAddressAsEmployer() { // Arrange. const string localAuthorityCode = "ABCD"; var vvm = new Fixture().Build <NewVacancyViewModel>().Create(); var employerWithGeocode = new Fixture().Create <Employer>(); MockMapper.Setup(m => m.Map <Vacancy, NewVacancyViewModel>(It.IsAny <Vacancy>())).Returns(vvm); MockEmployerService.Setup(m => m.GetEmployer(It.IsAny <int>(), It.IsAny <bool>())).Returns(employerWithGeocode); MockLocalAuthorityLookupService.Setup(m => m.GetLocalAuthorityCode(employerWithGeocode.Address.Postcode)).Returns(localAuthorityCode); MockProviderService.Setup(s => s.GetProvider(Ukprn, true)).Returns(new Provider()); MockVacancyPostingService.Setup(s => s.GetVacancy(It.IsAny <Guid>())).Returns(new Fixture().Create <Vacancy>()); var provider = GetVacancyPostingProvider(); // Act. provider.UpdateVacancy(_validVacancyMinimumDataSansReferenceNumber); // Assert. MockLocalAuthorityLookupService.Verify(m => m.GetLocalAuthorityCode(employerWithGeocode.Address.Postcode), Times.Once); MockVacancyPostingService.Verify(s => s.UpdateVacancy(It.Is <Vacancy>(v => v.LocalAuthorityCode == localAuthorityCode)), Times.Once); }
public void ShouldGetaStandard() { //Arrange const string standardCode = "12"; MockProviderService .UponReceiving($"a request to retrieve standard with id '{standardCode}'") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = $"/standards/{standardCode}", Headers = new Dictionary <string, string> { { "Accept", "application/json" } } }) .WillRespondWith(new ProviderServiceResponse { Status = 200, Headers = new Dictionary <string, string> { { "Content-Type", "application/json; charset=utf-8" } }, Body = new { StandardId = standardCode } }); var consumer = new StandardApiClient(MockProviderServiceBaseUri); //Act var result = consumer.Get(standardCode); // TODO is this needed? //Assert Assert.AreEqual(standardCode, result.StandardId); MockProviderService.VerifyInteractions(); }
public void ShouldGetFramework() { //Arrange const string frameworkId = "403-2-1"; MockProviderService .UponReceiving($"a request to retrieve framework with id '{frameworkId}'") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = $"/frameworks/{frameworkId}", Headers = new Dictionary <string, string> { { "Accept", "application/json" } } }) .WillRespondWith(new ProviderServiceResponse { Status = 200, Headers = new Dictionary <string, string> { { "Content-Type", "application/json; charset=utf-8" } }, Body = new { FrameworkId = frameworkId } }); var consumer = new FrameworkApiClient(MockProviderServiceBaseUri); //Act var result = consumer.Get(frameworkId); // TODO is this needed? //Assert Assert.AreEqual(frameworkId, result.FrameworkId); MockProviderService.VerifyInteractions(); }
public void ShouldReturnANewVacancyIfVacancyGuidDoesNotExists() { // Arrange var vacancyGuid = Guid.NewGuid(); Vacancy vacancy = null; MockVacancyPostingService.Setup(s => s.GetVacancy(vacancyGuid)).Returns(vacancy); var provider = GetVacancyPostingProvider(); // Act var result = provider.GetNewVacancyViewModel(VacancyOwnerRelationshipId, vacancyGuid, null); // Assert MockVacancyPostingService.Verify(s => s.GetVacancy(vacancyGuid), Times.Once); MockProviderService.Verify(s => s.GetVacancyOwnerRelationship(VacancyOwnerRelationshipId, true), Times.Once); MockEmployerService.Verify(s => s.GetEmployer(EmployerId, It.IsAny <bool>()), Times.Once); result.Should() .Match <NewVacancyViewModel>( r => r.VacancyOwnerRelationship.EmployerDescription == _vacancyOwnerRelationship.EmployerDescription && r.VacancyOwnerRelationship.ProviderSiteId == ProviderSiteId); }
public async Task GetProduct_ReturnsExpectedProduct() { var guidRegex = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"; var expectedProductId = Guid.Parse("E0C2E684-D83F-45C3-A6E5-D62A6F83A0BD"); var expectedName = "Test"; var expectedProduct = new { id = Match.Regex(expectedProductId.ToString(), $"^{guidRegex}$"), name = Match.Type(expectedName), description = Match.Type("A product for testing"), }; MockProviderService .Given("A Product with expected structure") // Describe the state the provider needs to setup .UponReceiving("a GET request for a single product") // textual description - business case .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = Match.Regex($"/{expectedProductId}", $"^\\/{guidRegex}$"), }) .WillRespondWith(new ProviderServiceResponse { Status = 200, Headers = new Dictionary <string, object> { { "Content-Type", "application/json; charset=utf-8" } }, Body = expectedProduct }); var consumer = new ProductClient(MockServerBaseUri); var result = await consumer.Get(expectedProductId); Assert.AreEqual(expectedProductId, result.Id); Assert.AreEqual(expectedName, result.Name); MockProviderService.VerifyInteractions(); }
public void ShouldUpdateIfVacancyReferenceIsPresent() { // Arrange. var vvm = new Fixture().Build <NewVacancyViewModel>().Create(); MockMapper.Setup(m => m.Map <Vacancy, NewVacancyViewModel>(It.IsAny <Vacancy>())).Returns(vvm); MockProviderService.Setup(m => m.GetVacancyOwnerRelationship(It.IsAny <int>(), true)).Returns(new VacancyOwnerRelationship()); MockEmployerService.Setup(m => m.GetEmployer(It.IsAny <int>(), It.IsAny <bool>())).Returns(new Fixture().Create <Employer>()); var provider = GetVacancyPostingProvider(); // Act. var viewModel = provider.UpdateVacancy(_validNewVacancyViewModelWithReferenceNumber); // Assert. MockVacancyPostingService.Verify(mock => mock.GetVacancyByReferenceNumber(_validNewVacancyViewModelWithReferenceNumber.VacancyReferenceNumber.Value), Times.Once); MockVacancyPostingService.Verify(mock => mock.GetNextVacancyReferenceNumber(), Times.Never); MockVacancyPostingService.Verify(mock => mock.UpdateVacancy(It.IsAny <Vacancy>()), Times.Once); viewModel.VacancyReferenceNumber.Should().HaveValue(); }