public void CompareTwoBooleans() { TestEqual <bool, bool, bool> equal = new TestEqual <bool, bool, bool>(true, false); TestSequence seq = TestExpressionTracer.GetTraceableBinaryExpressionActivity <bool, bool, bool>(equal, false.ToString()); TestRuntime.RunAndValidateWorkflow(seq); }
public void TryEqualsOnIncompatibleTypes() { TestEqual <int, string, string> eq = new TestEqual <int, string, string> { Left = 12, Right = "12" }; TestRuntime.ValidateInstantiationException(eq, TestExpressionTracer.GetExceptionMessage <int, string, string>(System.Linq.Expressions.ExpressionType.Equal)); }
public void ConstraintViolationIncompatibleTypes() { TestEqual <int, string, string> eq = new TestEqual <int, string, string>(); string errorMessage = TestExpressionTracer.GetExceptionMessage <int, string, string>(System.Linq.Expressions.ExpressionType.Equal); TestExpressionTracer.Validate(eq, new List <string> { errorMessage }); }
public void SetRightOperandNull() { TestEqual <int, int, bool> eq = new TestEqual <int, int, bool> { Left = 12 }; string errorMessage = string.Format(ErrorStrings.RequiredArgumentValueNotSupplied, "Right"); TestRuntime.ValidateWorkflowErrors(eq, new List <TestConstraintViolation>(), typeof(ArgumentException), errorMessage); }
public void CustomTypeOperandWithOperatorOverloaded() { TestEqual <Complex, Complex, bool> equal = new TestEqual <Complex, Complex, bool> { LeftExpression = context => new Complex(2, 3), RightExpression = context => new Complex(2, 3), }; TestSequence seq = TestExpressionTracer.GetTraceableBinaryExpressionActivity <Complex, Complex, bool>(equal, true.ToString()); TestRuntime.RunAndValidateWorkflow(seq); }
public void ThrowFromOverloadedOperator() { TestEqual <OverLoadOperatorThrowingType, OverLoadOperatorThrowingType, bool> eq = new TestEqual <OverLoadOperatorThrowingType, OverLoadOperatorThrowingType, bool> { LeftExpression = context => new OverLoadOperatorThrowingType(13), RightExpression = context => new OverLoadOperatorThrowingType(14), }; OverLoadOperatorThrowingType.ThrowException = true; eq.ExpectedOutcome = Outcome.UncaughtException(); TestSequence seq = TestExpressionTracer.GetTraceableBinaryExpressionActivity <OverLoadOperatorThrowingType, OverLoadOperatorThrowingType, bool>(eq, "12"); TestRuntime.RunAndValidateAbortedException(seq, typeof(ArithmeticException), null); }
private static DiscrepancyTestResult GetResult <T>(PatientProfile x, PatientProfile y, PatientProfileDiscrepancy discrepancy, PropertyGetter <T> propGetter, TestEqual <T> tester) { return(GetResult(x, y, discrepancy, propGetter, tester, DefaultToString)); }
/// <summary> /// Computes a <see cref="DiscrepancyTestResult"/> for a specified property /// </summary> /// <typeparam name="T">The type of the property being tested</typeparam> /// <param name="x">Left operand</param> /// <param name="y">Right operand</param> /// <param name="discrepancy">Discrepancy being tested</param> /// <param name="getter">A delegate that returns the value of the property from a <see cref="PatientProfile"/></param> /// <param name="tester">A delegate that tests for equality of the property - need not be null-safe</param> /// <param name="toString">A delegate that converts the property to a string</param> /// <returns></returns> private static DiscrepancyTestResult GetResult <T>(PatientProfile x, PatientProfile y, PatientProfileDiscrepancy discrepancy, PropertyGetter <T> getter, TestEqual <T> tester, ToStringDelegate <T> toString) { var vx = getter(x); var vy = getter(y); if (Equals(vx, default(T)) && Equals(vy, default(T))) { return(new DiscrepancyTestResult(discrepancy, false, StringDiff.Compute("", "", true))); } if (Equals(vx, default(T))) { return(new DiscrepancyTestResult(discrepancy, true, StringDiff.Compute("", toString(vy), true))); } if (Equals(vy, default(T))) { return(new DiscrepancyTestResult(discrepancy, true, StringDiff.Compute(toString(vx), "", true))); } return(new DiscrepancyTestResult(discrepancy, !tester(vx, vy), StringDiff.Compute(toString(vx), toString(vy), true))); }