public void CanGetATaxonomyEntity() { var taxonomy = EntityHelpers.CreateTaxonomy(); DatabaseContext.Add(taxonomy); DatabaseContext.SaveChanges(); var result = DatabaseContext.Taxonomies.ToList().FirstOrDefault(); result.Should().BeEquivalentTo(taxonomy); }
public void GetTaxonomiesReturnsTaxonomies() // all { var entity = EntityHelpers.CreateTaxonomy(); DatabaseContext.Taxonomies.Add(entity); DatabaseContext.SaveChanges(); var response = _classUnderTest.GetTaxonomies(null).ToList(); response.First().Name.Should().Be(entity.Name); }
public void GivenAnIdAMatchingTaxonomyGetsDeleted() { var taxonomy = EntityHelpers.CreateTaxonomy(); DatabaseContext.Add(taxonomy); DatabaseContext.SaveChanges(); _classUnderTest.DeleteTaxonomy(taxonomy.Id); var expectedResult = DatabaseContext.Taxonomies.Find(taxonomy.Id); expectedResult.Should().BeNull(); }
public void GivenTaxonomyDomainTaxonomyGetsCreated() { var taxonomy = EntityHelpers.CreateTaxonomy(); var gatewayResult = _classUnderTest.CreateTaxonomy(taxonomy); var expectedResult = DatabaseContext.Taxonomies.Where(x => x.Name == taxonomy.Name).FirstOrDefault(); gatewayResult.Should().NotBeNull(); gatewayResult.Should().BeEquivalentTo(_mapper.ToDomain(expectedResult), options => { return(options); }); }
public void GivenAnIdAMatchingTaxonomyGetsReturned() { var taxonomy = EntityHelpers.CreateTaxonomy(); DatabaseContext.Add(taxonomy); DatabaseContext.SaveChanges(); var gatewayResult = _classUnderTest.GetTaxonomy(taxonomy.Id); var expectedResult = DatabaseContext.Taxonomies.Find(taxonomy.Id); gatewayResult.Should().NotBeNull(); gatewayResult.Should().BeEquivalentTo(expectedResult, options => { options.Excluding(ex => ex.ServiceTaxonomies); return(options); }); }
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 void GivenATaxonomyTaxonomyGetsUpdated() { var taxonomy = EntityHelpers.CreateTaxonomy(); DatabaseContext.Add(taxonomy); DatabaseContext.SaveChanges(); var newTaxonomy = taxonomy; newTaxonomy.Description = Randomm.Text(); _classUnderTest.PatchTaxonomy(taxonomy.Id, newTaxonomy); var gatewayResult = DatabaseContext.Taxonomies.Find(taxonomy.Id); gatewayResult.Should().NotBeNull(); gatewayResult.Should().BeEquivalentTo(_mapper.ToDomain(newTaxonomy), options => { return(options); }); }
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); }