public override bool Equals(object obj) { ConditionalExpressionFingerprint other = obj as ConditionalExpressionFingerprint; return((other != null) && this.Equals(other)); }
public void Properties() { // Arrange ExpressionType expectedNodeType = ExpressionType.Conditional; Type expectedType = typeof(object); // Act ConditionalExpressionFingerprint fingerprint = new ConditionalExpressionFingerprint(expectedNodeType, expectedType); // Assert Assert.AreEqual(expectedNodeType, fingerprint.NodeType); Assert.AreEqual(expectedType, fingerprint.Type); }
public void Comparison_Inequality_Type() { // Arrange ExpressionType nodeType = ExpressionType.Conditional; Type type = typeof(object); // Act ConditionalExpressionFingerprint fingerprint1 = new ConditionalExpressionFingerprint(nodeType, type); ConditionalExpressionFingerprint fingerprint2 = new ConditionalExpressionFingerprint(nodeType, typeof(string)); // Assert Assert.AreNotEqual(fingerprint1, fingerprint2, "Fingerprints should not have been equal (differ by Type)."); }
public void Comparison_Inequality_FingerprintType() { // Arrange ExpressionType nodeType = ExpressionType.Conditional; Type type = typeof(object); // Act ConditionalExpressionFingerprint fingerprint1 = new ConditionalExpressionFingerprint(nodeType, type); DummyExpressionFingerprint fingerprint2 = new DummyExpressionFingerprint(nodeType, type); // Assert Assert.AreNotEqual(fingerprint1, fingerprint2, "Fingerprints should not have been equal ('other' is wrong type)."); }
public void Comparison_Inequality_Type() { // Arrange ExpressionType nodeType = ExpressionType.Conditional; Type type = typeof(object); // Act ConditionalExpressionFingerprint fingerprint1 = new ConditionalExpressionFingerprint(nodeType, type); ConditionalExpressionFingerprint fingerprint2 = new ConditionalExpressionFingerprint(nodeType, typeof(string)); // Assert Assert.AreNotEqual(fingerprint1, fingerprint2, "Fingerprints should not have been equal (differ by Type)."); }
public void Properties() { // Arrange ExpressionType expectedNodeType = ExpressionType.Conditional; Type expectedType = typeof(object); // Act ConditionalExpressionFingerprint fingerprint = new ConditionalExpressionFingerprint(expectedNodeType, expectedType); // Assert Assert.Equal(expectedNodeType, fingerprint.NodeType); Assert.Equal(expectedType, fingerprint.Type); }
public void Comparison_Inequality_FingerprintType() { // Arrange ExpressionType nodeType = ExpressionType.Conditional; Type type = typeof(object); // Act ConditionalExpressionFingerprint fingerprint1 = new ConditionalExpressionFingerprint(nodeType, type); DummyExpressionFingerprint fingerprint2 = new DummyExpressionFingerprint(nodeType, type); // Assert Assert.AreNotEqual(fingerprint1, fingerprint2, "Fingerprints should not have been equal ('other' is wrong type)."); }
public void Comparison_Inequality_Type() { // Arrange ExpressionType nodeType = ExpressionType.Conditional; Type type = typeof(object); // Act ConditionalExpressionFingerprint fingerprint1 = new ConditionalExpressionFingerprint(nodeType, type); ConditionalExpressionFingerprint fingerprint2 = new ConditionalExpressionFingerprint(nodeType, typeof(string)); // Assert Assert.NotEqual(fingerprint1, fingerprint2); }
public void Comparison_Inequality_Type() { // Arrange ExpressionType nodeType = ExpressionType.Conditional; Type type = typeof(object); // Act ConditionalExpressionFingerprint fingerprint1 = new ConditionalExpressionFingerprint(nodeType, type); ConditionalExpressionFingerprint fingerprint2 = new ConditionalExpressionFingerprint(nodeType, typeof(string)); // Assert Assert.NotEqual(fingerprint1, fingerprint2); }
public void Comparison_Equality() { // Arrange ExpressionType nodeType = ExpressionType.Conditional; Type type = typeof(object); // Act ConditionalExpressionFingerprint fingerprint1 = new ConditionalExpressionFingerprint(nodeType, type); ConditionalExpressionFingerprint fingerprint2 = new ConditionalExpressionFingerprint(nodeType, type); // Assert Assert.AreEqual(fingerprint1, fingerprint2, "Fingerprints should have been equal."); Assert.AreEqual(fingerprint1.GetHashCode(), fingerprint2.GetHashCode(), "Fingerprints should have been different."); }
public void Comparison_Equality() { // Arrange ExpressionType nodeType = ExpressionType.Conditional; Type type = typeof(object); // Act ConditionalExpressionFingerprint fingerprint1 = new ConditionalExpressionFingerprint(nodeType, type); ConditionalExpressionFingerprint fingerprint2 = new ConditionalExpressionFingerprint(nodeType, type); // Assert Assert.AreEqual(fingerprint1, fingerprint2, "Fingerprints should have been equal."); Assert.AreEqual(fingerprint1.GetHashCode(), fingerprint2.GetHashCode(), "Fingerprints should have been different."); }
public void Comparison_Equality() { // Arrange ExpressionType nodeType = ExpressionType.Conditional; Type type = typeof(object); // Act ConditionalExpressionFingerprint fingerprint1 = new ConditionalExpressionFingerprint(nodeType, type); ConditionalExpressionFingerprint fingerprint2 = new ConditionalExpressionFingerprint(nodeType, type); // Assert Assert.Equal(fingerprint1, fingerprint2); Assert.Equal(fingerprint1.GetHashCode(), fingerprint2.GetHashCode()); }
public void Comparison_Equality() { // Arrange ExpressionType nodeType = ExpressionType.Conditional; Type type = typeof(object); // Act ConditionalExpressionFingerprint fingerprint1 = new ConditionalExpressionFingerprint(nodeType, type); ConditionalExpressionFingerprint fingerprint2 = new ConditionalExpressionFingerprint(nodeType, type); // Assert Assert.Equal(fingerprint1, fingerprint2); Assert.Equal(fingerprint1.GetHashCode(), fingerprint2.GetHashCode()); }
public void Comparison_DifferByIfFalse() { // fingerprint1 is IIF(CONST:bool, CONST:TimeSpan, CONST:TimeSpan):TimeSpan // fingerprint2 is IIF(CONST:bool, CONST:TimeSpan, OP_NEGATE(CONST:TimeSpan):TimeSpan):TimeSpan, so not equivalent // Arrange ExpressionFingerprint fingerprint1 = ConditionalExpressionFingerprint.Create(Expression.Condition(Expression.Constant(true), Expression.Constant(TimeSpan.MinValue), Expression.Constant(TimeSpan.MaxValue)), new ParserContext()); ExpressionFingerprint fingerprint2 = ConditionalExpressionFingerprint.Create(Expression.Condition(Expression.Constant(true), Expression.Constant(TimeSpan.MaxValue), Expression.Negate(Expression.Constant(TimeSpan.Zero))), new ParserContext()); // Act bool areEqual = Object.Equals(fingerprint1, fingerprint2); // Assert Assert.IsFalse(areEqual, "Fingerprints should not have been equivalent - differ by ConditionalExpressionFingerprint.IfTrue."); }
public void Create_UnknownTest() { // Arrange ParserContext context = new ParserContext() { ModelParameter = Expression.Parameter(typeof(bool), "model") }; Expression testExpr = ExpressionHelper.GetUnknownExpression(typeof(bool)); Expression ifTrueExpr = Expression.UnaryPlus(Expression.Constant(TimeSpan.Zero)); Expression ifFalseExpr = Expression.Negate(Expression.Constant(TimeSpan.Zero)); ConditionalExpression expression = Expression.Condition(testExpr, ifTrueExpr, ifFalseExpr); // Act ConditionalExpressionFingerprint fingerprint = ConditionalExpressionFingerprint.Create(expression, context); // Assert Assert.IsNull(fingerprint, "Unknown Test expression cannot be parsed."); }
public void ToExpression() { // Arrange ParserContext context = new ParserContext(); Expression testExpr = Expression.Not(Expression.Constant(true)); Expression ifTrueExpr = Expression.UnaryPlus(Expression.Constant(TimeSpan.Zero)); Expression ifFalseExpr = Expression.Negate(Expression.Constant(TimeSpan.Zero)); ConditionalExpression expression = Expression.Condition(testExpr, ifTrueExpr, ifFalseExpr); ConditionalExpressionFingerprint fingerprint = ConditionalExpressionFingerprint.Create(expression, context); // Act ConditionalExpression result = (ConditionalExpression)fingerprint.ToExpression(context); // Assert Assert.AreEqual(ExpressionType.Not, result.Test.NodeType); Assert.AreEqual(ExpressionType.UnaryPlus, result.IfTrue.NodeType); Assert.AreEqual(ExpressionType.Negate, result.IfFalse.NodeType); }
public void Comparison_EquivalentExpressions() { // both fingerprints are IIF(CONST:bool, CONST:TimeSpan, CONST:TimeSpan):TimeSpan, so are equivalent // Arrange ExpressionFingerprint fingerprint1 = ConditionalExpressionFingerprint.Create(Expression.Condition(Expression.Constant(true), Expression.Constant(TimeSpan.MinValue), Expression.Constant(TimeSpan.MaxValue)), new ParserContext()); ExpressionFingerprint fingerprint2 = ConditionalExpressionFingerprint.Create(Expression.Condition(Expression.Constant(true), Expression.Constant(TimeSpan.MaxValue), Expression.Constant(TimeSpan.Zero)), new ParserContext()); // Act HashSet <ExpressionFingerprint> set = new HashSet <ExpressionFingerprint>() { fingerprint1, fingerprint2 }; // Assert Assert.AreEqual(1, set.Count, "Fingerprints should have been equivalent."); }
public void Create() { // Arrange ParserContext context = new ParserContext() { ModelParameter = Expression.Parameter(typeof(bool), "model") }; Expression testExpr = context.ModelParameter; Expression ifTrueExpr = Expression.UnaryPlus(Expression.Constant(TimeSpan.Zero)); Expression ifFalseExpr = Expression.Negate(Expression.Constant(TimeSpan.Zero)); ConditionalExpression expression = Expression.Condition(testExpr, ifTrueExpr, ifFalseExpr); // Act ConditionalExpressionFingerprint fingerprint = ConditionalExpressionFingerprint.Create(expression, context); // Assert Assert.AreEqual(ExpressionType.Parameter, fingerprint.Test.NodeType); Assert.AreEqual(ExpressionType.UnaryPlus, fingerprint.IfTrue.NodeType); Assert.AreEqual(ExpressionType.Negate, fingerprint.IfFalse.NodeType); }