diff --git a/Azure.EntityServices.sln b/Azure.EntityServices.sln index 1b4cbcf..4d50c8b 100644 --- a/Azure.EntityServices.sln +++ b/Azure.EntityServices.sln @@ -25,14 +25,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{12E4 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TableClient.PerformanceSample", "samples\TableClient.Performance.Sample\TableClient.PerformanceSample.csproj", "{1AE5DF7B-3328-49B9-A455-D609ACC2BB95}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common.Samples", "Common.Samples\Common.Samples.csproj", "{ADAFA655-104A-4375-BA08-3A8007860B5A}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlobClient.BasicSample", "samples\BlobClient.Sample\BlobClient.BasicSample.csproj", "{61ED3E91-9ED3-4D09-A51C-83ABA1F83D75}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TableClient.BasicSample", "samples\TableClient.Basic.Sample\TableClient.BasicSample.csproj", "{5CEB65EF-0D90-493C-9A81-270B3914F3C4}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TableClient.LegacySample", "TableClient.Legacy.Sample\TableClient.LegacySample.csproj", "{9DF46286-6193-4A5D-A127-866C76252419}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.EntityServices.Blobs.Extensions.DependencyInjection", "src\Azure.EntityServices.Blobs.Extensions.DependencyInjection\Azure.EntityServices.Blobs.Extensions.DependencyInjection.csproj", "{6D5B1034-2ED7-4EBE-BC4E-6C93CBDCDED6}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlobClient.DependencyInjection.Sample", "samples\BlobClient.DependencyInjection.Sample\BlobClient.DependencyInjection.Sample.csproj", "{BAB3206B-D2F7-4790-8629-76D7A33DC969}" @@ -47,6 +43,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{D449467E EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B6C4E5FE-96DE-4BDF-9D98-2288E601D08C}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common.Samples", "samples\Common.Samples\Common.Samples.csproj", "{9B8845F6-BEDD-4295-8E1B-7831B1246B26}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TableClient.LegacySample", "samples\TableClient.Legacy.Sample\TableClient.LegacySample.csproj", "{9BBE86B6-F1B9-4379-A739-898388CDAA96}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -77,10 +77,6 @@ Global {1AE5DF7B-3328-49B9-A455-D609ACC2BB95}.Debug|Any CPU.Build.0 = Debug|Any CPU {1AE5DF7B-3328-49B9-A455-D609ACC2BB95}.Release|Any CPU.ActiveCfg = Release|Any CPU {1AE5DF7B-3328-49B9-A455-D609ACC2BB95}.Release|Any CPU.Build.0 = Release|Any CPU - {ADAFA655-104A-4375-BA08-3A8007860B5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ADAFA655-104A-4375-BA08-3A8007860B5A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {ADAFA655-104A-4375-BA08-3A8007860B5A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ADAFA655-104A-4375-BA08-3A8007860B5A}.Release|Any CPU.Build.0 = Release|Any CPU {61ED3E91-9ED3-4D09-A51C-83ABA1F83D75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {61ED3E91-9ED3-4D09-A51C-83ABA1F83D75}.Debug|Any CPU.Build.0 = Debug|Any CPU {61ED3E91-9ED3-4D09-A51C-83ABA1F83D75}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -89,10 +85,6 @@ Global {5CEB65EF-0D90-493C-9A81-270B3914F3C4}.Debug|Any CPU.Build.0 = Debug|Any CPU {5CEB65EF-0D90-493C-9A81-270B3914F3C4}.Release|Any CPU.ActiveCfg = Release|Any CPU {5CEB65EF-0D90-493C-9A81-270B3914F3C4}.Release|Any CPU.Build.0 = Release|Any CPU - {9DF46286-6193-4A5D-A127-866C76252419}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9DF46286-6193-4A5D-A127-866C76252419}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9DF46286-6193-4A5D-A127-866C76252419}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9DF46286-6193-4A5D-A127-866C76252419}.Release|Any CPU.Build.0 = Release|Any CPU {6D5B1034-2ED7-4EBE-BC4E-6C93CBDCDED6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6D5B1034-2ED7-4EBE-BC4E-6C93CBDCDED6}.Debug|Any CPU.Build.0 = Debug|Any CPU {6D5B1034-2ED7-4EBE-BC4E-6C93CBDCDED6}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -113,6 +105,14 @@ Global {321BB55F-AA1C-4973-9315-7323D4FC19B0}.Debug|Any CPU.Build.0 = Debug|Any CPU {321BB55F-AA1C-4973-9315-7323D4FC19B0}.Release|Any CPU.ActiveCfg = Release|Any CPU {321BB55F-AA1C-4973-9315-7323D4FC19B0}.Release|Any CPU.Build.0 = Release|Any CPU + {9B8845F6-BEDD-4295-8E1B-7831B1246B26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9B8845F6-BEDD-4295-8E1B-7831B1246B26}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9B8845F6-BEDD-4295-8E1B-7831B1246B26}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9B8845F6-BEDD-4295-8E1B-7831B1246B26}.Release|Any CPU.Build.0 = Release|Any CPU + {9BBE86B6-F1B9-4379-A739-898388CDAA96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9BBE86B6-F1B9-4379-A739-898388CDAA96}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9BBE86B6-F1B9-4379-A739-898388CDAA96}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9BBE86B6-F1B9-4379-A739-898388CDAA96}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -124,15 +124,15 @@ Global {4019B11A-8481-4BE3-8B61-01F9FD0AEC5E} = {B6C4E5FE-96DE-4BDF-9D98-2288E601D08C} {1D6ED178-F026-4F39-9FC2-FBD1EB182B7B} = {B6C4E5FE-96DE-4BDF-9D98-2288E601D08C} {1AE5DF7B-3328-49B9-A455-D609ACC2BB95} = {12E4FDA9-194D-4758-BB02-1619C2956738} - {ADAFA655-104A-4375-BA08-3A8007860B5A} = {12E4FDA9-194D-4758-BB02-1619C2956738} {61ED3E91-9ED3-4D09-A51C-83ABA1F83D75} = {12E4FDA9-194D-4758-BB02-1619C2956738} {5CEB65EF-0D90-493C-9A81-270B3914F3C4} = {12E4FDA9-194D-4758-BB02-1619C2956738} - {9DF46286-6193-4A5D-A127-866C76252419} = {12E4FDA9-194D-4758-BB02-1619C2956738} {6D5B1034-2ED7-4EBE-BC4E-6C93CBDCDED6} = {B6C4E5FE-96DE-4BDF-9D98-2288E601D08C} {BAB3206B-D2F7-4790-8629-76D7A33DC969} = {12E4FDA9-194D-4758-BB02-1619C2956738} {8F8165C7-37ED-42C2-9D8A-BBABB461BCB8} = {12E4FDA9-194D-4758-BB02-1619C2956738} {C825B333-1737-45F2-ADD3-2BF7D735BB41} = {12E4FDA9-194D-4758-BB02-1619C2956738} {321BB55F-AA1C-4973-9315-7323D4FC19B0} = {12E4FDA9-194D-4758-BB02-1619C2956738} + {9B8845F6-BEDD-4295-8E1B-7831B1246B26} = {12E4FDA9-194D-4758-BB02-1619C2956738} + {9BBE86B6-F1B9-4379-A739-898388CDAA96} = {12E4FDA9-194D-4758-BB02-1619C2956738} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {92B5DB88-8C8E-4300-8891-C52633DDF5D9} diff --git a/TableClient.Legacy.Sample/TableClient.LegacySample.csproj b/TableClient.Legacy.Sample/TableClient.LegacySample.csproj deleted file mode 100644 index 45dc5ff..0000000 --- a/TableClient.Legacy.Sample/TableClient.LegacySample.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - Exe - netcoreapp3.1 - - - - - - - - - - - - - - - - PreserveNewest - - - - diff --git a/samples/BlobClient.DependencyInjection.Sample/BlobClient.DependencyInjection.Sample.csproj b/samples/BlobClient.DependencyInjection.Sample/BlobClient.DependencyInjection.Sample.csproj index 43362f5..02fe54f 100644 --- a/samples/BlobClient.DependencyInjection.Sample/BlobClient.DependencyInjection.Sample.csproj +++ b/samples/BlobClient.DependencyInjection.Sample/BlobClient.DependencyInjection.Sample.csproj @@ -12,10 +12,10 @@ - + diff --git a/samples/BlobClient.Sample/BlobClient.BasicSample.csproj b/samples/BlobClient.Sample/BlobClient.BasicSample.csproj index 4effcd7..3568bf1 100644 --- a/samples/BlobClient.Sample/BlobClient.BasicSample.csproj +++ b/samples/BlobClient.Sample/BlobClient.BasicSample.csproj @@ -6,7 +6,7 @@ - + diff --git a/Common.Samples/Common.Samples.csproj b/samples/Common.Samples/Common.Samples.csproj similarity index 100% rename from Common.Samples/Common.Samples.csproj rename to samples/Common.Samples/Common.Samples.csproj diff --git a/Common.Samples/ConsoleExtensions.cs b/samples/Common.Samples/ConsoleExtensions.cs similarity index 100% rename from Common.Samples/ConsoleExtensions.cs rename to samples/Common.Samples/ConsoleExtensions.cs diff --git a/Common.Samples/Diagnostics/EntityChangesObserver.cs b/samples/Common.Samples/Diagnostics/EntityChangesObserver.cs similarity index 100% rename from Common.Samples/Diagnostics/EntityChangesObserver.cs rename to samples/Common.Samples/Diagnostics/EntityChangesObserver.cs diff --git a/Common.Samples/Diagnostics/IPerfCounter.cs b/samples/Common.Samples/Diagnostics/IPerfCounter.cs similarity index 100% rename from Common.Samples/Diagnostics/IPerfCounter.cs rename to samples/Common.Samples/Diagnostics/IPerfCounter.cs diff --git a/Common.Samples/Diagnostics/IPerfCounters.cs b/samples/Common.Samples/Diagnostics/IPerfCounters.cs similarity index 100% rename from Common.Samples/Diagnostics/IPerfCounters.cs rename to samples/Common.Samples/Diagnostics/IPerfCounters.cs diff --git a/Common.Samples/Diagnostics/PerfCounter.cs b/samples/Common.Samples/Diagnostics/PerfCounter.cs similarity index 100% rename from Common.Samples/Diagnostics/PerfCounter.cs rename to samples/Common.Samples/Diagnostics/PerfCounter.cs diff --git a/Common.Samples/Diagnostics/PerfCounters.cs b/samples/Common.Samples/Diagnostics/PerfCounters.cs similarity index 100% rename from Common.Samples/Diagnostics/PerfCounters.cs rename to samples/Common.Samples/Diagnostics/PerfCounters.cs diff --git a/Common.Samples/Diagnostics/PerfMesure.cs b/samples/Common.Samples/Diagnostics/PerfMesure.cs similarity index 100% rename from Common.Samples/Diagnostics/PerfMesure.cs rename to samples/Common.Samples/Diagnostics/PerfMesure.cs diff --git a/Common.Samples/Fakers.cs b/samples/Common.Samples/Fakers.cs similarity index 100% rename from Common.Samples/Fakers.cs rename to samples/Common.Samples/Fakers.cs diff --git a/Common.Samples/Models/Address.cs b/samples/Common.Samples/Models/Address.cs similarity index 100% rename from Common.Samples/Models/Address.cs rename to samples/Common.Samples/Models/Address.cs diff --git a/Common.Samples/Models/AdressType.cs b/samples/Common.Samples/Models/AdressType.cs similarity index 100% rename from Common.Samples/Models/AdressType.cs rename to samples/Common.Samples/Models/AdressType.cs diff --git a/Common.Samples/Models/DocumentEntity.cs b/samples/Common.Samples/Models/DocumentEntity.cs similarity index 100% rename from Common.Samples/Models/DocumentEntity.cs rename to samples/Common.Samples/Models/DocumentEntity.cs diff --git a/Common.Samples/Models/HttpTraceEntity.cs b/samples/Common.Samples/Models/HttpTraceEntity.cs similarity index 100% rename from Common.Samples/Models/HttpTraceEntity.cs rename to samples/Common.Samples/Models/HttpTraceEntity.cs diff --git a/Common.Samples/Models/MessageModel.cs b/samples/Common.Samples/Models/MessageModel.cs similarity index 100% rename from Common.Samples/Models/MessageModel.cs rename to samples/Common.Samples/Models/MessageModel.cs diff --git a/Common.Samples/Models/PersonDashboard.cs b/samples/Common.Samples/Models/PersonDashboard.cs similarity index 100% rename from Common.Samples/Models/PersonDashboard.cs rename to samples/Common.Samples/Models/PersonDashboard.cs diff --git a/Common.Samples/Models/PersonEntity.cs b/samples/Common.Samples/Models/PersonEntity.cs similarity index 100% rename from Common.Samples/Models/PersonEntity.cs rename to samples/Common.Samples/Models/PersonEntity.cs diff --git a/Common.Samples/TestEnvironment.cs b/samples/Common.Samples/TestEnvironment.cs similarity index 100% rename from Common.Samples/TestEnvironment.cs rename to samples/Common.Samples/TestEnvironment.cs diff --git a/samples/TableClient.Basic.Sample/TableClient.BasicSample.csproj b/samples/TableClient.Basic.Sample/TableClient.BasicSample.csproj index a078216..b9ffb5b 100644 --- a/samples/TableClient.Basic.Sample/TableClient.BasicSample.csproj +++ b/samples/TableClient.Basic.Sample/TableClient.BasicSample.csproj @@ -6,9 +6,9 @@ - + diff --git a/samples/TableClient.DependencyInjection.AdvancedSample/TableClient.DependencyInjection.AdvancedSample.csproj b/samples/TableClient.DependencyInjection.AdvancedSample/TableClient.DependencyInjection.AdvancedSample.csproj index 3c164c1..c5e93ea 100644 --- a/samples/TableClient.DependencyInjection.AdvancedSample/TableClient.DependencyInjection.AdvancedSample.csproj +++ b/samples/TableClient.DependencyInjection.AdvancedSample/TableClient.DependencyInjection.AdvancedSample.csproj @@ -12,7 +12,7 @@ - + diff --git a/samples/TableClient.DependencyInjection.BasicSample/TableClient.DependencyInjection.BasicSample.csproj b/samples/TableClient.DependencyInjection.BasicSample/TableClient.DependencyInjection.BasicSample.csproj index 3c164c1..c5e93ea 100644 --- a/samples/TableClient.DependencyInjection.BasicSample/TableClient.DependencyInjection.BasicSample.csproj +++ b/samples/TableClient.DependencyInjection.BasicSample/TableClient.DependencyInjection.BasicSample.csproj @@ -12,7 +12,7 @@ - + diff --git a/samples/TableClient.DependencyInjection.ProjectionSample/TableClient.DependencyInjection.ProjectionSample.csproj b/samples/TableClient.DependencyInjection.ProjectionSample/TableClient.DependencyInjection.ProjectionSample.csproj index 3c164c1..c5e93ea 100644 --- a/samples/TableClient.DependencyInjection.ProjectionSample/TableClient.DependencyInjection.ProjectionSample.csproj +++ b/samples/TableClient.DependencyInjection.ProjectionSample/TableClient.DependencyInjection.ProjectionSample.csproj @@ -12,7 +12,7 @@ - + diff --git a/TableClient.Legacy.Sample/Program.cs b/samples/TableClient.Legacy.Sample/Program.cs similarity index 100% rename from TableClient.Legacy.Sample/Program.cs rename to samples/TableClient.Legacy.Sample/Program.cs diff --git a/TableClient.Legacy.Sample/SampleConsole.cs b/samples/TableClient.Legacy.Sample/SampleConsole.cs similarity index 100% rename from TableClient.Legacy.Sample/SampleConsole.cs rename to samples/TableClient.Legacy.Sample/SampleConsole.cs diff --git a/samples/TableClient.Legacy.Sample/TableClient.LegacySample.csproj b/samples/TableClient.Legacy.Sample/TableClient.LegacySample.csproj new file mode 100644 index 0000000..652feeb --- /dev/null +++ b/samples/TableClient.Legacy.Sample/TableClient.LegacySample.csproj @@ -0,0 +1,25 @@ + + + + Exe + netcoreapp3.1 + + + + + + + + + + + + + + + + PreserveNewest + + + + diff --git a/TableClient.Legacy.Sample/appsettings.json b/samples/TableClient.Legacy.Sample/appsettings.json similarity index 100% rename from TableClient.Legacy.Sample/appsettings.json rename to samples/TableClient.Legacy.Sample/appsettings.json diff --git a/samples/TableClient.Performance.Sample/TableClient.PerformanceSample.csproj b/samples/TableClient.Performance.Sample/TableClient.PerformanceSample.csproj index a078216..9a54d2f 100644 --- a/samples/TableClient.Performance.Sample/TableClient.PerformanceSample.csproj +++ b/samples/TableClient.Performance.Sample/TableClient.PerformanceSample.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/Azure.EntityServices.Queries/Core/BaseQueryExpressionBuilder.cs b/src/Azure.EntityServices.Queries/Core/BaseQueryExpressionBuilder.cs index 97a310d..d17eb6a 100644 --- a/src/Azure.EntityServices.Queries/Core/BaseQueryExpressionBuilder.cs +++ b/src/Azure.EntityServices.Queries/Core/BaseQueryExpressionBuilder.cs @@ -30,13 +30,14 @@ protected virtual string Build(IFilterExpression expression) if (expression.Group.Count > 0) { foreach (var operation in expression.Group) - { + { queryBuilder.Append($" {InstructionsProvider.Get(operation.GroupOperator)} ("); queryBuilder.Append(Build(operation)); queryBuilder.Append(")"); } - } + } queryBuilder.Append($" {InstructionsProvider.Get(expression.Operator)} "); + queryBuilder.Append(Build(expression.NextOperation)); return queryBuilder.ToString().Trim(); diff --git a/src/Azure.EntityServices.Queries/FilterExpression.cs b/src/Azure.EntityServices.Queries/FilterExpression.cs index 02b0f5d..818deeb 100644 --- a/src/Azure.EntityServices.Queries/FilterExpression.cs +++ b/src/Azure.EntityServices.Queries/FilterExpression.cs @@ -30,7 +30,7 @@ public virtual IFilterExpression Factory

() public List> Group { get; } = new List>(); public IFilterExpression NextOperation { get; set; } - public IFilterExpression LastOperation { get; set; } + public IFilterExpression PrevOperation { get; set; } public IQueryFilter AddOperator

(string expressionOperator, Expression> property) { @@ -40,7 +40,7 @@ public IQueryFilter AddOperator

(string expressionOperator, Expression; @@ -53,7 +53,7 @@ public IQueryFilter AddOperator(string expressionOperator, string property) newOperation.PropertyName = property; newOperation.PropertyType = typeof(object); - newOperation.LastOperation = this; + newOperation.PrevOperation = this; NextOperation = newOperation; return newOperation; diff --git a/src/Azure.EntityServices.Queries/HelperExtensions/DynamicQueryExtensions.cs b/src/Azure.EntityServices.Queries/HelperExtensions/DynamicQueryExtensions.cs index 40765c5..14d4a31 100644 --- a/src/Azure.EntityServices.Queries/HelperExtensions/DynamicQueryExtensions.cs +++ b/src/Azure.EntityServices.Queries/HelperExtensions/DynamicQueryExtensions.cs @@ -36,14 +36,16 @@ public static IFilterOperator WithEach(this IFilterOperator query, I public static IFilterOperator NotIn(this IQueryFilter query, params P[] values) { var exp = query as IFilterExpression; - - exp.LastOperation.AddGroupExpression(string.IsNullOrEmpty(exp.LastOperation.PropertyName) ? "" : "And", + + exp.PrevOperation.AddGroupExpression(string.IsNullOrEmpty(exp.PrevOperation.PropertyName) ? "" : "And", p => p.Where(exp.PropertyName) ._NotIn(values)); + + //ignore current expression because we need override and keep the previous expression exp.PropertyName = null; exp.Operator = null; - - return exp.LastOperation; + exp.PrevOperation.Operator = null; + return exp.PrevOperation; } ///

/// Build a filter to check if current field value was present in given list @@ -58,13 +60,15 @@ public static IFilterOperator In(this IQueryFilter query, params var exp = query as IFilterExpression; - exp.LastOperation.AddGroupExpression(string.IsNullOrEmpty(exp.LastOperation.PropertyName) ? "" : "And", + exp.PrevOperation.AddGroupExpression(string.IsNullOrEmpty(exp.PrevOperation.PropertyName) ? "" : "And", p => p.Where(exp.PropertyName) ._In(values)); + + //ignore current expression because we need override and keep the previous expression exp.PropertyName = null; exp.Operator = null; - - return exp.LastOperation; + exp.PrevOperation.Operator = null; + return exp.PrevOperation; } private static IFilterOperator _In(this IQueryFilter query, P[] values) @@ -75,7 +79,7 @@ private static IFilterOperator _In(this IQueryFilter query, P[] valu nextQuery = (IQuery)(nextQuery as IQueryFilter) .Equal(item) .Or((query as IFilterExpression).PropertyName); - } + } (nextQuery as IQueryFilter).Equal(values.Last()); return nextQuery as IFilterOperator; } diff --git a/src/Azure.EntityServices.Queries/IQueryExpression.cs b/src/Azure.EntityServices.Queries/IQueryExpression.cs index e8a2705..11a3482 100644 --- a/src/Azure.EntityServices.Queries/IQueryExpression.cs +++ b/src/Azure.EntityServices.Queries/IQueryExpression.cs @@ -13,6 +13,6 @@ public interface IFilterExpression : IFilterOperator, IQueryFilter, IQu List> Group { get; } public string GroupOperator { get; set; } IFilterExpression NextOperation { get; set; } - IFilterExpression LastOperation { get; set; } + IFilterExpression PrevOperation { get; set; } } } \ No newline at end of file diff --git a/tests/Azure.EntityServices.Tests/Azure.EntityServices.Tests.csproj b/tests/Azure.EntityServices.Tests/Azure.EntityServices.Tests.csproj index f1e593a..d417de7 100644 --- a/tests/Azure.EntityServices.Tests/Azure.EntityServices.Tests.csproj +++ b/tests/Azure.EntityServices.Tests/Azure.EntityServices.Tests.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -15,7 +15,7 @@ - + diff --git a/tests/Azure.EntityServices.Tests/QueryExpressions/ExpressionBuilderTests.cs b/tests/Azure.EntityServices.Tests/QueryExpressions/ExpressionBuilderTests.cs index 632235f..04d397c 100644 --- a/tests/Azure.EntityServices.Tests/QueryExpressions/ExpressionBuilderTests.cs +++ b/tests/Azure.EntityServices.Tests/QueryExpressions/ExpressionBuilderTests.cs @@ -113,7 +113,7 @@ public void Should_Build_TableStorage_Query_Expression_With_Grouped_Filter_Insid .AndNot(p => p .Where(p => p.Created).GreaterThan(DateTimeOffset.Parse("2012-04-21T18:25:43Z")) .Or(p => p.Created).LessThan(DateTimeOffset.Parse("2012-04-21T18:25:43Z"))) - .OrNot(p => p.Where(p=>p.Enabled).Equal(true)); + .OrNot(p => p.Where(p => p.Enabled).Equal(true)); var queryStr = builder.Build(); @@ -166,55 +166,57 @@ public void Should_BuildGroup_Dynamic_Query_Expression_In_Extension_Helper() var dynamicQuery = builder.Query .Where(p => p.TenantId).Equal("50") - .And(p => p.LastName) - .In("Doe"); + .And(p => p.LastName).In("Doe"); var queryStr = builder.Build(); queryStr.Trim() .Should() - .Be("TenantId Equal '50' And LastName Equal 'Doe'"); + .Be("TenantId Equal '50' And (LastName Equal 'Doe')"); dynamicQuery = builder.Query .Where(p => p.TenantId).Equal("50") - .And(p=>p - .Where("LastName") - .In("Doe", "Kent")); - + .And("LastName") + .In("Doe", "Kent"); queryStr = builder.Build(); queryStr.Trim() .Should() - .Be("TenantId Equal '50' And LastName Equal 'Doe' Or LastName Equal 'Kent'"); + .Be("TenantId Equal '50' And (LastName Equal 'Doe' Or LastName Equal 'Kent')"); } [TestMethod] - public void Should_BuildGroup_Dynamic_Query_Expression_NotIn_Extension_Helper() + public void Should_BuildGroup_Dynamic_SubQuery_With_In_Extension_Helper() { var builder = new MockedExpressionBuilder(); - - var dynamicQuery = builder.Query - .Where(p => p.TenantId).Equal("50") - .And(p => p.LastName) - .NotIn("Doe"); + builder.Query + .Where(p => p.TenantId).Equal("50") + .And(p => p + .Where("LastName") + .In("Doe", "Kent")); var queryStr = builder.Build(); queryStr.Trim() .Should() - .Be("TenantId Equal '50' And LastName NotEqual 'Doe'"); + .Be("TenantId Equal '50' And ((LastName Equal 'Doe' Or LastName Equal 'Kent'))"); + } - dynamicQuery = builder.Query - .Where(p => p.TenantId).Equal("50") - .And("LastName") - .NotIn("Doe", "Kent"); + [TestMethod] + public void Should_BuildGroup_Dynamic_Query_Expression_NotIn_Extension_Helper() + { + var builder = new MockedExpressionBuilder(); - queryStr = builder.Build(); + builder.Query + .Where(p => p.TenantId).Equal("50") + .And("LastName").NotIn("Doe", "Kent"); + + var queryStr = builder.Build(); queryStr.Trim() .Should() - .Be("TenantId Equal '50' And LastName NotEqual 'Doe' And LastName NotEqual 'Kent'"); + .Be("TenantId Equal '50' And (LastName NotEqual 'Doe' And LastName NotEqual 'Kent')"); } } } \ No newline at end of file diff --git a/tests/Azure.EntityServices.Tests/QueryExpressions/TableStorageQueryBuilderTests.cs b/tests/Azure.EntityServices.Tests/QueryExpressions/TableStorageQueryBuilderTests.cs index 4e6556a..f96f3fe 100644 --- a/tests/Azure.EntityServices.Tests/QueryExpressions/TableStorageQueryBuilderTests.cs +++ b/tests/Azure.EntityServices.Tests/QueryExpressions/TableStorageQueryBuilderTests.cs @@ -21,7 +21,8 @@ public void Should_Build_TableStorage_Query_Expression() .And(p => p.TenantId).Equal("10") .And(p => p .Where(p => p.Created).GreaterThan(DateTimeOffset.Parse("2012-04-21T18:25:43Z")) - .Or(p => p.Created).LessThan(DateTimeOffset.Parse("2012-04-21T18:25:43Z"))) + .Or(p => p.Created).LessThan(DateTimeOffset.Parse("2012-04-21T18:25:43Z")) + ) .And(p => p.Enabled).Equal(true); var queryStr = builder.Build(); @@ -70,8 +71,7 @@ public void Should_Use_Tag_GreaterThanOrEqual_Extension() var builder = new TableStorageQueryBuilder(new TagFilterExpression()); (builder.Query as TagFilterExpression) - .WhereTag("Created") - .GreaterThanOrEqual("2022-10-22") + .WhereTag("Created").GreaterThanOrEqual("2022-10-22") .And(p => p.TenantId).Equal("10"); var queryStr = builder.Build(); @@ -87,8 +87,7 @@ public void Should_Use_Tag_LessThanOrEqual_Extension() var builder = new TableStorageQueryBuilder(new TagFilterExpression()); (builder.Query as TagFilterExpression) - .WhereTag("Created") - .LessThanOrEqual("2022-10-22") + .WhereTag("Created").LessThanOrEqual("2022-10-22") .And(p => p.TenantId).Equal("10"); var queryStr = builder.Build(); @@ -143,14 +142,10 @@ public void Should_Build_Table_Filter_Expression_With_Invariant_Floating_Point_V var builder = new TableStorageQueryBuilder(new FilterExpression()); builder .Query - .WherePartitionKey() - .Equal("tenantId") - .And(p => p.Latitude) - .Equal(48.77309806265856) - .And(p => p.Distance) - .Equal(148.45648566856M) - .And(p => p.BankAmount) - .Equal(1248.7731F); + .WherePartitionKey().Equal("tenantId") + .And(p => p.Latitude).Equal(48.77309806265856) + .And(p => p.Distance).Equal(148.45648566856M) + .And(p => p.BankAmount).Equal(1248.7731F); var result = builder.Build(); result.Should() @@ -163,12 +158,9 @@ public void Should_Use_Multi_PartitionKey_filter() var builder = new TableStorageQueryBuilder(new TagFilterExpression("Created")); (builder.Query as TagFilterExpression) - .WherePartitionKey() - .Equal("partition1") - .OrPartitionKey() - .Equal("partition2") - .OrPartitionKey() - .Equal("Partition3"); + .WherePartitionKey().Equal("partition1") + .OrPartitionKey().Equal("partition2") + .OrPartitionKey().Equal("Partition3"); var queryStr = builder.Build(); @@ -199,8 +191,7 @@ public void Should_Use_IncludeTags_To_Get_All_Entities_Included_All_Tags() (builder.Query as TagFilterExpression) .IncludeTags() - .WherePartitionKey() - .Equal("tenant1"); + .WherePartitionKey().Equal("tenant1"); var queryStr = builder.Build(); @@ -215,8 +206,7 @@ public void Should_Use_In_Filter_With_Tag_Prop() var builder = new TableStorageQueryBuilder(new TagFilterExpression()); (builder.Query as TagFilterExpression) - .Where("PartitionKey") - .In("value1", "value2", "value3"); + .Where("PartitionKey").In("value1", "value2", "value3"); var queryStr = builder.Build(); queryStr.Trim() @@ -230,12 +220,9 @@ public void Should_Use_In_Filter_Inside_ExpressionFilter_Prop2() var builder = new TableStorageQueryBuilder(new TagFilterExpression()); (builder.Query as TagFilterExpression) - .Where("prop1s") - .Equal("value") - .And("tenant1") - .In("tag1", "tag2", "tag3") - .And("prop2") - .Equal("newValue"); + .Where("prop1s").Equal("value") + .And("tenant1").In("tag1", "tag2", "tag3") + .And("prop2").Equal("newValue"); var queryStr = builder.Build(); @@ -250,10 +237,8 @@ public void Should_Use_In_Filter_At_Start_Of_ExpressionFilter_Prop2() var builder = new TableStorageQueryBuilder(new TagFilterExpression()); (builder.Query as TagFilterExpression) - .Where("tenant1") - .In("tag1", "tag2", "tag3") - .And("prop2") - .Equal("newValue"); + .Where("tenant1").In("tag1", "tag2", "tag3") + .And("prop2").Equal("newValue"); var queryStr = builder.Build(); @@ -268,8 +253,7 @@ public void Should_Use_NotIn_Filter_With_Tag_Prop() var builder = new TableStorageQueryBuilder(new TagFilterExpression()); (builder.Query as TagFilterExpression) - .Where("PartitionKey") - .NotIn("value1", "value2", "value3"); + .Where("PartitionKey").NotIn("value1", "value2", "value3"); var queryStr = builder.Build(); queryStr.Trim() @@ -278,17 +262,14 @@ public void Should_Use_NotIn_Filter_With_Tag_Prop() } [TestMethod] - public void Should_Use_NotIn_Filter_Inside_ExpressionFilter_Prop2() + public void Should_Use_NotIn_Filter_Inside_ExpressionFilter() { var builder = new TableStorageQueryBuilder(new TagFilterExpression()); (builder.Query as TagFilterExpression) - .Where("prop1s") - .Equal("value") - .And("tenant1") - .NotIn("tag1", "tag2", "tag3") - .And("prop2") - .Equal("newValue"); + .Where("prop1s").Equal("value") + .And("tenant1").NotIn("tag1", "tag2", "tag3") + .And("prop2").Equal("newValue"); var queryStr = builder.Build(); @@ -298,15 +279,13 @@ public void Should_Use_NotIn_Filter_Inside_ExpressionFilter_Prop2() } [TestMethod] - public void Should_Use_NotIn_Filter_At_Start_Of_ExpressionFilter_Prop2() + public void Should_Use_NotIn_Filter_At_Start_Of_ExpressionFilter() { var builder = new TableStorageQueryBuilder(new TagFilterExpression()); (builder.Query as TagFilterExpression) - .Where("tenant1") - .NotIn("tag1", "tag2", "tag3") - .And("prop2") - .Equal("newValue"); + .Where("tenant1").NotIn("tag1", "tag2", "tag3") + .And("prop2").Equal("newValue"); var queryStr = builder.Build(); @@ -314,5 +293,17 @@ public void Should_Use_NotIn_Filter_At_Start_Of_ExpressionFilter_Prop2() .Should() .Be("(tenant1 ne 'tag1' and tenant1 ne 'tag2' and tenant1 ne 'tag3') and prop2 eq 'newValue'"); } + [TestMethod] + public void Should_Use_NotIn_Filter_At_End_Of_ExpressionFilter() + { + var builder = new TableStorageQueryBuilder(new TagFilterExpression()); + + (builder.Query as TagFilterExpression) + .Where("tenant1").NotIn("tag1", "tag2", "tag3"); + var queryStr = builder.Build(); + queryStr.Trim() + .Should() + .Be("(tenant1 ne 'tag1' and tenant1 ne 'tag2' and tenant1 ne 'tag3')"); + } } } \ No newline at end of file