Permalink
Browse files

Build: improve coverage. Fix issues with HasDifferentValue

  • Loading branch information...
dupdob committed Jun 13, 2017
1 parent 2aa96f3 commit bf83672695478b819b6f7fd3b72cd4bccb3115bc
@@ -571,7 +571,6 @@ public static ICheckLink<ICheck<IEnumerable>> IsNullOrEmpty(this ICheck<IEnumera
ExtensibilityHelper.ExtractChecker(subChecker).SetSutLabel("single element");
return subChecker;
}
},
checker.BuildMessage("The {0} has exactly one element, whereas it should not.").ToString());
}
@@ -15,13 +15,14 @@
namespace NFluent.Helpers
{
using Extensibility;
using System;
#if NETSTANDARD1_3
using System.Reflection;
#endif
using Extensions;
using System;
using Extensibility;
using Extensions;
/// <summary>
/// Helper class related to Equality methods (used like a traits).
@@ -63,19 +64,23 @@ internal static class EqualityHelper
bool negated = false) where TU : class, IMustImplementIForkableCheckWithoutDisplayingItsMethodsWithinIntelliSense
{
var mode = EqualityMode.Equals;
if (userOperator)
{
mode = EqualityMode.OperatorEq;
}
if (checker.Negated)
{
negated = !negated;
}
if (negated == FluentEquals(checker.Value, expected, mode))
var shouldFail = negated;
if (userOperator)
{
mode = negated ? EqualityMode.OperatorNeq : EqualityMode.OperatorEq;
shouldFail = false;
}
if (shouldFail == FluentEquals(checker.Value, expected, mode))
{
throw new FluentCheckException(BuildErrorMessage(checker, expected, negated, userOperator));
}
return checker.BuildChainingObject();
}
@@ -100,21 +105,30 @@ internal static class EqualityHelper
private static bool FluentEquals(object instance, object expected, EqualityMode mode)
{
// ReSharper disable once RedundantNameQualifier
var ret= object.Equals(instance, expected);
var ret = object.Equals(instance, expected);
if (mode == EqualityMode.OperatorEq || mode == EqualityMode.OperatorNeq)
{
if (mode == EqualityMode.OperatorNeq)
{
ret = !ret;
}
var actualType = instance.GetTypeWithoutThrowingException();
var expectedType = expected.GetTypeWithoutThrowingException();
var operatorName = mode == EqualityMode.OperatorEq ? "op_Equality" : "op_Inequality";
var ope = actualType
.GetMethod(operatorName, new[] { actualType, expectedType }) ?? expectedType
.GetMethod(operatorName, new[] { actualType, expectedType });
if (ope == null) return ret;
ret =(bool) ope.Invoke(null, new[] { instance, expected});
if (ope == null)
{
return ret;
}
ret = (bool)ope.Invoke(null, new[] { instance, expected});
}
else if (expected != null && instance != null)
{
var expectedType = expected.GetType();
// if both types are numerical, check if the values are the same to generate a precise message
if (ExtensionsCommonHelpers.IsNumerical(expectedType) && ExtensionsCommonHelpers.IsNumerical(instance.GetType()))
{
@@ -84,7 +84,7 @@ public void ContainsOnceSucceeds()
}
[Test]
public void ContainsOnceSucceedsWithMultipleOccurences()
public void ContainsOnceSucceedsWithMultipleOccurrences()
{
var tresAmigosAndMore = new[] { "un", "dos", "tres", "tres" };
Check.That(tresAmigosAndMore).Contains(tresAmigosAndMore).Once();

0 comments on commit bf83672

Please sign in to comment.