public void EventGridFilterConverterWhenConvertedThrowsException(ApiAdvancedFilter filter, string destinationFilterName) { // Arrange // Act // Assert Assert.NotNull(destinationFilterName); Assert.ThrowsAny <Exception>(() => filter.Convert()); }
public void EventGridFilterConverterWhenConvertedCreatesFilters(ApiAdvancedFilter filter, string destinationFilterName) { // Arrange // Act var result = filter.Convert(); //Assert Assert.NotNull(result); Assert.NotNull(result.Key); Assert.Equal(destinationFilterName, result.GetType().Name); }
public static AdvancedFilter Convert(this ApiAdvancedFilter advancedFilter) { if (advancedFilter == null) { throw new ArgumentNullException(nameof(advancedFilter)); } return(advancedFilter.Type switch { FilterType.StringContains => new StringContainsAdvancedFilter(advancedFilter.Property, advancedFilter.Values.Select(x => (string)x).ToList()), FilterType.StringEndsWith => new StringEndsWithAdvancedFilter(advancedFilter.Property, advancedFilter.Values.Select(x => (string)x).ToList()), FilterType.StringIn => new StringInAdvancedFilter(advancedFilter.Property, advancedFilter.Values.Select(x => (string)x).ToList()), FilterType.StringBeginsWith => new StringBeginsWithAdvancedFilter(advancedFilter.Property, advancedFilter.Values.Select(x => (string)x).ToList()), FilterType.StringNotIn => new StringNotInAdvancedFilter(advancedFilter.Property, advancedFilter.Values.Select(x => (string)x).ToList()), FilterType.NumberNotIn => new NumberNotInAdvancedFilter(advancedFilter.Property, advancedFilter.Values.Select(x => (double?)double.Parse(x.ToString(), null)).ToList()), FilterType.NumberLessThanOrEquals => new NumberLessThanOrEqualsAdvancedFilter(advancedFilter.Property, advancedFilter.Values?.Count == 1 ? advancedFilter.Values.Select(x => (double?)double.Parse(x.ToString(), null)).FirstOrDefault() : throw new InvalidOperationException($"Only one filter can be passed to {nameof(NumberLessThanOrEqualsAdvancedFilter)}")), FilterType.NumberLessThan => new NumberLessThanAdvancedFilter(advancedFilter.Property, advancedFilter.Values?.Count == 1 ? advancedFilter.Values.Select(x => (double?)double.Parse(x.ToString(), null)).FirstOrDefault() : throw new InvalidOperationException($"Only one filter can be passed to {nameof(NumberLessThanAdvancedFilter)}")), FilterType.NumberIn => new NumberInAdvancedFilter(advancedFilter.Property, advancedFilter.Values.Select(x => (double?)double.Parse(x.ToString(), null)).ToList()), FilterType.NumberGreaterThanOrEquals => new NumberGreaterThanAdvancedFilter(advancedFilter.Property, advancedFilter.Values?.Count == 1 ? advancedFilter.Values.Select(x => (double?)double.Parse(x.ToString(), null)).FirstOrDefault() : throw new InvalidOperationException($"Only one filter can be passed to {nameof(NumberGreaterThanOrEqualsAdvancedFilter)}")), FilterType.NumberGreaterThan => new NumberGreaterThanAdvancedFilter(advancedFilter.Property, advancedFilter.Values?.Count == 1 ? advancedFilter.Values.Select(x => (double?)double.Parse(x.ToString(), null)).FirstOrDefault() : throw new InvalidOperationException($"Only one filter can be passed to {nameof(NumberGreaterThanAdvancedFilter)}")), FilterType.BoolEquals => new BoolEqualsAdvancedFilter(advancedFilter.Property, advancedFilter.Values?.Count == 1 ? advancedFilter.Values.Select(x => bool.Parse(x.ToString())).FirstOrDefault() : throw new InvalidOperationException($"Only one filter can be passed to {nameof(BoolEqualsAdvancedFilter)}")), _ => throw new NotSupportedException(nameof(advancedFilter.Type)), });