Skip to content

Commit

Permalink
feat!: updated for dotnet 9
Browse files Browse the repository at this point in the history
  • Loading branch information
pksorensen committed Nov 12, 2024
1 parent 9b49e7b commit b30eb35
Show file tree
Hide file tree
Showing 16 changed files with 175 additions and 215 deletions.
11 changes: 6 additions & 5 deletions ExpressionEngine/ExpressionEngine.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net8.0;net48;net462</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0;net48;net462</TargetFrameworks>

<PackageId>Delegate.ExpressionEngine</PackageId>
<Authors>Delegate A/S,thygesteffensen</Authors>
Expand All @@ -26,19 +26,20 @@

</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />

</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />

</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Sprache" Version="2.3.1" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Globalization;
using System.Globalization;
using System.Threading.Tasks;
using ExpressionEngine.Functions.Base;
using ExpressionEngine.Functions.CustomException;
Expand Down
4 changes: 2 additions & 2 deletions Test/Expression/GenericExpressionTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Threading.Tasks;
using ExpressionEngine;
using ExpressionEngine.Functions.Base;
using NUnit.Framework;
using NUnit.Framework;using NUnit.Framework.Legacy;

namespace Test.Expression
{
Expand All @@ -18,7 +18,7 @@ public async Task TestFunction(IFunction func, string name,
{
var result = await func.ExecuteFunction(parameters);

Assert.AreEqual(expected, result);
ClassicAssert.AreEqual(expected, result);
}
}
}
23 changes: 12 additions & 11 deletions Test/Expression/StringFunctionTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using ExpressionEngine;
using ExpressionEngine.Functions.Implementations.StringFunctions;
using NUnit.Framework;
using NUnit.Framework;using NUnit.Framework.Legacy;
using NUnit.Framework.Legacy;

namespace Test.Expression
{
Expand Down Expand Up @@ -188,15 +189,15 @@ public async Task GuidFunctionTest()

var result1 = await func.ExecuteFunction();

Assert.AreEqual(36, result1.GetValue<string>().Length);
ClassicAssert.AreEqual(36, result1.GetValue<string>().Length);

var result2 = await func.ExecuteFunction(new ValueContainer("N"));

Assert.AreEqual(32, result2.GetValue<string>().Length);
ClassicAssert.AreEqual(32, result2.GetValue<string>().Length);

var result3 = await func.ExecuteFunction(new ValueContainer("B"));

Assert.AreEqual(38, result3.GetValue<string>().Length);
ClassicAssert.AreEqual(38, result3.GetValue<string>().Length);
}

[Test]
Expand All @@ -209,13 +210,13 @@ public async Task SplitFunctionTest()

var array = result1.GetValue<List<ValueContainer>>();

Assert.AreEqual(5, array.Count);
ClassicAssert.AreEqual(5, array.Count);

Assert.AreEqual("This is ", array[0].GetValue<string>());
Assert.AreEqual(" a ", array[1].GetValue<string>());
Assert.AreEqual(" ", array[2].GetValue<string>());
Assert.AreEqual("litted ", array[3].GetValue<string>());
Assert.AreEqual(" string", array[4].GetValue<string>());
ClassicAssert.AreEqual("This is ", array[0].GetValue<string>());
ClassicAssert.AreEqual(" a ", array[1].GetValue<string>());
ClassicAssert.AreEqual(" ", array[2].GetValue<string>());
ClassicAssert.AreEqual("litted ", array[3].GetValue<string>());
ClassicAssert.AreEqual(" string", array[4].GetValue<string>());
}
}
}
51 changes: 26 additions & 25 deletions Test/ExpressionGrammarTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using ExpressionEngine;
using ExpressionEngine.Functions.Base;
using ExpressionEngine.Functions.CustomException;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using NUnit.Framework;using NUnit.Framework.Legacy;
using NUnit.Framework.Legacy;

namespace Test
{
Expand Down Expand Up @@ -48,7 +49,7 @@ public async Task IndicesTest()

var result = await _expressionGrammar.EvaluateToString(expressionString);

Assert.AreEqual("value", result);
ClassicAssert.AreEqual("value", result);
}

[Test]
Expand All @@ -58,16 +59,16 @@ public async Task BooleanTest()

await _expressionGrammar.EvaluateToValueContainer(expressionString);

Assert.NotNull(_dummyFunction.Parameters);
Assert.AreEqual(2, _dummyFunction.Parameters.Length);
ClassicAssert.NotNull(_dummyFunction.Parameters);
ClassicAssert.AreEqual(2, _dummyFunction.Parameters.Length);
var param1 = _dummyFunction.Parameters[0];
var param2 = _dummyFunction.Parameters[1];
Assert.NotNull(param1);
Assert.NotNull(param2);
Assert.AreEqual(ValueType.Boolean, param1.Type());
Assert.AreEqual(ValueType.Boolean, param2.Type());
Assert.AreEqual(true, param1.GetValue<bool>());
Assert.AreEqual(false, param2.GetValue<bool>());
ClassicAssert.NotNull(param1);
ClassicAssert.NotNull(param2);
ClassicAssert.AreEqual(ValueType.Boolean, param1.Type());
ClassicAssert.AreEqual(ValueType.Boolean, param2.Type());
ClassicAssert.AreEqual(true, param1.GetValue<bool>());
ClassicAssert.AreEqual(false, param2.GetValue<bool>());
}

[Test]
Expand All @@ -79,8 +80,8 @@ public async Task NullConditional()

var result = await _expressionGrammar.EvaluateToValueContainer(expressionString);

Assert.NotNull(result);
Assert.AreEqual(ValueType.Null, result.Type());
ClassicAssert.NotNull(result);
ClassicAssert.AreEqual(ValueType.Null, result.Type());
}

[Test]
Expand All @@ -90,10 +91,10 @@ public async Task IndexOnNonObject()

const string expressionString = "@dummyFunction()?.name1";

var exception = Assert.ThrowsAsync<InvalidTemplateException>(async () =>
var exception = ClassicAssert.ThrowsAsync<InvalidTemplateException>(async () =>
await _expressionGrammar.EvaluateToValueContainer(expressionString));

Assert.AreEqual("Unable to process template language expressions in action 'Compose' inputs " +
ClassicAssert.AreEqual("Unable to process template language expressions in action 'Compose' inputs " +
"at line 'x' and column 'y': 'The template language expression 'dummyFunction()?.name1' cannot be " +
"evaluated because property 'name1' cannot be selected. Property selection is not supported on values " +
"of type 'String'.", exception.Message);
Expand All @@ -112,21 +113,21 @@ public async Task NegativeNumbers()

if (functionOutput != null && functionOutput.Type() == ValueType.String)
{
Assert.AreNotEqual(expressionString, functionOutput.GetValue<string>());
ClassicAssert.AreNotEqual(expressionString, functionOutput.GetValue<string>());
}

var functionParameters = _dummyFunction.Parameters;

Assert.AreEqual(4, functionParameters.Length);
Assert.AreEqual(ValueType.Integer, functionParameters[0].Type());
Assert.AreEqual(ValueType.Float, functionParameters[1].Type());
Assert.AreEqual(ValueType.Integer, functionParameters[2].Type());
Assert.AreEqual(ValueType.Float, functionParameters[3].Type());
ClassicAssert.AreEqual(4, functionParameters.Length);
ClassicAssert.AreEqual(ValueType.Integer, functionParameters[0].Type());
ClassicAssert.AreEqual(ValueType.Float, functionParameters[1].Type());
ClassicAssert.AreEqual(ValueType.Integer, functionParameters[2].Type());
ClassicAssert.AreEqual(ValueType.Float, functionParameters[3].Type());

Assert.AreEqual(expectedOutput1, functionParameters[0]);
Assert.AreEqual(expectedOutput2, functionParameters[1]);
Assert.AreEqual(expectedOutput3, functionParameters[2]);
Assert.AreEqual(expectedOutput4, functionParameters[3]);
ClassicAssert.AreEqual(expectedOutput1, functionParameters[0]);
ClassicAssert.AreEqual(expectedOutput2, functionParameters[1]);
ClassicAssert.AreEqual(expectedOutput3, functionParameters[2]);
ClassicAssert.AreEqual(expectedOutput4, functionParameters[3]);
}
}

Expand Down
13 changes: 7 additions & 6 deletions Test/FunctionDefinitionTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System;
using System.Threading.Tasks;
using ExpressionEngine;
using ExpressionEngine.Functions.CustomException;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using NUnit.Framework;using NUnit.Framework.Legacy;
using NUnit.Framework.Legacy;

namespace Test
{
Expand All @@ -27,21 +28,21 @@ public async Task TestFunctionDef()

var actualResult = await ee.Parse("@concat(addAndConcat(), '!')");

Assert.AreEqual(expectedResult, actualResult);
ClassicAssert.AreEqual(expectedResult, actualResult);
}

[TestCase]
public void TestFunctionException()
{
const string expectedMessage = "fromFunctionName cannot end in ()";

var exception = Assert.Throws<ArgumentError>(() =>
var exception = ClassicAssert.Throws<ArgumentError>(() =>
{
_serviceCollection.AddFunctionDefinition("addAndConcat()", "concat('result of 1+1 is: ', add(1,1))");
});

Assert.NotNull(exception);
Assert.AreEqual(expectedMessage,exception.Message);
ClassicAssert.NotNull(exception);
ClassicAssert.AreEqual(expectedMessage,exception.Message);
}
}
}
42 changes: 21 additions & 21 deletions Test/IndexTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using ExpressionEngine;
using ExpressionEngine.Functions.Base;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using NUnit.Framework;using NUnit.Framework.Legacy;

namespace Test
{
Expand Down Expand Up @@ -40,8 +40,8 @@ public async Task Test()

var output = await ee.ParseToValueContainer(str);

Assert.AreEqual(ValueType.Boolean, output.Type());
Assert.AreEqual(true, output.GetValue<bool>());
ClassicAssert.AreEqual(ValueType.Boolean, output.Type());
ClassicAssert.AreEqual(true, output.GetValue<bool>());
}

[Test]
Expand All @@ -52,8 +52,8 @@ public async Task Test1()

var output = await ee.ParseToValueContainer(str);

Assert.AreEqual(ValueType.Boolean, output.Type());
Assert.AreEqual(true, output.GetValue<bool>());
ClassicAssert.AreEqual(ValueType.Boolean, output.Type());
ClassicAssert.AreEqual(true, output.GetValue<bool>());
}

[Test]
Expand All @@ -64,8 +64,8 @@ public async Task Test2()

var output = await ee.ParseToValueContainer(str);

Assert.AreEqual(ValueType.Boolean, output.Type());
Assert.AreEqual(true, output.GetValue<bool>());
ClassicAssert.AreEqual(ValueType.Boolean, output.Type());
ClassicAssert.AreEqual(true, output.GetValue<bool>());
}

[Test]
Expand All @@ -76,8 +76,8 @@ public async Task Test3()

var output = await ee.ParseToValueContainer(str);

Assert.AreEqual(ValueType.Boolean, output.Type());
Assert.AreEqual(true, output.GetValue<bool>());
ClassicAssert.AreEqual(ValueType.Boolean, output.Type());
ClassicAssert.AreEqual(true, output.GetValue<bool>());
}

[Test]
Expand All @@ -88,8 +88,8 @@ public async Task Test4()

var output = await ee.ParseToValueContainer(str);

Assert.AreEqual(ValueType.Boolean, output.Type());
Assert.AreEqual(true, output.GetValue<bool>());
ClassicAssert.AreEqual(ValueType.Boolean, output.Type());
ClassicAssert.AreEqual(true, output.GetValue<bool>());
}


Expand All @@ -101,8 +101,8 @@ public async Task Test5()

var output = await ee.ParseToValueContainer(str);

Assert.AreEqual(ValueType.Object, output.Type());
Assert.AreEqual("John Doe", output.AsDict()["name"].GetValue<string>());
ClassicAssert.AreEqual(ValueType.Object, output.Type());
ClassicAssert.AreEqual("John Doe", output.AsDict()["name"].GetValue<string>());
}

[Test]
Expand All @@ -113,8 +113,8 @@ public async Task Test6()

var output = await ee.ParseToValueContainer(str);

Assert.AreEqual(ValueType.String, output.Type());
Assert.AreEqual("John Doe", output.GetValue<string>());
ClassicAssert.AreEqual(ValueType.String, output.Type());
ClassicAssert.AreEqual("John Doe", output.GetValue<string>());
}

[Test]
Expand All @@ -125,8 +125,8 @@ public async Task Test7()

var output = await ee.ParseToValueContainer(str);

Assert.AreEqual(ValueType.Object, output.Type());
Assert.AreEqual("John Doe", output.AsDict()["name"].GetValue<string>());
ClassicAssert.AreEqual(ValueType.Object, output.Type());
ClassicAssert.AreEqual("John Doe", output.AsDict()["name"].GetValue<string>());

var t = new ValueContainer();
}
Expand All @@ -140,8 +140,8 @@ public async Task Test8()

var output = await ee.ParseToValueContainer(str);

Assert.AreEqual(ValueType.String, output.Type());
Assert.AreEqual("John Doe", output.GetValue<string>());
ClassicAssert.AreEqual(ValueType.String, output.Type());
ClassicAssert.AreEqual("John Doe", output.GetValue<string>());
}

[Test]
Expand All @@ -152,8 +152,8 @@ public async Task Test9()

var output = await ee.ParseToValueContainer(str);

Assert.AreEqual(ValueType.String, output.Type());
Assert.AreEqual("John Doe", output.GetValue<string>());
ClassicAssert.AreEqual(ValueType.String, output.Type());
ClassicAssert.AreEqual("John Doe", output.GetValue<string>());
}
}
}
Loading

0 comments on commit b30eb35

Please sign in to comment.