diff --git a/ODataNullPropagationVisitor.Test/EnumerableNullPropagationYankerTests.cs b/ODataNullPropagationVisitor.Test/EnumerableNullPropagationYankerTests.cs new file mode 100644 index 0000000..883c23f --- /dev/null +++ b/ODataNullPropagationVisitor.Test/EnumerableNullPropagationYankerTests.cs @@ -0,0 +1,55 @@ +using System.Collections.Generic; +using System.Linq; +using Xunit; +using OData.Linq; + +namespace ODataNullPropagationVisitor.Test +{ + + public class EnumerableNullPropagationYankerTests + { + public class Product + { + public string Name { get; set; } + public IEnumerable Stores { get; set; } + } + + public class Store + { + public string Name { get; set; } + } + + [Fact] + public void Should_Remove_Null_Propgation_In_MethodCall_Expressions() + { + var storeList = new List + { + new Store { Name = "Store 1" }, + }; + + var productList = new List() + { + new Product { Name = "Product 1", Stores = storeList}, + }; + + var productsQueryable = productList.AsQueryable(); + + var withPropagation = (from p in productsQueryable + where (p.Stores == null ? Enumerable.Empty() : p.Stores).Any(x => x.Name == "Store 1") + select p).Expression; + + var withoutPropagation = (from p in productsQueryable + where (p.Stores.Any(x => x.Name == "Store 1")) + select p).Expression; + + var propagationRemoved = new EnumerableNullPropagationYanker().Visit(withPropagation); + + string withPropagationString = SimpleExpressionPrinter.Stringify(withPropagation); + string withoutPropagationString = SimpleExpressionPrinter.Stringify(withoutPropagation); + string propagationRemovedString = SimpleExpressionPrinter.Stringify(propagationRemoved); + + Assert.NotEqual(withPropagationString, propagationRemovedString); + Assert.Equal(withoutPropagationString, propagationRemovedString); + } + } +} diff --git a/ODataNullPropagationVisitor.Test/ODataNullPropagationVisitor.Test.csproj b/ODataNullPropagationVisitor.Test/ODataNullPropagationVisitor.Test.csproj index 8211d65..364fe7e 100644 --- a/ODataNullPropagationVisitor.Test/ODataNullPropagationVisitor.Test.csproj +++ b/ODataNullPropagationVisitor.Test/ODataNullPropagationVisitor.Test.csproj @@ -1,73 +1,74 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {2C0BC430-0803-4D80-9587-CE4055C7AAFD} - Library - Properties - ODataNullPropagationVisitor.Test - ODataNullPropagationVisitor.Test - v4.0 - 512 - ..\ - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\QueryInterceptor.0.1.4237.2400\lib\net40\QueryInterceptor.dll - - - - - - - - - - ..\packages\xunit.1.9.0.1566\lib\xunit.dll - - - - - - - - - - - - - {1C92242B-A2DF-4F53-8BAC-57EA406AF0FF} - ODataNullPropagationVisitor - - - - - + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {2C0BC430-0803-4D80-9587-CE4055C7AAFD} + Library + Properties + ODataNullPropagationVisitor.Test + ODataNullPropagationVisitor.Test + v4.0 + 512 + ..\ + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\QueryInterceptor.0.1.4237.2400\lib\net40\QueryInterceptor.dll + + + + + + + + + + ..\packages\xunit.1.9.0.1566\lib\xunit.dll + + + + + + + + + + + + + + {1C92242B-A2DF-4F53-8BAC-57EA406AF0FF} + ODataNullPropagationVisitor + + + + + \ No newline at end of file diff --git a/ODataNullPropagationVisitor/ODataNullPropagationVisitor.csproj b/ODataNullPropagationVisitor/ODataNullPropagationVisitor.csproj index 71df6fa..707fde1 100644 --- a/ODataNullPropagationVisitor/ODataNullPropagationVisitor.csproj +++ b/ODataNullPropagationVisitor/ODataNullPropagationVisitor.csproj @@ -1,65 +1,67 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {1C92242B-A2DF-4F53-8BAC-57EA406AF0FF} - Library - Properties - OData.Linq - ODataNullPropagationVisitor - v4.0 - 512 - ..\ - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\QueryInterceptor.0.1.4237.2400\lib\net40\QueryInterceptor.dll - - - - - - - - - - - - - - - - - - - - - + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {1C92242B-A2DF-4F53-8BAC-57EA406AF0FF} + Library + Properties + OData.Linq + ODataNullPropagationVisitor + v4.0 + 512 + ..\ + true + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\QueryInterceptor.0.1.4237.2400\lib\net40\QueryInterceptor.dll + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ODataNullPropagationVisitor/QueryableExtensions.cs b/ODataNullPropagationVisitor/QueryableExtensions.cs index 4e78144..b7a53bc 100644 --- a/ODataNullPropagationVisitor/QueryableExtensions.cs +++ b/ODataNullPropagationVisitor/QueryableExtensions.cs @@ -1,14 +1,18 @@ -using System.Linq; -using QueryInterceptor; - -namespace OData.Linq { - public static class QueryableExtensions { - public static IQueryable WithoutNullPropagation(this IQueryable query) { - return query.InterceptWith(new NullPropagationYanker()); - } - - public static IQueryable WithoutMethodCallNullPropagation(this IQueryable query) { - return query.InterceptWith(new MethodCallNullPropagationYanker()); - } - } +using System.Linq; +using QueryInterceptor; + +namespace OData.Linq { + public static class QueryableExtensions { + public static IQueryable WithoutNullPropagation(this IQueryable query) { + return query.InterceptWith(new NullPropagationYanker()); + } + + public static IQueryable WithoutMethodCallNullPropagation(this IQueryable query) { + return query.InterceptWith(new MethodCallNullPropagationYanker()); + } + + public static IQueryable WithoutEnumerableNullPropagation(this IQueryable query) { + return query.InterceptWith(new EnumerableNullPropagationYanker()); + } + } } \ No newline at end of file