Skip to content

Commit

Permalink
Merge pull request #98 from bijington/issue-96-tidy-up-of-warnings
Browse files Browse the repository at this point in the history
Enabled warnings as errors and fixed related issues.
  • Loading branch information
bijington authored Jan 26, 2021
2 parents 7820c4e + 470db93 commit 1270099
Show file tree
Hide file tree
Showing 40 changed files with 269 additions and 80 deletions.
2 changes: 2 additions & 0 deletions Source/Expressive.Tests/ContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ public static void TestRegisterFunctionWithForce()

Assert.That(context.FunctionNames, Does.Contain(functionName));
context.TryGetFunction(functionName, out var ifFunction);
#pragma warning disable CA1825
ifFunction.Invoke(new IExpression[0], new Dictionary<string, object>());
#pragma warning restore CA1825
Assert.That(customIfCount, Is.EqualTo(1));
}

Expand Down
18 changes: 18 additions & 0 deletions Source/Expressive.Tests/DictionaryEnumerationTestData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections.Generic;

namespace Expressive.Tests
{
public class DictionaryEnumerationTestData
{
public ExpressiveOptions Options { get; }
public IEqualityComparer<string> Comparer { get; }
public bool ExpectedEnumeration { get; }

public DictionaryEnumerationTestData(ExpressiveOptions options, IEqualityComparer<string> comparer, bool expectedEnumeration)
{
this.Options = options;
this.Comparer = comparer;
this.ExpectedEnumeration = expectedEnumeration;
}
}
}
16 changes: 2 additions & 14 deletions Source/Expressive.Tests/ExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,9 @@ public void ShouldEvaluateWithVariableProvider()
[TestCaseSource(nameof(DictionaryEnumerationSource))]
public static void ShouldNotEnumerateDictionaryWithAppropriateComparer(DictionaryEnumerationTestData sourceData)
{
#pragma warning disable CA1062 // Validate arguments of public methods - this really isn't going to be null
var context = new Context(sourceData.Options);
#pragma warning restore CA1062 // Validate arguments of public methods
var expression = new Expression("1+2", context);
var dictionary = new MockDictionary(sourceData.Comparer);

Expand Down Expand Up @@ -1237,19 +1239,5 @@ public MockDictionary(IEqualityComparer<string> comparer) : base(comparer)

public new int Count => throw new InvalidOperationException();
}

public class DictionaryEnumerationTestData
{
public ExpressiveOptions Options { get; }
public IEqualityComparer<string> Comparer { get; }
public bool ExpectedEnumeration { get; }

public DictionaryEnumerationTestData(ExpressiveOptions options, IEqualityComparer<string> comparer, bool expectedEnumeration)
{
this.Options = options;
this.Comparer = comparer;
this.ExpectedEnumeration = expectedEnumeration;
}
}
}
}
1 change: 1 addition & 0 deletions Source/Expressive.Tests/Expressive.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<AssemblyOriginatorKeyFile>..\ExpressiveStrongName.snk</AssemblyOriginatorKeyFile>

<DelaySign>false</DelaySign>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Expressive.Tests.Functions.Conversion
{
[TestClass]
public class DateFunctionTests : FunctionBaseTests
public class DateFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Expressive.Tests.Functions.Conversion
{
[TestClass]
public class DecimalFunctionTests : FunctionBaseTests
public class DecimalFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Expressive.Tests.Functions.Conversion
{
[TestClass]
public class DoubleFunctionTests : FunctionBaseTests
public class DoubleFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Expressive.Tests.Functions.Conversion
{
[TestClass]
public class IntegerFunctionTests : FunctionBaseTests
public class IntegerFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Expressive.Tests.Functions.Conversion
{
[TestClass]
public class LongFunctionTests : FunctionBaseTests
public class LongFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Expressive.Tests.Functions.Conversion
{
[TestClass]
public class StringFunctionTests : FunctionBaseTests
public class StringFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Expressive.Tests.Functions.Date
{
[TestClass]
public class AddDaysFunctionTests : FunctionBaseTests
public class AddDaysFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Expressive.Tests.Functions.Date
{
[TestClass]
public class AddHoursFunctionTests : FunctionBaseTests
public class AddHoursFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Expressive.Tests.Functions.Date
{
[TestClass]
public class AddMillisecondsFunctionTests : FunctionBaseTests
public class AddMillisecondsFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Expressive.Tests.Functions.Date
{
[TestClass]
public class AddMinutesFunctionTests : FunctionBaseTests
public class AddMinutesFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Expressive.Tests.Functions.Date
{
[TestClass]
public class AddMonthsFunctionTests : FunctionBaseTests
public class AddMonthsFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Expressive.Tests.Functions.Date
{
[TestClass]
public class AddSecondsFunctionTests : FunctionBaseTests
public class AddSecondsFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Expressive.Tests.Functions.Date
{
[TestClass]
public class AddYearsFunctionTests : FunctionBaseTests
public class AddYearsFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Expressive.Tests.Functions.Date
{
[TestClass]
public class DayOfFunctionTests : FunctionBaseTests
public class DayOfFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Expressive.Tests.Functions.Date
{
[TestClass]
public class DaysBetweenFunctionTests : FunctionBaseTests
public class DaysBetweenFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Expressive.Tests.Functions.Date
{
[TestClass]
public class HourOfFunctionTests : FunctionBaseTests
public class HourOfFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Expressive.Tests.Functions.Date
{
[TestClass]
public class HoursBetweenFunctionTests : FunctionBaseTests
public class HoursBetweenFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Expressive.Tests.Functions.Date
{
[TestClass]
public class MillisecondOfFunctionTests : FunctionBaseTests
public class MillisecondOfFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Expressive.Tests.Functions.Date
{
[TestClass]
public class MillisecondsBetweenFunctionTests : FunctionBaseTests
public class MillisecondsBetweenFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Expressive.Tests.Functions.Date
{
[TestClass]
public class MinuteOfFunctionTests : FunctionBaseTests
public class MinuteOfFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Expressive.Tests.Functions.Date
{
[TestClass]
public class MinutesBetweenFunctionTests : FunctionBaseTests
public class MinutesBetweenFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Expressive.Tests.Functions.Date
{
[TestClass]
public class MonthOfFunctionTests : FunctionBaseTests
public class MonthOfFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Expressive.Tests.Functions.Date
{
[TestClass]
public class SecondOfFunctionTests : FunctionBaseTests
public class SecondOfFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Expressive.Tests.Functions.Date
{
[TestClass]
public class SecondsBetweenFunctionTests : FunctionBaseTests
public class SecondsBetweenFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Expressive.Tests.Functions.Date
{
[TestClass]
public class YearOfFunctionTests : FunctionBaseTests
public class YearOfFunctionTests : FunctionBaseTestBase
{
[TestMethod]
public void TestName()
Expand Down
42 changes: 42 additions & 0 deletions Source/Expressive.Tests/Functions/FunctionBaseTestBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Expressive.Expressions;
using Expressive.Functions;
using Moq;
using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;

namespace Expressive.Tests.Functions
{
public abstract class FunctionBaseTestBase
{
protected abstract IFunction ActualFunction { get; }

protected void AssertException(Type exceptionType, string exceptionMessage, params object[] values)
{
try
{
this.ActualFunction.Evaluate(
values?.Select(v => Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == v)).ToArray(),
new Context(ExpressiveOptions.None));
}
#pragma warning disable CA1031 // Do not catch general exception types - We will eventually switch to NUnit that should remove the need for this.
catch (Exception e)
#pragma warning restore CA1031 // Do not catch general exception types
{
Assert.IsInstanceOfType(e, exceptionType);
Assert.AreEqual(exceptionMessage, e.Message);
return;
}

throw new InvalidOperationException($"An exception of type: {exceptionType} was expected but no exception was thrown");
}

protected object Evaluate(params object[] values)
{
return this.ActualFunction.Evaluate(
values?.Select(v => Mock.Of<IExpression>(e => e.Evaluate(It.IsAny<IDictionary<string, object>>()) == v)).ToArray(),
new Context(ExpressiveOptions.None));
}
}
}
Loading

0 comments on commit 1270099

Please sign in to comment.