Skip to content

Commit 5d3d1f5

Browse files
authored
Merge pull request #82 from codingseb/dev
Dev
2 parents b20c910 + 341b932 commit 5d3d1f5

9 files changed

+148
-104
lines changed

CodingSeb.ExpressionEvaluator.Tests/CodingSeb.ExpressionEvaluator.Tests.csproj

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@
44
<Company>Coding Seb</Company>
55
<Product>CodingSeb.ExpressionEvaluator.Tests</Product>
66
<Copyright>Copyright © Coding Seb 2018</Copyright>
7-
<TargetFrameworks>net45;netcoreapp2.1</TargetFrameworks>
7+
<TargetFrameworks>net47;netcoreapp2.1</TargetFrameworks>
88
<UserSecretsId>c4ac27fa-8b9c-4784-a284-7a9a06320537</UserSecretsId>
99
</PropertyGroup>
1010
<ItemGroup>
1111
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
12-
<PackageReference Include="NUnit" Version="3.12.0" />
13-
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
12+
<PackageReference Include="NUnit" Version="3.13.0" />
13+
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
1414
<PrivateAssets>all</PrivateAssets>
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
</PackageReference>
17-
<PackageReference Include="Shouldly" Version="3.0.2" />
18-
</ItemGroup>
19-
<ItemGroup>
17+
<PackageReference Include="Shouldly" Version="4.0.3" />
18+
</ItemGroup><ItemGroup>
2019
<Compile Update="OthersTests.cs" />
2120
<Compile Update="Resources.Designer.cs">
2221
<AutoGen>True</AutoGen>

CodingSeb.ExpressionEvaluator.Tests/ExpressionEvaluatorTests.cs

+52-11
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,6 @@ public static IEnumerable<TestCaseData> TestCasesForWithCustomVariablesExpressio
11791179
yield return new TestCaseData("expObj.NullValue ?? \"A\"", ExpandoObjectVariables, true).SetCategory("ExpandoObject").SetCategory("Instance Property").Returns("A");
11801180
#endregion
11811181

1182-
11831182
#endregion
11841183

11851184
#region Delegates as a variable
@@ -1494,7 +1493,7 @@ public static IEnumerable<TestCaseData> TestCasesForExceptionThrowingEvaluation
14941493
yield return new TestCaseData(evaluator, "false || 1/0>0", typeof(DivideByZeroException)).SetCategory("Conditional Or, positive left operand (should lead to exception associativity)");
14951494
yield return new TestCaseData(evaluator, "true && (true && 1/0>0)", typeof(DivideByZeroException)).SetCategory("Conditional And, positive left operand (should lead to exception)");
14961495
yield return new TestCaseData(evaluator, "false || (false || 1/0>0)", typeof(DivideByZeroException)).SetCategory("Conditional Or, positive left operand (should lead to exception associativity)");
1497-
1496+
14981497
#endregion
14991498
}
15001499
}
@@ -1509,6 +1508,48 @@ public void ExceptionThrowingEvaluation(ExpressionEvaluator evaluator, string ex
15091508

15101509
#endregion
15111510

1511+
#region Bug corrections
1512+
1513+
/// <summary>
1514+
/// To correct #81 Exception is assigned to variable
1515+
/// With simple variable
1516+
/// </summary>
1517+
[Test]
1518+
[Category("Bug")]
1519+
[Category("#81")]
1520+
public void Evaluate_WithException_ThrowsExceptionAndDoesNotAssignItSimpleVariable()
1521+
{
1522+
ExpressionEvaluator evaluator = new ExpressionEvaluator();
1523+
1524+
evaluator.Variables.Add("exceptionGenerator", new ExceptionGenerator());
1525+
Assert.Throws<ExpressionEvaluatorSyntaxErrorException>(() => evaluator.Evaluate("result = exceptionGenerator.ThrowAnException()"));
1526+
1527+
evaluator.Variables.ContainsKey("result").ShouldBeFalse();
1528+
}
1529+
1530+
/// <summary>
1531+
/// To correct #81 Exception is assigned to variable
1532+
/// With InObject
1533+
/// </summary>
1534+
[Test]
1535+
[Category("Bug")]
1536+
[Category("#81")]
1537+
public void Evaluate_WithException_ThrowsExceptionAndDoesNotAssignItInObject()
1538+
{
1539+
ExpressionEvaluator evaluator = new ExpressionEvaluator();
1540+
1541+
ObjectContainer objectContainer = new ObjectContainer();
1542+
1543+
evaluator.Variables.Add("exceptionGenerator", new ExceptionGenerator());
1544+
evaluator.Variables.Add("objectContainer", objectContainer);
1545+
Assert.Throws<ExpressionEvaluatorSyntaxErrorException>(() => evaluator.Evaluate("objectContainer.AnObjectProperty = exceptionGenerator.ThrowAnException()"));
1546+
1547+
objectContainer.AnObjectProperty.ShouldBeOfType(typeof(int));
1548+
objectContainer.AnObjectProperty.ShouldBe(10);
1549+
}
1550+
1551+
#endregion
1552+
15121553
#region EvaluateWithSpecificEvaluator
15131554

15141555
#region TestCasesEvaluateWithSpecificEvaluator
@@ -1596,9 +1637,9 @@ public static IEnumerable<TestCaseData> TestCasesEvaluateWithSpecificEvaluator
15961637
.SetCategory("Integer Numbers default types");
15971638

15981639
yield return new TestCaseData(new ExpressionEvaluator
1599-
{
1600-
OptionForceIntegerNumbersEvaluationsAsDoubleByDefault = false
1601-
}
1640+
{
1641+
OptionForceIntegerNumbersEvaluationsAsDoubleByDefault = false
1642+
}
16021643
, "(130-120)/(2*250)"
16031644
, null)
16041645
.Returns(0)
@@ -1979,12 +2020,12 @@ void Evaluator_PreEvaluateVariable(object sender, VariablePreEvaluationEventArg
19792020

19802021
yield return new TestCaseData(xExpressionEvaluator1
19812022
, "true || true"
1982-
, new Func<Exception, object> (exception =>
1983-
{
1984-
exception.ShouldNotBeOfType<ExpressionEvaluatorSyntaxErrorException>();
2023+
, new Func<Exception, object>(exception =>
2024+
{
2025+
exception.ShouldNotBeOfType<ExpressionEvaluatorSyntaxErrorException>();
19852026

1986-
return true;
1987-
}))
2027+
return true;
2028+
}))
19882029
.Returns(true)
19892030
.SetCategory("ExpressionEvaluator extend")
19902031
.SetCategory("inherits ExpressionEvaluator")
@@ -2118,7 +2159,7 @@ void Evaluator_PreEvaluateVariable(object sender, VariablePreEvaluationEventArg
21182159
, "Persons.Sum(x=>x.Number)"
21192160
, null)
21202161
.Returns(23.22m)
2121-
.SetCategory("Bug resolution");
2162+
.SetCategory("Bug resolution");
21222163

21232164
yield return new TestCaseData(new ExpressionEvaluator() { Context = new { Persons } }
21242165
, "Persons.Average(x=>x.Number)"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This file is used by Code Analysis to maintain SuppressMessage
2+
// attributes that are applied to this project.
3+
// Project-level suppressions either have no target or are given
4+
// a specific target and scoped to a namespace, type, member, etc.
5+
6+
using System.Diagnostics.CodeAnalysis;
7+
8+
[assembly: SuppressMessage("Design", "RCS1169:Make field read-only.", Justification = "<Pending>", Scope = "namespaceanddescendants", Target = "~N:CodingSeb.ExpressionEvaluator.Tests")]
9+
[assembly: SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "<Pending>", Scope = "namespaceanddescendants", Target = "~N:CodingSeb.ExpressionEvaluator.Tests")]
10+
[assembly: SuppressMessage("CodeQuality", "IDE0051:Remove unused private members", Justification = "<Pending>", Scope = "namespaceanddescendants", Target = "~N:CodingSeb.ExpressionEvaluator.Tests")]
11+
[assembly: SuppressMessage("Redundancy", "RCS1213:Remove unused member declaration.", Justification = "<Pending>", Scope = "namespaceanddescendants", Target = "~N:CodingSeb.ExpressionEvaluator.Tests")]
12+
[assembly: SuppressMessage("CodeQuality", "IDE0051:Remove unused private members", Justification = "<Pending>", Scope = "namespaceanddescendants", Target = "~N:CodingSeb.ExpressionEvaluator.Tests")]
13+
[assembly: SuppressMessage("Design", "RCS1170:Use read-only auto-implemented property.", Justification = "<Pending>", Scope = "namespaceanddescendants", Target = "~N:CodingSeb.ExpressionEvaluator.Tests")]

CodingSeb.ExpressionEvaluator.Tests/TestsUtils/ClassWithNonPublicMembersAndMethods.cs

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
1-
namespace CodingSeb.ExpressionEvaluator.Tests
1+
#pragma warning disable 414
2+
namespace CodingSeb.ExpressionEvaluator.Tests
23
{
34
public class ClassWithNonPublicMembersAndMethods
45
{
5-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "RCS1169:Make field read-only.", Justification = "<Pending>")]
6-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Redundancy", "RCS1213:Remove unused member declaration.", Justification = "<Pending>")]
7-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "<Pending>")]
8-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Code Quality", "IDE0051:Remove unused private members", Justification = "<Pending>")]
96
private int myPrivateField = 5;
107

118
protected int myProtectedField = 10;
129

13-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "RCS1170:Use read-only auto-implemented property.", Justification = "<Pending>")]
14-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Redundancy", "RCS1213:Remove unused member declaration.", Justification = "<Pending>")]
15-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Code Quality", "IDE0051:Remove unused private members", Justification = "<Pending>")]
1610
private int MyPrivateProperty { get; set; } = 15;
1711

1812
protected int MyProtectedProperty { get; set; } = 20;
1913

20-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Redundancy", "RCS1213:Remove unused member declaration.", Justification = "<Pending>")]
21-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Code Quality", "IDE0051:Remove unused private members", Justification = "<Pending>")]
2214
private string MyPrivateMethod(string name)
2315
{
2416
return "Hello " + name;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace CodingSeb.ExpressionEvaluator.Tests
4+
{
5+
public class ExceptionGenerator
6+
{
7+
public void ThrowAnException()
8+
{
9+
throw new Exception();
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace CodingSeb.ExpressionEvaluator.Tests
2+
{
3+
public class ObjectContainer
4+
{
5+
public object AnObjectProperty { get; set; } = 10;
6+
}
7+
}

CodingSeb.ExpressionEvaluator.sln

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.0.28729.10

CodingSeb.ExpressionEvaluator/CodingSeb.ExpressionEvaluator.csproj

+11-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<Product>CodingSeb.ExpressionEvaluator</Product>
66
<Description>A Simple Math and Pseudo C# Expression Evaluator in One C# File. Can also execute small C# like scripts</Description>
77
<Copyright>Copyright © Coding Seb 2017</Copyright>
8-
<Version>1.4.18.0</Version>
9-
<AssemblyVersion>1.4.18.0</AssemblyVersion>
10-
<FileVersion>1.4.18.0</FileVersion>
8+
<Version>1.4.19.0</Version>
9+
<AssemblyVersion>1.4.19.0</AssemblyVersion>
10+
<FileVersion>1.4.19.0</FileVersion>
1111
<OutputPath>bin\$(Configuration)\</OutputPath>
1212
<Authors>Coding Seb</Authors>
1313
<PackageId>CodingSeb.ExpressionEvaluator</PackageId>
@@ -17,8 +17,11 @@
1717
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
1818
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1919
<PackageIconUrl>https://github.com/codingseb/ExpressionEvaluator/blob/master/Icon.png?raw=true</PackageIconUrl>
20+
<PackageIcon>Icon.png</PackageIcon>
2021
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
21-
<PackageReleaseNotes>* Better exception when expression is empty</PackageReleaseNotes>
22+
<PackageReleaseNotes>* Correction of the bug Exceptions are assigned to variables
23+
* List of corresponding extensions methods in exception when wrong override is used
24+
* Text correction in exception</PackageReleaseNotes>
2225
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
2326
<RepositoryUrl>https://github.com/codingseb/ExpressionEvaluator</RepositoryUrl>
2427
</PropertyGroup>
@@ -36,6 +39,10 @@
3639
<PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" />
3740
</ItemGroup>
3841
<ItemGroup>
42+
<None Include="..\Icon.png">
43+
<Pack>True</Pack>
44+
<PackagePath></PackagePath>
45+
</None>
3946
<None Include="..\LICENSE.md">
4047
<Pack>True</Pack>
4148
<PackagePath></PackagePath>

0 commit comments

Comments
 (0)