From dbe271949cc62515e3727c85aa34c5c4604f306f Mon Sep 17 00:00:00 2001 From: Aditya Sarpotdar Date: Thu, 27 Apr 2023 14:55:28 +0000 Subject: [PATCH] Initial commit --- .../src/Linq/TranslationContext.cs | 6 +++ .../BaselineTest/BaselineTests.cs | 4 +- ...nqGeneralBaselineTests.TestLambdaReuse.xml | 38 +++++++++++++++++++ .../LinqGeneralBaselineTests.cs | 21 +++++++++- ...icrosoft.Azure.Cosmos.EmulatorTests.csproj | 6 +++ 5 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.TestLambdaReuse.xml diff --git a/Microsoft.Azure.Cosmos/src/Linq/TranslationContext.cs b/Microsoft.Azure.Cosmos/src/Linq/TranslationContext.cs index 9205052604..8fc95d8701 100644 --- a/Microsoft.Azure.Cosmos/src/Linq/TranslationContext.cs +++ b/Microsoft.Azure.Cosmos/src/Linq/TranslationContext.cs @@ -119,6 +119,7 @@ public void PopParameter() { ParameterExpression last = this.lambdaParametersStack[this.lambdaParametersStack.Count - 1]; this.lambdaParametersStack.RemoveAt(this.lambdaParametersStack.Count - 1); + this.substitutions.Remove(last); } /// @@ -337,6 +338,11 @@ public Expression Lookup(ParameterExpression parameter) return null; } + internal void Remove(ParameterExpression parameter) + { + this.substitutionTable.Remove(parameter); + } + public const string InputParameterName = "root"; } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/BaselineTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/BaselineTests.cs index e9fbc54267..62f20f1fe4 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/BaselineTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/BaselineTests.cs @@ -153,8 +153,8 @@ public void ExecuteTestSuite(IEnumerable inputs, [CallerMemberName] stri Please run the ..\azure-cosmos-dotnet-v3\UpdateContracts.ps1 script to update the baselines. Expected: {baselineTextSuffix}, Actual: {outputTextSuffix}, - OutputPath: {outputPath}, - BaselinePath: {baselinePath}"); + OutputPath: {Path.GetFullPath(outputPath)}, + BaselinePath: {Path.GetFullPath(baselinePath)}"); } /// diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.TestLambdaReuse.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.TestLambdaReuse.xml new file mode 100644 index 0000000000..bd2e168e76 --- /dev/null +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.TestLambdaReuse.xml @@ -0,0 +1,38 @@ + + + + Where with same predicate instance]]> + + + + + + + + + Select with same predicate instance]]> + + + + + + + + + Select -> Where with same predicate instance]]> + new AnonymousType(Int = 10, Result = c)).Where(DisplayClass.predicate2)]]> + + + + + + \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqGeneralBaselineTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqGeneralBaselineTests.cs index a9782bb26b..3fc3aff900 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqGeneralBaselineTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/LinqGeneralBaselineTests.cs @@ -1272,6 +1272,25 @@ orderby f.FamilyId descending this.ExecuteTestSuite(inputs); } + [TestMethod] + public void TestLambdaReuse() + { + List inputs = new List(); + + System.Linq.Expressions.Expression> predicate = f => f.Int == 5; + inputs.Add(new LinqTestInput("Where -> Where with same predicate instance", b => getQuery(b).Where(predicate).Where(predicate))); + inputs.Add(new LinqTestInput("Where -> Select with same predicate instance", b => getQuery(b).Where(predicate).Select(predicate))); + + System.Linq.Expressions.Expression> predicate2 = f => f.ToString() == "a"; + inputs.Add(new LinqTestInput("Where -> Select -> Where with same predicate instance", + b => getQuery(b) + .Where(predicate2) + .Select(c => new { Int = 10, Result = c }) + .Where(predicate2))); + + this.ExecuteTestSuite(inputs); + } + [TestMethod] public void TestThenByTranslation() { @@ -1922,7 +1941,7 @@ public async Task ValidateLinqQueries() Gender = "female", Grade = 1, Pets = new List() { pet, new Pet() { GivenName = "koko" } }, - Things = new Dictionary() { { "A", "B" }, { "C", "D" } }, + Things = new Dictionary() { { "A", "B" }, { "C", "D" } } }; Address address = new Address { State = "NY", County = "Manhattan", City = "NY" }; diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Microsoft.Azure.Cosmos.EmulatorTests.csproj b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Microsoft.Azure.Cosmos.EmulatorTests.csproj index a504adc855..51891d7e3f 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Microsoft.Azure.Cosmos.EmulatorTests.csproj +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Microsoft.Azure.Cosmos.EmulatorTests.csproj @@ -35,6 +35,7 @@ + @@ -283,6 +284,11 @@ + + + PreserveNewest + + PreserveNewest