public void SHOULD_convert_field() { // arrange var facet = new FacetImpl { Id = GetRandom.Guid(), FieldName = GetRandom.String(10), FacetType = "SingleSelect", IsDisplayed = true, // StartValue = GetRandom.NumericString(2), // EndValue = GetRandom.NumericString(2), // GapSize = GetRandom.NumericString(2), MaxCollapsedValueCount = GetRandom.Int(), MaxExpendedValueCount = GetRandom.Int(), SortWeight = GetRandom.Decimal(), }; // act var result = FacetsMapper.ConvertToFacetSetting(facet); // assert result.Should().NotBeNull(); result.FieldName.Should().Be(facet.FieldName); result.FacetType.Should().Be(FacetType.SingleSelect); result.FacetValueType.Should().Be(typeof(string)); result.IsDisplayed.Should().Be(facet.IsDisplayed); // result.StartValue.Should().Be(facet.StartValue); // result.EndValue.Should().Be(facet.EndValue); // result.GapSize.Should().Be(facet.GapSize); result.MaxCollapsedValueCount.Should().Be(facet.MaxCollapsedValueCount); result.MaxExpendedValueCount.Should().Be(facet.MaxExpendedValueCount); result.SortWeight.Should().Be((double)facet.SortWeight); }
public void WHEN_facet_is_null_SHOULD_throw_error() { // arrange IFacet facet = null; // act & assert Assert.Throws <ArgumentNullException>(() => FacetsMapper.ConvertToFacetSetting(facet)); }
protected virtual List <FacetSetting> LoadFacetSettings(Guid?pageId) { var result = new List <FacetSetting>(); IFacetConfiguration facetConfiguration = null; if (pageId.HasValue) // loading from current page { facetConfiguration = GetFacetConfigurationFromPage(pageId.Value); } if (facetConfiguration == null) // if no config on page, using any config from db { facetConfiguration = GetDefaultFacetConfiguration(); if (facetConfiguration == null) // no facet configs exist { return(result); } } var facetsIds = GetIds(facetConfiguration.Facets); var facets = DataQueryService.Get <IFacet>().Where(f => facetsIds.Contains(f.Id)).ToList(); var facetsAndData = facets.Select(f => new { Facet = f, DependsOnIds = GetIds(f.DependsOn), PromotedIds = GetIds(f.PromotedValues), }).ToList(); var allDependsOnIds = facetsAndData.SelectMany(f => f.DependsOnIds).Distinct().ToList(); var allDependsOn = LoadDependsOn(allDependsOnIds, facets); var allPromotedIds = facetsAndData.SelectMany(f => f.PromotedIds).Distinct().ToList(); var allPromoted = LoadPromotedFacetValues(allPromotedIds); foreach (var facet in facetsAndData) { var dependsOn = facet.DependsOnIds .Select(id => allDependsOn.TryGetValue(id, out var dependedFacet) ? dependedFacet : null) .Where(f => f != null) .ToList(); var promoted = facet.PromotedIds .Select(id => allPromoted.TryGetValue(id, out var promotedFacet) ? promotedFacet : null) .Where(f => f != null) .ToList(); result.Add(FacetsMapper.ConvertToFacetSetting(facet.Facet, dependsOn, promoted)); } return(result); }
public void WHEN_facet_is_singleSelect_SHOULD_convert() { // arrange var facet = CreateFacet(); // act var result = FacetsMapper.ConvertToFacetSetting(facet); // assert result.FacetType.Should().Be(FacetType.SingleSelect); result.FacetValueType.Should().Be(typeof(string)); }
public void WHEN_facet_is_range_SHOULD_convert() { // arrange var facet = CreateFacet(); facet.FacetType = "Range"; // act var result = FacetsMapper.ConvertToFacetSetting(facet); // assert result.FacetType.Should().Be(FacetType.Range); result.FacetValueType.Should().Be(typeof(decimal)); }
public void WHEN_dependsOn_present_SHOULD_convert() { // arrange var dependsOn = CreateFacet(); var facet = CreateFacet(dependsOn); // act var result = FacetsMapper.ConvertToFacetSetting(facet, new List <IFacet> { dependsOn }); // assert result.DependsOn.Should().NotBeNull(); result.DependsOn.Should().HaveCount(1); result.DependsOn[0].Should().Be(dependsOn.FieldName); }
public void WHEN_promotedValues_present_SHOULD_convert() { // arrange var promoted = CreatePromotedFacet(); var facet = CreateFacet(); facet.PromotedValuesItems.Add(promoted); // act var result = FacetsMapper.ConvertToFacetSetting(facet, null, new List <IPromotedFacetValueSetting> { promoted }); // assert result.PromotedValues.Should().NotBeNull(); result.PromotedValues.Should().HaveCount(1); var promotedResult = result.PromotedValues[0]; promotedResult.Title.Should().Be(promoted.Title); promotedResult.SortWeight.Should().Be((double)promoted.SortWeight); }