public async Task GetServicesBySearchParamsReturnServicesIfMatchedToSynonymGroup() { var synonymGroup1 = EntityHelpers.CreateSynonymGroupWithWords(5); var synonymGroup2 = EntityHelpers.CreateSynonymGroupWithWords(3); synonymGroup2.SynonymWords.ToList()[1].Word = synonymGroup1.SynonymWords.ToList()[1].Word; var services = EntityHelpers.CreateServices(); var serviceToFind1 = EntityHelpers.CreateService(); var serviceToFind2 = EntityHelpers.CreateService(); var searchTerm = synonymGroup1.SynonymWords.ToList()[1].Word; serviceToFind1.Name += synonymGroup1.SynonymWords.ToList()[4].Word; serviceToFind2.Name += synonymGroup2.SynonymWords.ToList()[2].Word; DatabaseContext.SynonymGroups.Add(synonymGroup1); DatabaseContext.SynonymGroups.Add(synonymGroup2); DatabaseContext.Services.AddRange(services); DatabaseContext.Services.Add(serviceToFind1); DatabaseContext.Services.Add(serviceToFind2); DatabaseContext.SaveChanges(); var requestUri = new Uri($"api/v1/services?search={searchTerm}", UriKind.Relative); var response = Client.GetAsync(requestUri).Result; response.StatusCode.Should().Be(200); var content = response.Content; var stringContent = await content.ReadAsStringAsync().ConfigureAwait(false); var deserializedBody = JsonConvert.DeserializeObject <GetServiceResponseList>(stringContent); deserializedBody.Services.Count.Should().Be(2); }
[TestCase(TestName = "When SearchService Service controller method is called, Then it returns all ACTIVE services")] // ignores deleted ones // Assuming no default pagination - there's none yet public void SearchServiceEndpointReturnsAllActiveServices() // behaviour does not depend on filters { // arrange var services = EntityHelpers.CreateServices(10).ToList(); //List<ServiceEntity> expectedData = services.Select(s => s.ToDomain()).ToList(); var deletedService = EntityHelpers.CreateService(); deletedService.Status = "deleted"; deletedService.OrganizationId = null; deletedService.Organization = null; services.Add(deletedService); // added 11th service (broken) DatabaseContext.Services.AddRange(services); DatabaseContext.SaveChanges(); // act var gatewayResult = _classUnderTest.SearchServices(new SearchServicesRequest()); var fullMatches = gatewayResult.FullMatchServices; var splitMatches = gatewayResult.SplitMatchServices; var returnedServices = fullMatches.Concat(splitMatches).ToList(); // assert gatewayResult.Should().NotBeNull(); fullMatches.Should().NotBeNull(); splitMatches.Should().NotBeNull(); fullMatches.Should().BeOfType <List <ServiceEntity> >(); splitMatches.Should().BeOfType <List <ServiceEntity> >(); returnedServices.Should().NotContain(s => s.Status == "deleted"); returnedServices.Count.Should().Be(10); }
public void WhenAddressesGatewayReturnsNullThenUsecasePopulatesDistanceAndMetadataFields() { // arrange var request = Randomm.Create <GetServiceByIdRequest>(); request.PostCode = Randomm.Postcode(); var expectedService = EntityHelpers.CreateService().ToDomain(); _mockServicesGateway.Setup(g => g.GetService(It.IsAny <int>())).Returns(expectedService); var expectedPostcodeCoords = Randomm.Coordinates(); _mockAddressesGateway.Setup(g => g.GetPostcodeCoordinates(It.IsAny <string>())).Returns(expectedPostcodeCoords); // act var usecaseResponse = _classUnderTest.ExecuteGet(request); // assert usecaseResponse.Metadata.PostCode.Should().Be(request.PostCode); usecaseResponse.Metadata.PostCodeLatitude.Should().Be(expectedPostcodeCoords.Latitude); usecaseResponse.Metadata.PostCodeLongitude.Should().Be(expectedPostcodeCoords.Longitude); usecaseResponse.Metadata.Error.Should().BeNull(); usecaseResponse.Service.Locations.Should().OnlyContain(l => l.Latitude.HasValue && l.Longitude.HasValue ? l.Distance != null : l.Distance == null); }
public async Task GetServicesBySearchParamsReturnServicesIfMatched() { var services = EntityHelpers.CreateServices().ToList(); var expectedResponse = new GetServiceResponseList(); expectedResponse.Services = new List <R.Service>(); var serviceToFind1 = EntityHelpers.CreateService(); var serviceToFind2 = EntityHelpers.CreateService(); var searchTerm = Randomm.Text(); serviceToFind1.Name += searchTerm; serviceToFind2.Name += searchTerm; expectedResponse.Services.Add(serviceToFind1.ToDomain().ToResponse().Service); expectedResponse.Services.Add(serviceToFind2.ToDomain().ToResponse().Service); await DatabaseContext.Services.AddRangeAsync(services).ConfigureAwait(true); await DatabaseContext.Services.AddAsync(serviceToFind1).ConfigureAwait(true); await DatabaseContext.Services.AddAsync(serviceToFind2).ConfigureAwait(true); await DatabaseContext.SaveChangesAsync().ConfigureAwait(true); var requestUri = new Uri($"api/v1/services?search={searchTerm}", UriKind.Relative); var response = Client.GetAsync(requestUri).Result; response.StatusCode.Should().Be(200); var content = response.Content; var stringContent = await content.ReadAsStringAsync().ConfigureAwait(false); var deserializedBody = JsonConvert.DeserializeObject <GetServiceResponseList>(stringContent); deserializedBody.Services.Count.Should().Be(2); }
public void WhenAddressesGatewayThrowsAnExceptionThenUsecasePopulatesTheMetadataErrorField() { // arrange var request = Randomm.Create <GetServiceByIdRequest>(); request.PostCode = Randomm.Postcode(); var expectedService = EntityHelpers.CreateService().ToDomain(); _mockServicesGateway.Setup(g => g.GetService(It.IsAny <int>())).Returns(expectedService); var expectedException = new Exception(Randomm.Text()); _mockAddressesGateway.Setup(g => g.GetPostcodeCoordinates(It.IsAny <string>())).Throws(expectedException); // act var usecaseResponse = _classUnderTest.ExecuteGet(request); // assert usecaseResponse.Service.Locations.Should().OnlyContain(l => l.Distance == null); usecaseResponse.Metadata.PostCode.Should().Be(request.PostCode); usecaseResponse.Metadata.PostCodeLatitude.Should().Be(null); usecaseResponse.Metadata.PostCodeLongitude.Should().Be(null); usecaseResponse.Metadata.Error.Should().Be(expectedException.Message); }
public async Task SearchServicesReturnServicesAccordingToRankIfMatched() { var searchWord1 = Randomm.Word(); var searchWord2 = Randomm.Word(); var irrelevantWord = Randomm.Word(); var bridgeSyn1Word = Utility.SuperSetOfString(searchWord1); var bridgeSyn2Word = Utility.SuperSetOfString(searchWord2); var synWord1 = Randomm.Word(); var synWord2 = Randomm.Word(); var synWord3 = Randomm.Word(); var synonymGroup1 = EntityHelpers.CreateSynonymGroupWithWords(); var synonymGroup2 = EntityHelpers.CreateSynonymGroupWithWords(); var dummySynGroup = EntityHelpers.CreateSynonymGroupWithWords(); var bridgeSynonym1 = EntityHelpers.SynWord(synonymGroup1, bridgeSyn1Word); var bridgeSynonym2 = EntityHelpers.SynWord(synonymGroup2, bridgeSyn2Word); var matchSynonym1 = EntityHelpers.SynWord(synonymGroup1, synWord1); var matchSynonym2 = EntityHelpers.SynWord(synonymGroup1, synWord2); var matchSynonym3 = EntityHelpers.SynWord(synonymGroup2, synWord3); synonymGroup1.SynonymWords.Add(bridgeSynonym1); synonymGroup2.SynonymWords.Add(bridgeSynonym2); synonymGroup1.SynonymWords.Add(matchSynonym1); synonymGroup1.SynonymWords.Add(matchSynonym2); synonymGroup2.SynonymWords.Add(matchSynonym3); var services = EntityHelpers.CreateServices(5); var matchService1 = EntityHelpers.CreateService(); var matchService2 = EntityHelpers.CreateService(); var matchService3 = EntityHelpers.CreateService(); var matchService4 = EntityHelpers.CreateService(); matchService1.Name += searchWord2; //matchService2.Description += synWord2; matchService2.Description += " " + synWord2; //15 Feb 2021 - Change made so we only search for whole words in the service description! - So we add a space. matchService3.Organization.Name += synWord3; matchService4.Organization.Name += searchWord1; services.AddMany(matchService1, matchService2, matchService3, matchService4); DatabaseContext.SynonymGroups.AddRange(synonymGroup1); DatabaseContext.SynonymGroups.AddRange(synonymGroup2); DatabaseContext.SynonymGroups.AddRange(dummySynGroup); DatabaseContext.Services.AddRange(services); DatabaseContext.SaveChanges(); var requestUri = new Uri($"api/v1/services?search={searchWord1} {searchWord2} {irrelevantWord}", UriKind.Relative); var response = Client.GetAsync(requestUri).Result; response.StatusCode.Should().Be(200); var content = response.Content; var stringContent = await content.ReadAsStringAsync().ConfigureAwait(false); var deserializedBody = JsonConvert.DeserializeObject <GetServiceResponseList>(stringContent); deserializedBody.Services.Count.Should().Be(4); deserializedBody.Services[0].Name.Should().Be(matchService4.Name); deserializedBody.Services[1].Name.Should().Be(matchService1.Name); deserializedBody.Services[2].Name.Should().Be(matchService3.Name); deserializedBody.Services[3].Name.Should().Be(matchService2.Name); }
public void CanGetAServiceEntity() { var service = EntityHelpers.CreateService(); DatabaseContext.Add(service); DatabaseContext.SaveChanges(); var result = DatabaseContext.Services.ToList().FirstOrDefault(); result.Should().BeEquivalentTo(service); }
public void FactoryShouldProvidePlaceholderImageIfImagePropertyIsNull() { // arrange var domainService = EntityHelpers.CreateService().ToDomain(); domainService.Image = null; // act var expectedService = domainService.ToResponseService(); // assert expectedService.Images.Should().NotBeNull(); expectedService.Images.Medium.Should().Be(_imagePlaceholder); expectedService.Images.Original.Should().Be(_imagePlaceholder); }
public void GivenValidPostcodeUsecaseShouldCallAddressesGatewayWithThatPostcode() { // dummy setup var expectedService = EntityHelpers.CreateService().ToDomain(); _mockServicesGateway.Setup(g => g.GetService(It.IsAny <int>())).Returns(expectedService); // arrange var request = Randomm.Create <GetServiceByIdRequest>(); // act _classUnderTest.ExecuteGet(request); // assert _mockAddressesGateway.Verify(g => g.GetPostcodeCoordinates(It.Is <string>(p => p == request.PostCode)), Times.Once); }
public void FactoryConvertsServiceDomainToGetServiceResponseBoundary() { // arrange var domainService = EntityHelpers.CreateService().ToDomain(); // would need domain generator, but domain object is messed up now. var expectedService = domainService.ToResponseService(); // act var responseBoundary = domainService.ToResponse(); // assert responseBoundary.Service.Should().BeEquivalentTo(expectedService); responseBoundary.Metadata.Error.Should().BeNull(); responseBoundary.Metadata.PostCode.Should().BeNull(); responseBoundary.Metadata.PostCodeLatitude.Should().BeNull(); responseBoundary.Metadata.PostCodeLongitude.Should().BeNull(); }
public void GivenMultipleTaxonomyIdSearchParametersWhenSearchServicesGatewayMethodIsCalledThenItReturnsMatchingTaxonomyIdResults() { var taxonomy1 = EntityHelpers.CreateTaxonomy(); var taxonomy2 = EntityHelpers.CreateTaxonomy(); taxonomy1.Vocabulary = "demographic"; taxonomy2.Vocabulary = "category"; var services = EntityHelpers.CreateServices(); var serviceToFind1 = EntityHelpers.CreateService(); var serviceToFind2 = EntityHelpers.CreateService(); var serviceTaxonomy1 = EntityHelpers.CreateServiceTaxonomy(); var serviceTaxonomy2 = EntityHelpers.CreateServiceTaxonomy(); var serviceTaxonomy3 = EntityHelpers.CreateServiceTaxonomy(); var serviceTaxonomy4 = EntityHelpers.CreateServiceTaxonomy(); serviceTaxonomy1.Service = serviceToFind1; serviceTaxonomy1.Taxonomy = taxonomy1; serviceTaxonomy2.Service = serviceToFind1; serviceTaxonomy2.Taxonomy = taxonomy2; serviceTaxonomy3.Service = serviceToFind2; serviceTaxonomy3.Taxonomy = taxonomy1; serviceTaxonomy4.Service = serviceToFind2; serviceTaxonomy4.Taxonomy = taxonomy2; DatabaseContext.Services.AddRange(services); DatabaseContext.Services.Add(serviceToFind1); DatabaseContext.Services.Add(serviceToFind2); DatabaseContext.ServiceTaxonomies.Add(serviceTaxonomy1); DatabaseContext.ServiceTaxonomies.Add(serviceTaxonomy2); DatabaseContext.ServiceTaxonomies.Add(serviceTaxonomy3); DatabaseContext.ServiceTaxonomies.Add(serviceTaxonomy4); DatabaseContext.SaveChanges(); var requestParams = new SearchServicesRequest(); requestParams.TaxonomyIds = new List <int> { taxonomy1.Id, taxonomy2.Id }; var expectedData = new List <Service>(); expectedData.Add(serviceToFind1); expectedData.Add(serviceToFind2); var gatewayResult = _classUnderTest.SearchServices(requestParams); var fullMatches = gatewayResult.FullMatchServices; gatewayResult.Should().NotBeNull(); fullMatches.Should().NotBeNull(); fullMatches.Count.Should().Be(expectedData.Count); }
[TestCase(TestName = "Given user provided search term consisting of multiple words, When services get filtered in SearchService method, Then the returned services are categorized into Full user input match Or Split match.")] // done so to ensure the less relevant services are in the separate collection public void SearchServiceGatewaySeparatesOutFullMatchResultsFromSplitMatch() { // arrange var word1 = Randomm.Word(); var word2 = Randomm.Word(); var userSearchInput = $"{word1} {word2}"; var request = new SearchServicesRequest() { Search = userSearchInput }; var services = new List <Service>(); var serviceToFind1 = EntityHelpers.CreateService(); // full match serviceToFind1.Name += userSearchInput; var serviceToFind2 = EntityHelpers.CreateService(); // split match 1 serviceToFind2.Name += word1; var serviceToFind3 = EntityHelpers.CreateService(); // split match 2 serviceToFind3.Name += word2; services.Add(serviceToFind1); services.Add(serviceToFind2); services.Add(serviceToFind3); DatabaseContext.Services.AddRange(services); DatabaseContext.SaveChanges(); // act var gatewayResult = _classUnderTest.SearchServices(request); var fullMatches = gatewayResult.FullMatchServices; var splitMatches = gatewayResult.SplitMatchServices; // assert gatewayResult.Should().NotBeNull(); fullMatches.Should().NotBeNull(); splitMatches.Should().NotBeNull(); fullMatches.Should().Contain(s => s.Name.Contains(userSearchInput, StringComparison.OrdinalIgnoreCase)); fullMatches.Should().HaveCount(1); splitMatches.Should().Contain(s => s.Name.Contains(word1, StringComparison.OrdinalIgnoreCase)); splitMatches.Should().Contain(s => s.Name.Contains(word2, StringComparison.OrdinalIgnoreCase)); splitMatches.Should().NotContain(s => s.Name.Contains(userSearchInput, StringComparison.OrdinalIgnoreCase)); splitMatches.Should().HaveCount(2); }
public void WhenDoingPartialTextSearchMatchesWordsOf3orLessCharactersLongGetIgnored() //it's too short - these will be searched and found inside other words in DB { // arrange var shortWordList = new List <string> { "and", "a", "an", "the", "bfg", "42" }; var shortWord = shortWordList.RandomItem(); var word = Randomm.Word().Replace(shortWord, "test");// have to ensure the shortword is not contained in the actual word for the sake of test var userSearchInput = $"{shortWord} {word}"; var request = new SearchServicesRequest() { Search = userSearchInput }; var services = EntityHelpers.CreateServices(5).ToList(); //dummy services services.ForEach(s => s.Name = s.Name.Replace(word, "ssj")); //make sure they don't match the search word //assuming there's no full match. due to full match containing a shortword, the assertion at the bottom wouldn't be able to test what's needed. var serviceToFind = EntityHelpers.CreateService(); // word 1 match serviceToFind.Name = serviceToFind.Name.Replace(shortWord, "test"); //ensuring random hash does not contain shortword. for the assertion bellow to work as intended, the service name's hash part should not contain shortword. serviceToFind.Name += word; var serviceToNotFind = EntityHelpers.CreateService(); // shortword no match. this ensures that the test can fail if the implementation is wrong or not present. serviceToNotFind.Name = serviceToNotFind.Name.Replace(word, "1234"); // make sure the mismatching service does not contain a desired search term serviceToNotFind.Name += shortWord; services.Add(serviceToFind); services.Add(serviceToNotFind); DatabaseContext.Services.AddRange(services); DatabaseContext.SaveChanges(); // act var gatewayResult = _classUnderTest.SearchServices(request); var splitMatches = gatewayResult.SplitMatchServices; // assert gatewayResult.Should().NotBeNull(); splitMatches.Should().NotBeNull(); splitMatches.Should().NotContain(s => s.Name.Contains(shortWord, StringComparison.OrdinalIgnoreCase)); splitMatches.Should().HaveCount(1); }
public void UponFilteringServicesByAMultiWordInputTheReturnedResultsIncludePartialMatches() { // arrange var word1 = Randomm.Word(); var word2 = Randomm.Word(); var userSearchInput = $"{word1} {word2}"; var request = new SearchServicesRequest() { Search = userSearchInput }; var services = EntityHelpers.CreateServices(5).ToList(); // dummy services var serviceToFind1 = EntityHelpers.CreateService(); // full match serviceToFind1.Name += userSearchInput; var serviceToFind2 = EntityHelpers.CreateService(); // word 1 match serviceToFind2.Name += word1; var serviceToFind3 = EntityHelpers.CreateService(); // word 2 match serviceToFind3.Name += word2; services.Add(serviceToFind1); services.Add(serviceToFind2); services.Add(serviceToFind3); DatabaseContext.Services.AddRange(services); DatabaseContext.SaveChanges(); // act var gatewayResult = _classUnderTest.SearchServices(request); var fullMatches = gatewayResult.FullMatchServices; var splitMatches = gatewayResult.SplitMatchServices; var returnedServices = fullMatches.Concat(splitMatches).ToList(); // assert gatewayResult.Should().NotBeNull(); fullMatches.Should().NotBeNull(); splitMatches.Should().NotBeNull(); returnedServices.Should().Contain(s => s.Name.Contains(userSearchInput, StringComparison.OrdinalIgnoreCase)); returnedServices.Should().Contain(s => s.Name.Contains(word1, StringComparison.OrdinalIgnoreCase)); returnedServices.Should().Contain(s => s.Name.Contains(word2, StringComparison.OrdinalIgnoreCase)); returnedServices.Should().HaveCount(3); }
public void GivenATaxonomyIdMatchingServiceTaxonomiesAreReturned() { var service = EntityHelpers.CreateService(); DatabaseContext.Add(service); DatabaseContext.SaveChanges(); var taxonomyId = service.ServiceTaxonomies.FirstOrDefault().TaxonomyId; var gatewayResult = _classUnderTest.GetServiceTaxonomies(taxonomyId); var expectedResult = DatabaseContext.ServiceTaxonomies.Where(x => x.TaxonomyId == taxonomyId); gatewayResult.Should().NotBeNull(); gatewayResult.Should().BeEquivalentTo(expectedResult, options => { options.Excluding(ex => ex.Service); options.Excluding(ex => ex.Taxonomy.ServiceTaxonomies); return(options); }); }
public void GivenAnIdWhenGetServiceyUseCaseIsCalledThenItCallsGetServiceGatewayMethodAndPassesInThatId() { // dummy setup var expectedService = EntityHelpers.CreateService().ToDomain(); _mockServicesGateway.Setup(g => g.GetService(It.IsAny <int>())).Returns(expectedService); // arrange var reqParams = Randomm.Create <GetServiceByIdRequest>(); reqParams.PostCode = null; // act _classUnderTest.ExecuteGet(reqParams); // assert _mockServicesGateway.Verify(g => g.GetService(It.Is <int>(p => p == reqParams.Id)), Times.Once); }
public void GetServicesUseCaseCallsGatewayGetServices() // ???? Duplicate test. I think the intention was to test the other endpoint. TODO: change upon refactoring. { // dummy setup var expectedService = EntityHelpers.CreateService().ToDomain(); _mockServicesGateway.Setup(g => g.GetService(It.IsAny <int>())).Returns(expectedService); // arrange var requestParams = Randomm.Create <GetServiceByIdRequest>(); requestParams.PostCode = null; // act _classUnderTest.ExecuteGet(requestParams); // assert _mockServicesGateway.Verify(u => u.GetService(It.Is <int>(p => p == requestParams.Id)), Times.Once); }
public async Task GetServicesByTaxonomyIdServicesIfMatchedToTaxonomyId() { var taxonomy1 = EntityHelpers.CreateTaxonomy(); var taxonomy2 = EntityHelpers.CreateTaxonomy(); var taxonomy3 = EntityHelpers.CreateTaxonomy(); taxonomy1.Vocabulary = "demographic"; taxonomy2.Vocabulary = "category"; taxonomy3.Vocabulary = "demographic"; var services = EntityHelpers.CreateServices(); var serviceToFind1 = EntityHelpers.CreateService(); var serviceToFind2 = EntityHelpers.CreateService(); var serviceTaxonomy1 = EntityHelpers.CreateServiceTaxonomy(); var serviceTaxonomy2 = EntityHelpers.CreateServiceTaxonomy(); var serviceTaxonomy3 = EntityHelpers.CreateServiceTaxonomy(); var searchTerm = Randomm.Create <string>(); serviceToFind1.Name += searchTerm; serviceToFind2.Name += searchTerm; serviceTaxonomy1.Service = serviceToFind1; serviceTaxonomy1.Taxonomy = taxonomy1; serviceTaxonomy2.Service = serviceToFind2; serviceTaxonomy2.Taxonomy = taxonomy2; serviceTaxonomy3.Service = services.First(); serviceTaxonomy3.Taxonomy = taxonomy2; DatabaseContext.Services.AddRange(services); DatabaseContext.Services.Add(serviceToFind1); DatabaseContext.Services.Add(serviceToFind2); DatabaseContext.ServiceTaxonomies.Add(serviceTaxonomy1); DatabaseContext.ServiceTaxonomies.Add(serviceTaxonomy2); DatabaseContext.ServiceTaxonomies.Add(serviceTaxonomy3); DatabaseContext.Taxonomies.Add(taxonomy3); DatabaseContext.SaveChanges(); var requestUri = new Uri($"api/v1/services?search={searchTerm}&taxonomyids={taxonomy2.Id}&taxonomyids={taxonomy3.Id}", UriKind.Relative); var response = Client.GetAsync(requestUri).Result; response.StatusCode.Should().Be(200); var content = response.Content; var stringContent = await content.ReadAsStringAsync().ConfigureAwait(false); var deserializedBody = JsonConvert.DeserializeObject <GetServiceResponseList>(stringContent); deserializedBody.Services.Count.Should().Be(0); }
public void GivenSearchParametersWhenSearchServicesGatewayMethodIsCalledThenItReturnsMatchingSynonymGroupResults() { // arrange var synonymGroup1 = EntityHelpers.CreateSynonymGroupWithWords(5); var synonymGroup2 = EntityHelpers.CreateSynonymGroupWithWords(3); synonymGroup2.SynonymWords.ToList()[1].Word = synonymGroup1.SynonymWords.ToList()[1].Word; var services = EntityHelpers.CreateServices(); services.ForEach(s => s.Name = "irrelevant"); var serviceToFind1 = EntityHelpers.CreateService(); var serviceToFind2 = EntityHelpers.CreateService(); var searchTerm = synonymGroup1.SynonymWords.ToList()[1].Word; var requestParams = new SearchServicesRequest(); requestParams.Search = searchTerm; serviceToFind1.Name += synonymGroup1.SynonymWords.ToList()[4].Word; serviceToFind2.Name += synonymGroup2.SynonymWords.ToList()[2].Word; DatabaseContext.SynonymGroups.Add(synonymGroup1); DatabaseContext.SynonymGroups.Add(synonymGroup2); DatabaseContext.Services.AddRange(services); DatabaseContext.Services.Add(serviceToFind1); DatabaseContext.Services.Add(serviceToFind2); DatabaseContext.SaveChanges(); var expectedData = new List <Service>(); expectedData.Add(serviceToFind1); expectedData.Add(serviceToFind2); // act var gatewayResult = _classUnderTest.SearchServices(requestParams); var fullMatches = gatewayResult.FullMatchServices; var splitMatches = gatewayResult.SplitMatchServices; var returnedServices = fullMatches.Concat(splitMatches).ToList(); // assert gatewayResult.Should().NotBeNull(); fullMatches.Should().NotBeNull(); splitMatches.Should().NotBeNull(); returnedServices.Count.Should().Be(expectedData.Count); }
public async Task GivenValidImageIdImageGetsDeleted() { var file = EntityHelpers.CreateFile(); var service = EntityHelpers.CreateService(); service.Image = file; service.ImageId = file.Id; await DatabaseContext.Files.AddAsync(file).ConfigureAwait(true); await DatabaseContext.Services.AddAsync(service).ConfigureAwait(true); await DatabaseContext.SaveChangesAsync().ConfigureAwait(true); await _classUnderTest.DeleteFileInfo(service.Id, file).ConfigureAwait(true); var expectedResult = DatabaseContext.Files.Where(x => x.Id == file.Id).SingleOrDefault(); expectedResult.Should().BeNull(); var expectedService = DatabaseContext.Services.Where(x => x.Id == service.Id).SingleOrDefault(); service.Image.Should().BeNull(); }
public void GivenSuccessfulGetServiceyGatewayCallWhenGatewayReturnsAValueThenTheUseCaseReturnsThatSameValue() { // dummy setup var expectedService = EntityHelpers.CreateService().ToDomain(); _mockServicesGateway.Setup(g => g.GetService(It.IsAny <int>())).Returns(expectedService); // arrange var reqParams = Randomm.Create <GetServiceByIdRequest>(); reqParams.PostCode = null; var gatewayResult = EntityHelpers.CreateService().ToDomain(); _mockServicesGateway.Setup(g => g.GetService(It.IsAny <int>())).Returns(gatewayResult); // act var usecaseResult = _classUnderTest.ExecuteGet(reqParams); // assert usecaseResult.Should().BeEquivalentTo(gatewayResult.ToResponse()); }
public async Task ReturnsThatMatchingService() { // arrange DatabaseContext.Database.RollbackTransaction(); var service = EntityHelpers.CreateService(); DatabaseContext.Services.Add(service); DatabaseContext.SaveChanges(); var expectedService = DatabaseContext.Services.FirstOrDefault(); var searchSearviceId = expectedService.Id; // act var requestUri = new Uri($"api/v1/services/{searchSearviceId}?postcode={Randomm.Postcode()}", UriKind.Relative); var response = Client.GetAsync(requestUri).Result; var content = response.Content; var stringResponse = await content.ReadAsStringAsync().ConfigureAwait(true); var actualService = JsonConvert.DeserializeObject <GetServiceResponse>(stringResponse); // assert response.StatusCode.Should().Be(200); actualService.Service.Id.Should().Be(expectedService.Id); actualService.Service.Status.Should().Be(service.Status); }
public void FactoryConvertsServiceDomainIntoServiceResponse() { // arrange var domainService = EntityHelpers.CreateService().ToDomain(); // would need domain generator, but domain object is messed up now. // act var responseService = domainService.ToResponseService(); // assert responseService.Id.Should().Be(domainService.Id); responseService.Name.Should().Be(domainService.Name); responseService.Categories.Should().OnlyContain(c => c.Vocabulary == "category" && domainService.ServiceTaxonomies.Any(st => st.Taxonomy != null && st.Taxonomy.Id == c.Id && st.Taxonomy.Name == c.Name && st.Description == c.Description && st.Taxonomy.Weight == c.Weight )); responseService.Contact.Email.Should().Be(domainService.Email); responseService.Contact.Telephone.Should().Be(domainService.Telephone); responseService.Contact.Website.Should().Be(domainService.Website); responseService.Demographic.Should().OnlyContain(d => d.Vocabulary == "demographic" && domainService.ServiceTaxonomies.Any(st => st.Taxonomy.Id == d.Id && st.Taxonomy.Name == d.Name )); responseService.Description.Should().Be(domainService.Description); responseService.Images.Original.Should().Be(domainService.Image.Url); responseService.Locations.Should().HaveCount(domainService.ServiceLocations.Count); responseService.Locations.Should().OnlyContain(l => domainService.ServiceLocations.Any(sl => (double?)sl.Latitude == l.Latitude && (double?)sl.Longitude == l.Longitude && sl.Uprn == l.Uprn && sl.Address1 == l.Address1 && sl.Address2 == l.Address2 && sl.City == l.City && sl.StateProvince == sl.StateProvince && sl.PostalCode == l.PostalCode && sl.Country == l.Country && null == l.Distance )); responseService.Organization.Id.Should().Be(domainService.Organization.Id); responseService.Organization.Name.Should().Be(domainService.Organization.Name); responseService.Organization.Status.Should().Be(domainService.Organization.Status); responseService.Referral.Email.Should().Be(domainService.ReferralEmail); responseService.Referral.Website.Should().Be(domainService.ReferralLink); responseService.Social.Facebook.Should().Be(domainService.Facebook); responseService.Social.Instagram.Should().Be(domainService.Instagram); responseService.Social.Linkedin.Should().Be(domainService.Linkedin); responseService.Social.Twitter.Should().Be(domainService.Twitter); responseService.Status.Should().Be(domainService.Status); }
public void WholeAndSplitUserInputMatchesAreReturnedInCorrectRank() { // arrange var searchWord1 = Randomm.Word(); // word that won't match any results, however 1 of its synonyms from synonym group will var searchWord2 = Randomm.Word(); // same as above, but the matching synonym will be in another synonym group var irrelevantWord = Randomm.Word(); // a control word, that won't match anything, nor its synonyms will. var userInput = $"{searchWord1} " + $"{irrelevantWord} " + $"{searchWord2}"; var request = new SearchServicesRequest(); request.Search = userInput; var bridgeSyn1Word = Utility.SuperSetOfString(searchWord1); // A superset word of search word 1 that will relate to a synonym word inside synonym group 1 - this word has no match in the DB var bridgeSyn2Word = Utility.SuperSetOfString(searchWord2); // A superset word of search word 2 that will relate to a synonym word inside synonym group 2 - this word has no match in the DB var synWord1 = Randomm.Word(); // synonym within the same synonym group (1) as a word related to search word 1 - this word has a match in the DB var synWord2 = Randomm.Word(); // synonym within the same synonym group (1) as a word related to search word 1 - this word has a match in the DB var synWord3 = Randomm.Word(); // synonym within the same synonym group (2) as a word related to search word 2 - this word has a match in the DB var synonymGroup1 = EntityHelpers.CreateSynonymGroupWithWords(); // relevant group with dummy synonym words var synonymGroup2 = EntityHelpers.CreateSynonymGroupWithWords(); // relevant group with dummy synonym words var dummySynGroup = EntityHelpers.CreateSynonymGroupWithWords(); // dummy synonym group that should not be picked up var bridgeSynonym1 = EntityHelpers.SynWord(synonymGroup1, bridgeSyn1Word); // synonym that has no match in DB, however it bridges user input search word with the synonym group 1 var bridgeSynonym2 = EntityHelpers.SynWord(synonymGroup2, bridgeSyn2Word); var matchSynonym1 = EntityHelpers.SynWord(synonymGroup1, synWord1); // creating a synonym word object to insert that will have a match, creating a link with synonym group 1 var matchSynonym2 = EntityHelpers.SynWord(synonymGroup1, synWord2); var matchSynonym3 = EntityHelpers.SynWord(synonymGroup2, synWord3); synonymGroup1.SynonymWords.Add(bridgeSynonym1); // added bridge synonym to the synonym group synonymGroup2.SynonymWords.Add(bridgeSynonym2); synonymGroup1.SynonymWords.Add(matchSynonym1); // added match synonym into a synonym group synonymGroup1.SynonymWords.Add(matchSynonym2); synonymGroup2.SynonymWords.Add(matchSynonym3); var services = EntityHelpers.CreateServices(5); // creating list of dummy services that should not be found var matchService1 = EntityHelpers.CreateService(); // service that is intended to be found through the synonym of synonym group 1 var matchService2 = EntityHelpers.CreateService(); // service that is intended to be found through the synonym of synonym group 1 var matchService3 = EntityHelpers.CreateService(); // service that is intended to be found through the synonym of synonym group 2 var matchService4 = EntityHelpers.CreateService(); // service that is intended to be found through the main search term matchService1.Name += searchWord2; // creating a link between a service and a match synonym 1 // creating a link between a service and a match synonym 2 matchService2.Description += " " + synWord2; //15 Feb 2021 - Change made so we only search for whole words in the service description! - So we add a space. matchService3.Organization.Name += synWord3; // creating a link between a service and a match synonym 3 matchService4.Organization.Name += searchWord1; // creating a link between a service and a main search word services.AddMany(matchService1, matchService2, matchService3, matchService4); // include match services into a to be inserted services collection DatabaseContext.SynonymGroups.AddRange(synonymGroup1); // adding synonym groups containing synonym words into a database DatabaseContext.SynonymGroups.AddRange(synonymGroup2); DatabaseContext.SynonymGroups.AddRange(dummySynGroup); DatabaseContext.Services.AddRange(services); // adding services into a database DatabaseContext.SaveChanges(); // act var gatewayResult = _classUnderTest.SearchServices(request); var splitMatches = gatewayResult.SplitMatchServices; var fullMatches = gatewayResult.FullMatchServices; // assert splitMatches.Should().HaveCount(4); fullMatches.Should().HaveCount(0); splitMatches[0].Name.Should().Be(matchService4.Name); splitMatches[1].Name.Should().Be(matchService1.Name); splitMatches[2].Name.Should().Be(matchService3.Name); splitMatches[3].Name.Should().Be(matchService2.Name); }