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); }
public void GivenAnIdAMatchingTaxonomyAndServiceTaxonomyGetsDeleted() { var serviceTaxonomy = EntityHelpers.CreateServiceTaxonomy(); var taxonomy = EntityHelpers.CreateTaxonomy(); serviceTaxonomy.Taxonomy = taxonomy; DatabaseContext.Add(taxonomy); DatabaseContext.Add(serviceTaxonomy); DatabaseContext.SaveChanges(); _classUnderTest.DeleteTaxonomy(taxonomy.Id); var expectedResult = DatabaseContext.Taxonomies.Find(taxonomy.Id); expectedResult.Should().BeNull(); var expectedResult2 = DatabaseContext.ServiceTaxonomies.Where(x => x.TaxonomyId == taxonomy.Id); expectedResult2.Should().BeEmpty(); }
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); }